Merge pull request #337 from nuttycom/fix_clippy
Fix clippy complaints.
This commit is contained in:
commit
db8c67037c
|
@ -141,10 +141,7 @@ pub trait WalletRead {
|
|||
///
|
||||
/// This will return `Ok(None)` if the note identifier does not appear in the
|
||||
/// database as a known note ID.
|
||||
fn get_memo_as_utf8(
|
||||
&self,
|
||||
id_note: Self::NoteRef,
|
||||
) -> Result<Option<String>, Self::Error>;
|
||||
fn get_memo_as_utf8(&self, id_note: Self::NoteRef) -> Result<Option<String>, Self::Error>;
|
||||
|
||||
/// Returns the note commitment tree at the specified block height.
|
||||
fn get_commitment_tree(
|
||||
|
@ -153,6 +150,7 @@ pub trait WalletRead {
|
|||
) -> Result<Option<CommitmentTree<Node>>, Self::Error>;
|
||||
|
||||
/// Returns the incremental witnesses as of the specified block height.
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn get_witnesses(
|
||||
&self,
|
||||
block_height: BlockHeight,
|
||||
|
@ -453,10 +451,7 @@ pub mod testing {
|
|||
Ok(Amount::zero())
|
||||
}
|
||||
|
||||
fn get_memo_as_utf8(
|
||||
&self,
|
||||
_id_note: Self::NoteRef,
|
||||
) -> Result<Option<String>, Self::Error> {
|
||||
fn get_memo_as_utf8(&self, _id_note: Self::NoteRef) -> Result<Option<String>, Self::Error> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
|
@ -467,6 +462,7 @@ pub mod testing {
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn get_witnesses(
|
||||
&self,
|
||||
_block_height: BlockHeight,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(clippy::needless_doctest_main)]
|
||||
//! Tools for blockchain validation & scanning
|
||||
//!
|
||||
//! # Examples
|
||||
|
@ -174,6 +175,7 @@ where
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_doctest_main)]
|
||||
/// Scans at most `limit` new blocks added to the cache for any transactions received by
|
||||
/// the tracked accounts.
|
||||
///
|
||||
|
@ -267,7 +269,7 @@ where
|
|||
// Get the most recent CommitmentTree
|
||||
let mut tree = data
|
||||
.get_commitment_tree(last_height)
|
||||
.map(|t| t.unwrap_or(CommitmentTree::new()))?;
|
||||
.map(|t| t.unwrap_or_else(CommitmentTree::empty))?;
|
||||
|
||||
// Get most recent incremental witnesses for the notes we are tracking
|
||||
let mut witnesses = data.get_witnesses(last_height)?;
|
||||
|
|
|
@ -24,7 +24,7 @@ pub const ANCHOR_OFFSET: u32 = 10;
|
|||
|
||||
/// Scans a [`Transaction`] for any information that can be decrypted by the accounts in
|
||||
/// the wallet, and saves it to the wallet.
|
||||
pub fn decrypt_and_store_transaction<'db, N, E, P, D>(
|
||||
pub fn decrypt_and_store_transaction<N, E, P, D>(
|
||||
params: &P,
|
||||
data: &mut D,
|
||||
tx: &Transaction,
|
||||
|
@ -44,8 +44,8 @@ where
|
|||
.or(data
|
||||
.block_height_extrema()?
|
||||
.map(|(_, max_height)| max_height + 1))
|
||||
.or(params.activation_height(NetworkUpgrade::Sapling))
|
||||
.ok_or(Error::SaplingNotActive.into())?;
|
||||
.or_else(|| params.activation_height(NetworkUpgrade::Sapling))
|
||||
.ok_or(Error::SaplingNotActive)?;
|
||||
|
||||
let outputs = decrypt_transaction(params, height, tx, &extfvks);
|
||||
if outputs.is_empty() {
|
||||
|
@ -68,6 +68,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_doctest_main)]
|
||||
/// Creates a transaction paying the specified address from the given account.
|
||||
///
|
||||
/// Returns the row index of the newly-created transaction in the `transactions` table
|
||||
|
@ -153,6 +154,7 @@ where
|
|||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create_spend_to_address<E, N, P, D, R>(
|
||||
wallet_db: &mut D,
|
||||
params: &P,
|
||||
|
@ -187,7 +189,7 @@ where
|
|||
// Target the next block, assuming we are up-to-date.
|
||||
let (height, anchor_height) = wallet_db
|
||||
.get_target_and_anchor_heights()
|
||||
.and_then(|x| x.ok_or(Error::ScanRequired.into()))?;
|
||||
.and_then(|x| x.ok_or_else(|| Error::ScanRequired.into()))?;
|
||||
|
||||
let target_value = value + DEFAULT_FEE;
|
||||
let spendable_notes = wallet_db.select_spendable_notes(account, target_value, anchor_height)?;
|
||||
|
@ -242,27 +244,25 @@ where
|
|||
};
|
||||
|
||||
// Update the database atomically, to ensure the result is internally consistent.
|
||||
wallet_db
|
||||
.transactionally(|up| {
|
||||
let created = time::OffsetDateTime::now_utc();
|
||||
let tx_ref = up.put_tx_data(&tx, Some(created))?;
|
||||
wallet_db.transactionally(|up| {
|
||||
let created = time::OffsetDateTime::now_utc();
|
||||
let tx_ref = up.put_tx_data(&tx, Some(created))?;
|
||||
|
||||
// Mark notes as spent.
|
||||
//
|
||||
// This locks the notes so they aren't selected again by a subsequent call to
|
||||
// create_spend_to_address() before this transaction has been mined (at which point the notes
|
||||
// get re-marked as spent).
|
||||
//
|
||||
// Assumes that create_spend_to_address() will never be called in parallel, which is a
|
||||
// reasonable assumption for a light client such as a mobile phone.
|
||||
for spend in &tx.shielded_spends {
|
||||
up.mark_spent(tx_ref, &spend.nullifier)?;
|
||||
}
|
||||
// Mark notes as spent.
|
||||
//
|
||||
// This locks the notes so they aren't selected again by a subsequent call to
|
||||
// create_spend_to_address() before this transaction has been mined (at which point the notes
|
||||
// get re-marked as spent).
|
||||
//
|
||||
// Assumes that create_spend_to_address() will never be called in parallel, which is a
|
||||
// reasonable assumption for a light client such as a mobile phone.
|
||||
for spend in &tx.shielded_spends {
|
||||
up.mark_spent(tx_ref, &spend.nullifier)?;
|
||||
}
|
||||
|
||||
up.insert_sent_note(tx_ref, output_index as usize, account, to, value, memo)?;
|
||||
up.insert_sent_note(tx_ref, output_index as usize, account, to, value, memo)?;
|
||||
|
||||
// Return the row number of the transaction, so the caller can fetch it for sending.
|
||||
Ok(tx_ref)
|
||||
})
|
||||
.map_err(|e| e.into())
|
||||
// Return the row number of the transaction, so the caller can fetch it for sending.
|
||||
Ok(tx_ref)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ use crate::wallet::{AccountId, WalletShieldedOutput, WalletShieldedSpend, Wallet
|
|||
///
|
||||
/// The given [`CommitmentTree`] and existing [`IncrementalWitness`]es are incremented
|
||||
/// with this output's commitment.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn scan_output<P: consensus::Parameters>(
|
||||
params: &P,
|
||||
height: BlockHeight,
|
||||
|
@ -260,14 +261,14 @@ mod tests {
|
|||
let rseed = generate_random_rseed(&Network::TestNetwork, height, &mut rng);
|
||||
let note = Note {
|
||||
g_d: to.diversifier().g_d().unwrap(),
|
||||
pk_d: to.pk_d().clone(),
|
||||
pk_d: *to.pk_d(),
|
||||
value: value.into(),
|
||||
rseed,
|
||||
};
|
||||
let encryptor = SaplingNoteEncryption::new(
|
||||
Some(extfvk.fvk.ovk),
|
||||
note.clone(),
|
||||
to.clone(),
|
||||
to,
|
||||
Memo::default(),
|
||||
&mut rng,
|
||||
);
|
||||
|
@ -325,7 +326,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(cb.vtx.len(), 2);
|
||||
|
||||
let mut tree = CommitmentTree::new();
|
||||
let mut tree = CommitmentTree::empty();
|
||||
let txs = scan_block(
|
||||
&Network::TestNetwork,
|
||||
cb,
|
||||
|
@ -364,7 +365,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(cb.vtx.len(), 3);
|
||||
|
||||
let mut tree = CommitmentTree::new();
|
||||
let mut tree = CommitmentTree::empty();
|
||||
let txs = scan_block(
|
||||
&Network::TestNetwork,
|
||||
cb,
|
||||
|
@ -399,12 +400,12 @@ mod tests {
|
|||
let cb = fake_compact_block(1u32.into(), nf, extfvk, Amount::from_u64(5).unwrap(), false);
|
||||
assert_eq!(cb.vtx.len(), 2);
|
||||
|
||||
let mut tree = CommitmentTree::new();
|
||||
let mut tree = CommitmentTree::empty();
|
||||
let txs = scan_block(
|
||||
&Network::TestNetwork,
|
||||
cb,
|
||||
&[],
|
||||
&[(account, nf.clone())],
|
||||
&[(account, nf)],
|
||||
&mut tree,
|
||||
&mut [],
|
||||
);
|
||||
|
|
|
@ -4,7 +4,6 @@ use std::collections::HashMap;
|
|||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use base64;
|
||||
use nom::{
|
||||
character::complete::char, combinator::all_consuming, multi::separated_list, sequence::preceded,
|
||||
};
|
||||
|
@ -21,10 +20,6 @@ pub enum MemoError {
|
|||
}
|
||||
|
||||
impl RawMemo {
|
||||
pub fn from_str(s: &str) -> Result<Self, MemoError> {
|
||||
RawMemo::from_bytes(s.as_bytes())
|
||||
}
|
||||
|
||||
// Construct a raw memo from a vector of bytes.
|
||||
pub fn from_bytes(v: &[u8]) -> Result<Self, MemoError> {
|
||||
if v.len() > 512 {
|
||||
|
@ -77,7 +72,7 @@ impl FromStr for RawMemo {
|
|||
type Err = MemoError;
|
||||
|
||||
fn from_str(memo: &str) -> Result<Self, Self::Err> {
|
||||
RawMemo::from_str(memo)
|
||||
RawMemo::from_bytes(memo.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -403,7 +398,7 @@ mod parse {
|
|||
pub enum Param {
|
||||
Addr(RecipientAddress),
|
||||
Amount(Amount),
|
||||
Memo(RawMemo),
|
||||
Memo(Box<RawMemo>),
|
||||
Label(String),
|
||||
Message(String),
|
||||
Other(String, String),
|
||||
|
@ -428,7 +423,7 @@ mod parse {
|
|||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
pub fn to_payment(vs: Vec<Param>, i: usize) -> Result<Payment, String> {
|
||||
|
@ -448,10 +443,10 @@ mod parse {
|
|||
|
||||
for v in vs {
|
||||
match v {
|
||||
Param::Amount(a) => payment.amount = a.clone(),
|
||||
Param::Amount(a) => payment.amount = a,
|
||||
Param::Memo(m) => {
|
||||
match payment.recipient_address {
|
||||
RecipientAddress::Shielded(_) => payment.memo = Some(m),
|
||||
RecipientAddress::Shielded(_) => payment.memo = Some(*m),
|
||||
RecipientAddress::Transparent(_) => return Err(format!("Payment {} attempted to associate a memo with a transparent recipient address", i)),
|
||||
}
|
||||
},
|
||||
|
@ -463,7 +458,7 @@ mod parse {
|
|||
}
|
||||
}
|
||||
|
||||
return Ok(payment);
|
||||
Ok(payment)
|
||||
}
|
||||
|
||||
/// Parser that consumes the leading "zcash:[address]" from
|
||||
|
@ -601,7 +596,7 @@ mod parse {
|
|||
.map_err(|e| e.to_string()),
|
||||
|
||||
"memo" => memo_from_base64(value)
|
||||
.map(Param::Memo)
|
||||
.map(|m| Param::Memo(Box::new(m)))
|
||||
.map_err(|e| format!("Decoded memo was invalid: {:?}", e)),
|
||||
|
||||
other if other.starts_with("req-") => {
|
||||
|
@ -957,7 +952,7 @@ mod tests {
|
|||
let fragment = memo_param(&memo, i);
|
||||
let (rest, iparam) = zcashparam(&TEST_NETWORK)(&fragment).unwrap();
|
||||
assert_eq!(rest, "");
|
||||
assert_eq!(iparam.param, Param::Memo(memo));
|
||||
assert_eq!(iparam.param, Param::Memo(Box::new(memo)));
|
||||
assert_eq!(iparam.payment_index, i.unwrap_or(0));
|
||||
}
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ mod tests {
|
|||
let (cb4, _) = fake_compact_block(
|
||||
sapling_activation_height() + 3,
|
||||
cb3.hash(),
|
||||
extfvk.clone(),
|
||||
extfvk,
|
||||
Amount::from_u64(3).unwrap(),
|
||||
);
|
||||
insert_into_cache(&db_cache, &cb3);
|
||||
|
@ -295,7 +295,7 @@ mod tests {
|
|||
let (cb4, _) = fake_compact_block(
|
||||
sapling_activation_height() + 3,
|
||||
BlockHash([1; 32]),
|
||||
extfvk.clone(),
|
||||
extfvk,
|
||||
Amount::from_u64(3).unwrap(),
|
||||
);
|
||||
insert_into_cache(&db_cache, &cb3);
|
||||
|
@ -408,12 +408,8 @@ mod tests {
|
|||
extfvk.clone(),
|
||||
value,
|
||||
);
|
||||
let (cb3, _) = fake_compact_block(
|
||||
sapling_activation_height() + 2,
|
||||
cb2.hash(),
|
||||
extfvk.clone(),
|
||||
value,
|
||||
);
|
||||
let (cb3, _) =
|
||||
fake_compact_block(sapling_activation_height() + 2, cb2.hash(), extfvk, value);
|
||||
insert_into_cache(&db_cache, &cb3);
|
||||
match scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None) {
|
||||
Err(SqliteClientError::BackendError(e)) => {
|
||||
|
|
|
@ -16,7 +16,7 @@ pub enum SqliteClientError {
|
|||
/// The rcm value for a note cannot be decoded to a valid JubJub point.
|
||||
InvalidNote,
|
||||
|
||||
/// The note id associated with a witness being stored corresponds to a
|
||||
/// The note id associated with a witness being stored corresponds to a
|
||||
/// sent note, not a received note.
|
||||
InvalidNoteId,
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ impl<P: consensus::Parameters> WalletDB<P> {
|
|||
/// Given a wallet database connection, obtain a handle for the write operations
|
||||
/// for that database. This operation may eagerly initialize and cache sqlite
|
||||
/// prepared statements that are used in write operations.
|
||||
pub fn get_update_ops<'a>(&'a self) -> Result<DataConnStmtCache<'a, P>, SqliteClientError> {
|
||||
pub fn get_update_ops(&self) -> Result<DataConnStmtCache<'_, P>, SqliteClientError> {
|
||||
Ok(
|
||||
DataConnStmtCache {
|
||||
wallet_db: self,
|
||||
|
@ -220,6 +220,7 @@ impl<P: consensus::Parameters> WalletRead for WalletDB<P> {
|
|||
wallet::get_commitment_tree(self, block_height)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn get_witnesses(
|
||||
&self,
|
||||
block_height: BlockHeight,
|
||||
|
@ -317,10 +318,7 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> {
|
|||
self.wallet_db.get_balance_at(account, anchor_height)
|
||||
}
|
||||
|
||||
fn get_memo_as_utf8(
|
||||
&self,
|
||||
id_note: Self::NoteRef,
|
||||
) -> Result<Option<String>, Self::Error> {
|
||||
fn get_memo_as_utf8(&self, id_note: Self::NoteRef) -> Result<Option<String>, Self::Error> {
|
||||
self.wallet_db.get_memo_as_utf8(id_note)
|
||||
}
|
||||
|
||||
|
@ -331,6 +329,7 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> {
|
|||
self.wallet_db.get_commitment_tree(block_height)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn get_witnesses(
|
||||
&self,
|
||||
block_height: BlockHeight,
|
||||
|
@ -571,14 +570,14 @@ mod tests {
|
|||
let rseed = generate_random_rseed(&network(), height, &mut rng);
|
||||
let note = Note {
|
||||
g_d: to.diversifier().g_d().unwrap(),
|
||||
pk_d: to.pk_d().clone(),
|
||||
pk_d: *to.pk_d(),
|
||||
value: value.into(),
|
||||
rseed,
|
||||
};
|
||||
let encryptor = SaplingNoteEncryption::new(
|
||||
Some(extfvk.fvk.ovk),
|
||||
note.clone(),
|
||||
to.clone(),
|
||||
to,
|
||||
Memo::default(),
|
||||
&mut rng,
|
||||
);
|
||||
|
@ -631,7 +630,7 @@ mod tests {
|
|||
ctx.outputs.push({
|
||||
let note = Note {
|
||||
g_d: to.diversifier().g_d().unwrap(),
|
||||
pk_d: to.pk_d().clone(),
|
||||
pk_d: *to.pk_d(),
|
||||
value: value.into(),
|
||||
rseed,
|
||||
};
|
||||
|
@ -659,7 +658,7 @@ mod tests {
|
|||
let rseed = generate_random_rseed(&network(), height, &mut rng);
|
||||
let note = Note {
|
||||
g_d: change_addr.diversifier().g_d().unwrap(),
|
||||
pk_d: change_addr.pk_d().clone(),
|
||||
pk_d: *change_addr.pk_d(),
|
||||
value: (in_value - value).into(),
|
||||
rseed,
|
||||
};
|
||||
|
|
|
@ -565,7 +565,9 @@ pub fn put_received_note<'a, P, T: ShieldedOutput>(
|
|||
// It isn't there, so insert our note into the database.
|
||||
stmts.stmt_insert_received_note.execute_named(&sql_args)?;
|
||||
|
||||
Ok(NoteId::ReceivedNoteId(stmts.wallet_db.conn.last_insert_rowid()))
|
||||
Ok(NoteId::ReceivedNoteId(
|
||||
stmts.wallet_db.conn.last_insert_rowid(),
|
||||
))
|
||||
} else {
|
||||
// It was there, so grab its row number.
|
||||
stmts
|
||||
|
|
|
@ -416,12 +416,8 @@ mod tests {
|
|||
}
|
||||
|
||||
// Mine block 11 so that the second note becomes verified
|
||||
let (cb, _) = fake_compact_block(
|
||||
sapling_activation_height() + 10,
|
||||
cb.hash(),
|
||||
extfvk.clone(),
|
||||
value,
|
||||
);
|
||||
let (cb, _) =
|
||||
fake_compact_block(sapling_activation_height() + 10, cb.hash(), extfvk, value);
|
||||
insert_into_cache(&db_cache, &cb);
|
||||
scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap();
|
||||
|
||||
|
@ -460,7 +456,7 @@ mod tests {
|
|||
let (cb, _) = fake_compact_block(
|
||||
sapling_activation_height(),
|
||||
BlockHash([0; 32]),
|
||||
extfvk.clone(),
|
||||
extfvk,
|
||||
value,
|
||||
);
|
||||
insert_into_cache(&db_cache, &cb);
|
||||
|
|
|
@ -702,19 +702,14 @@ mod tests {
|
|||
.create_note(110000, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng)))
|
||||
.unwrap();
|
||||
let cm1 = Node::new(note1.cmu().to_repr());
|
||||
let mut tree = CommitmentTree::new();
|
||||
let mut tree = CommitmentTree::empty();
|
||||
// fake that the note appears in some previous
|
||||
// shielded output
|
||||
tree.append(cm1).unwrap();
|
||||
let witness1 = IncrementalWitness::from_tree(&tree);
|
||||
|
||||
builder_a
|
||||
.add_sapling_spend(
|
||||
extsk.clone(),
|
||||
*to.diversifier(),
|
||||
note1.clone(),
|
||||
witness1.path().unwrap(),
|
||||
)
|
||||
.add_sapling_spend(extsk, *to.diversifier(), note1, witness1.path().unwrap())
|
||||
.unwrap();
|
||||
|
||||
let mut db_a = DemoBuilder {
|
||||
|
|
|
@ -11,6 +11,7 @@ use blake2s_simd::Params;
|
|||
/// Produces a random point in the Jubjub curve.
|
||||
/// The point is guaranteed to be prime order
|
||||
/// and not the identity.
|
||||
#[allow(clippy::assertions_on_constants)]
|
||||
pub fn group_hash(tag: &[u8], personalization: &[u8]) -> Option<jubjub::SubgroupPoint> {
|
||||
assert_eq!(personalization.len(), 8);
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ pub struct CommitmentTree<Node: Hashable> {
|
|||
|
||||
impl<Node: Hashable> CommitmentTree<Node> {
|
||||
/// Creates an empty tree.
|
||||
pub fn new() -> Self {
|
||||
pub fn empty() -> Self {
|
||||
CommitmentTree {
|
||||
left: None,
|
||||
right: None,
|
||||
|
@ -66,6 +66,7 @@ impl<Node: Hashable> CommitmentTree<Node> {
|
|||
}
|
||||
|
||||
/// Reads a `CommitmentTree` from its serialized form.
|
||||
#[allow(clippy::redundant_closure)]
|
||||
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||
let left = Optional::read(&mut reader, |r| Node::read(r))?;
|
||||
let right = Optional::read(&mut reader, |r| Node::read(r))?;
|
||||
|
@ -203,7 +204,7 @@ impl<Node: Hashable> CommitmentTree<Node> {
|
|||
///
|
||||
/// let mut rng = OsRng;
|
||||
///
|
||||
/// let mut tree = CommitmentTree::<Node>::new();
|
||||
/// let mut tree = CommitmentTree::<Node>::empty();
|
||||
///
|
||||
/// tree.append(Node::new(bls12_381::Scalar::random(&mut rng).to_repr()));
|
||||
/// tree.append(Node::new(bls12_381::Scalar::random(&mut rng).to_repr()));
|
||||
|
@ -237,6 +238,7 @@ impl<Node: Hashable> IncrementalWitness<Node> {
|
|||
}
|
||||
|
||||
/// Reads an `IncrementalWitness` from its serialized form.
|
||||
#[allow(clippy::redundant_closure)]
|
||||
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||
let tree = CommitmentTree::read(&mut reader)?;
|
||||
let filled = Vector::read(&mut reader, |r| Node::read(r))?;
|
||||
|
@ -348,7 +350,7 @@ impl<Node: Hashable> IncrementalWitness<Node> {
|
|||
if self.cursor_depth == 0 {
|
||||
self.filled.push(node);
|
||||
} else {
|
||||
let mut cursor = CommitmentTree::new();
|
||||
let mut cursor = CommitmentTree::empty();
|
||||
cursor
|
||||
.append_inner(node, depth)
|
||||
.expect("cursor should not be full");
|
||||
|
@ -550,7 +552,7 @@ mod tests {
|
|||
|
||||
impl TestCommitmentTree {
|
||||
fn new() -> Self {
|
||||
TestCommitmentTree(CommitmentTree::new())
|
||||
TestCommitmentTree(CommitmentTree::empty())
|
||||
}
|
||||
|
||||
pub fn read<R: Read>(reader: R) -> io::Result<Self> {
|
||||
|
@ -618,7 +620,7 @@ mod tests {
|
|||
#[test]
|
||||
fn sapling_empty_root() {
|
||||
let mut tmp = [0u8; 32];
|
||||
CommitmentTree::<Node>::new()
|
||||
CommitmentTree::<Node>::empty()
|
||||
.root()
|
||||
.write(&mut tmp[..])
|
||||
.expect("length is 32 bytes");
|
||||
|
@ -630,7 +632,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn empty_commitment_tree_roots() {
|
||||
let tree = CommitmentTree::<Node>::new();
|
||||
let tree = CommitmentTree::<Node>::empty();
|
||||
let mut tmp = [0u8; 32];
|
||||
for (i, &expected) in HEX_EMPTY_ROOTS.iter().enumerate().skip(1) {
|
||||
tree.root_inner(i, PathFiller::empty())
|
||||
|
|
|
@ -635,6 +635,7 @@ pub fn try_sapling_output_recovery_with_ock<P: consensus::Parameters>(
|
|||
/// `PaymentAddress` to which the note was sent.
|
||||
///
|
||||
/// Implements section 4.17.3 of the Zcash Protocol Specification.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn try_sapling_output_recovery<P: consensus::Parameters>(
|
||||
params: &P,
|
||||
height: BlockHeight,
|
||||
|
|
|
@ -22,6 +22,7 @@ pub trait TxProver {
|
|||
/// the context for later use.
|
||||
///
|
||||
/// [`SpendDescription`]: crate::transaction::components::SpendDescription
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn spend_proof(
|
||||
&self,
|
||||
ctx: &mut Self::SaplingProvingContext,
|
||||
|
|
|
@ -296,6 +296,7 @@ impl TransparentInputs {
|
|||
}
|
||||
|
||||
#[cfg(feature = "zfuture")]
|
||||
#[allow(clippy::type_complexity)]
|
||||
struct TzeInputInfo<'a, BuildCtx> {
|
||||
prevout: TzeOut,
|
||||
builder: Box<dyn FnOnce(&BuildCtx) -> Result<(u32, Vec<u8>), Error> + 'a>,
|
||||
|
@ -1043,7 +1044,7 @@ mod tests {
|
|||
.create_note(50000, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng)))
|
||||
.unwrap();
|
||||
let cmu1 = Node::new(note1.cmu().to_repr());
|
||||
let mut tree = CommitmentTree::new();
|
||||
let mut tree = CommitmentTree::empty();
|
||||
tree.append(cmu1).unwrap();
|
||||
let witness1 = IncrementalWitness::from_tree(&tree);
|
||||
|
||||
|
@ -1136,7 +1137,7 @@ mod tests {
|
|||
.create_note(50999, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng)))
|
||||
.unwrap();
|
||||
let cmu1 = Node::new(note1.cmu().to_repr());
|
||||
let mut tree = CommitmentTree::new();
|
||||
let mut tree = CommitmentTree::empty();
|
||||
tree.append(cmu1).unwrap();
|
||||
let mut witness1 = IncrementalWitness::from_tree(&tree);
|
||||
|
||||
|
|
|
@ -1042,7 +1042,7 @@ mod tests {
|
|||
match xfvk.dk.diversifier(di) {
|
||||
Ok((l, d)) if l == di => assert_eq!(d.0, tv.d0.unwrap()),
|
||||
Ok((_, _)) => assert!(tv.d0.is_none()),
|
||||
Err(_) => panic!(),
|
||||
Err(()) => panic!(),
|
||||
}
|
||||
|
||||
// d1
|
||||
|
@ -1050,7 +1050,7 @@ mod tests {
|
|||
match xfvk.dk.diversifier(di) {
|
||||
Ok((l, d)) if l == di => assert_eq!(d.0, tv.d1.unwrap()),
|
||||
Ok((_, _)) => assert!(tv.d1.is_none()),
|
||||
Err(_) => panic!(),
|
||||
Err(()) => panic!(),
|
||||
}
|
||||
|
||||
// d2
|
||||
|
@ -1058,7 +1058,7 @@ mod tests {
|
|||
match xfvk.dk.diversifier(di) {
|
||||
Ok((l, d)) if l == di => assert_eq!(d.0, tv.d2.unwrap()),
|
||||
Ok((_, _)) => assert!(tv.d2.is_none()),
|
||||
Err(_) => panic!(),
|
||||
Err(()) => panic!(),
|
||||
}
|
||||
|
||||
// dmax
|
||||
|
|
|
@ -39,12 +39,9 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
randomness: jubjub::Fr::random(&mut rng),
|
||||
};
|
||||
|
||||
let nsk = jubjub::Fr::random(&mut rng);
|
||||
let ak = jubjub::SubgroupPoint::random(&mut rng);
|
||||
|
||||
let proof_generation_key = ProofGenerationKey {
|
||||
ak: ak.clone(),
|
||||
nsk: nsk.clone(),
|
||||
ak: jubjub::SubgroupPoint::random(&mut rng),
|
||||
nsk: jubjub::Fr::random(&mut rng),
|
||||
};
|
||||
|
||||
let viewing_key = proof_generation_key.to_viewing_key();
|
||||
|
|
|
@ -632,6 +632,7 @@ mod test {
|
|||
use bellman::gadgets::boolean::{AllocatedBit, Boolean};
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
fn test_into_edwards() {
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
|
||||
|
@ -680,7 +681,7 @@ mod test {
|
|||
let p = jubjub::ExtendedPoint::random(&mut rng);
|
||||
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
let q = EdwardsPoint::witness(&mut cs, Some(p.clone())).unwrap();
|
||||
let q = EdwardsPoint::witness(&mut cs, Some(p)).unwrap();
|
||||
|
||||
let p = p.to_affine();
|
||||
|
||||
|
@ -744,7 +745,7 @@ mod test {
|
|||
AllocatedBit::alloc(cs.namespace(|| format!("scalar bit {}", i)), Some(b))
|
||||
.unwrap()
|
||||
})
|
||||
.map(|v| Boolean::from(v))
|
||||
.map(Boolean::from)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let q = fixed_base_multiplication(
|
||||
|
@ -795,7 +796,7 @@ mod test {
|
|||
AllocatedBit::alloc(cs.namespace(|| format!("scalar bit {}", i)), Some(b))
|
||||
.unwrap()
|
||||
})
|
||||
.map(|v| Boolean::from(v))
|
||||
.map(Boolean::from)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let q = p.mul(cs.namespace(|| "scalar mul"), &s_bits).unwrap();
|
||||
|
@ -1080,7 +1081,7 @@ mod test {
|
|||
|
||||
// generator for the prime subgroup
|
||||
let g_prime = g * largest_small_subgroup_order;
|
||||
check_small_order_from_p(g_prime.clone(), false);
|
||||
check_small_order_from_p(g_prime, false);
|
||||
let prime_subgroup_order_minus_1 = prime_subgroup_order - jubjub::Fr::one();
|
||||
|
||||
let should_not_be_zero = g_prime * prime_subgroup_order_minus_1;
|
||||
|
@ -1093,7 +1094,7 @@ mod test {
|
|||
// generator for the small order subgroup
|
||||
let g_small = g * prime_subgroup_order_minus_1;
|
||||
let g_small = g_small + g;
|
||||
check_small_order_from_p(g_small.clone(), true);
|
||||
check_small_order_from_p(g_small, true);
|
||||
|
||||
// g_small does have order 8
|
||||
let largest_small_subgroup_order_minus_1 = largest_small_subgroup_order - jubjub::Fr::one();
|
||||
|
|
|
@ -132,10 +132,10 @@ mod test {
|
|||
let convert_segment = 2; // Conversion to Edwards
|
||||
let add_segments = 6; // Edwards addition
|
||||
|
||||
return (chunks) * lookup_chunk - precomputed_booleans
|
||||
(chunks) * lookup_chunk - precomputed_booleans
|
||||
+ segments * convert_segment
|
||||
+ all_but_last_segments * ((63 - 1) * add_chunks + add_segments)
|
||||
+ (last_chunks - 1) * add_chunks;
|
||||
+ (last_chunks - 1) * add_chunks
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -534,12 +534,9 @@ fn test_input_circuit_with_bls12_381() {
|
|||
randomness: jubjub::Fr::random(&mut rng),
|
||||
};
|
||||
|
||||
let nsk = jubjub::Fr::random(&mut rng);
|
||||
let ak = jubjub::SubgroupPoint::random(&mut rng);
|
||||
|
||||
let proof_generation_key = ProofGenerationKey {
|
||||
ak: ak.clone(),
|
||||
nsk: nsk.clone(),
|
||||
ak: jubjub::SubgroupPoint::random(&mut rng),
|
||||
nsk: jubjub::Fr::random(&mut rng),
|
||||
};
|
||||
|
||||
let viewing_key = proof_generation_key.to_viewing_key();
|
||||
|
@ -571,14 +568,14 @@ fn test_input_circuit_with_bls12_381() {
|
|||
jubjub::ExtendedPoint::from(value_commitment.commitment()).to_affine();
|
||||
let note = Note {
|
||||
value: value_commitment.value,
|
||||
g_d: g_d.clone(),
|
||||
pk_d: payment_address.pk_d().clone(),
|
||||
rseed: Rseed::BeforeZip212(commitment_randomness.clone()),
|
||||
g_d,
|
||||
pk_d: *payment_address.pk_d(),
|
||||
rseed: Rseed::BeforeZip212(commitment_randomness),
|
||||
};
|
||||
|
||||
let mut position = 0u64;
|
||||
let cmu = note.cmu();
|
||||
let mut cur = cmu.clone();
|
||||
let mut cur = cmu;
|
||||
|
||||
for (i, val) in auth_path.clone().into_iter().enumerate() {
|
||||
let (uncle, b) = val.unwrap();
|
||||
|
@ -706,12 +703,9 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() {
|
|||
randomness: jubjub::Fr::from_str(&(1000 * (i + 1)).to_string()).unwrap(),
|
||||
};
|
||||
|
||||
let nsk = jubjub::Fr::random(&mut rng);
|
||||
let ak = jubjub::SubgroupPoint::random(&mut rng);
|
||||
|
||||
let proof_generation_key = ProofGenerationKey {
|
||||
ak: ak.clone(),
|
||||
nsk: nsk.clone(),
|
||||
ak: jubjub::SubgroupPoint::random(&mut rng),
|
||||
nsk: jubjub::Fr::random(&mut rng),
|
||||
};
|
||||
|
||||
let viewing_key = proof_generation_key.to_viewing_key();
|
||||
|
@ -751,14 +745,14 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() {
|
|||
);
|
||||
let note = Note {
|
||||
value: value_commitment.value,
|
||||
g_d: g_d.clone(),
|
||||
pk_d: payment_address.pk_d().clone(),
|
||||
rseed: Rseed::BeforeZip212(commitment_randomness.clone()),
|
||||
g_d,
|
||||
pk_d: *payment_address.pk_d(),
|
||||
rseed: Rseed::BeforeZip212(commitment_randomness),
|
||||
};
|
||||
|
||||
let mut position = 0u64;
|
||||
let cmu = note.cmu();
|
||||
let mut cur = cmu.clone();
|
||||
let mut cur = cmu;
|
||||
|
||||
for (i, val) in auth_path.clone().into_iter().enumerate() {
|
||||
let (uncle, b) = val.unwrap();
|
||||
|
@ -858,10 +852,7 @@ fn test_output_circuit_with_bls12_381() {
|
|||
let nsk = jubjub::Fr::random(&mut rng);
|
||||
let ak = jubjub::SubgroupPoint::random(&mut rng);
|
||||
|
||||
let proof_generation_key = ProofGenerationKey {
|
||||
ak: ak.clone(),
|
||||
nsk: nsk.clone(),
|
||||
};
|
||||
let proof_generation_key = ProofGenerationKey { ak, nsk };
|
||||
|
||||
let viewing_key = proof_generation_key.to_viewing_key();
|
||||
|
||||
|
@ -890,7 +881,7 @@ fn test_output_circuit_with_bls12_381() {
|
|||
value_commitment: Some(value_commitment.clone()),
|
||||
payment_address: Some(payment_address.clone()),
|
||||
commitment_randomness: Some(commitment_randomness),
|
||||
esk: Some(esk.clone()),
|
||||
esk: Some(esk),
|
||||
};
|
||||
|
||||
instance.synthesize(&mut cs).unwrap();
|
||||
|
|
|
@ -13,6 +13,7 @@ pub struct InputNote {
|
|||
}
|
||||
|
||||
impl InputNote {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute<Scalar, CS>(
|
||||
mut cs: CS,
|
||||
a_sk: Option<SpendingKey>,
|
||||
|
|
|
@ -347,14 +347,14 @@ fn test_sprout_constraints() {
|
|||
fn get_u256<R: ReadBytesExt>(mut reader: R) -> [u8; 32] {
|
||||
let mut result = [0u8; 32];
|
||||
|
||||
for i in 0..32 {
|
||||
result[i] = reader.read_u8().unwrap();
|
||||
for b in &mut result {
|
||||
*b = reader.read_u8().unwrap();
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
while test_vector.len() != 0 {
|
||||
while !test_vector.is_empty() {
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let phi = Some(get_u256(&mut test_vector));
|
||||
|
@ -374,8 +374,10 @@ fn test_sprout_constraints() {
|
|||
auth_path[i] = Some((sibling, false));
|
||||
}
|
||||
let mut position = test_vector.read_u64::<LittleEndian>().unwrap();
|
||||
for i in 0..TREE_DEPTH {
|
||||
auth_path[i].as_mut().map(|p| p.1 = (position & 1) == 1);
|
||||
for sibling in &mut auth_path {
|
||||
if let Some(p) = sibling {
|
||||
p.1 = (position & 1) == 1;
|
||||
}
|
||||
|
||||
position >>= 1;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use bellman::gadgets::sha256::sha256_block_no_padding;
|
|||
use bellman::{ConstraintSystem, SynthesisError};
|
||||
use ff::PrimeField;
|
||||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
fn prf<Scalar, CS>(
|
||||
cs: CS,
|
||||
a: bool,
|
||||
|
|
|
@ -90,6 +90,7 @@ pub fn generate_circuit_generator(mut gen: jubjub::SubgroupPoint) -> FixedGenera
|
|||
|
||||
/// Returns the coordinates of this point's Montgomery curve representation, or `None` if
|
||||
/// it is the point at infinity.
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
pub(crate) fn to_montgomery_coords(g: ExtendedPoint) -> Option<(Scalar, Scalar)> {
|
||||
let g = g.to_affine();
|
||||
let (x, y) = (g.get_u(), g.get_v());
|
||||
|
|
|
@ -65,10 +65,9 @@ pub fn default_params_folder() -> Option<PathBuf> {
|
|||
#[cfg_attr(docsrs, doc(cfg(feature = "download-params")))]
|
||||
pub fn download_parameters() -> Result<(), minreq::Error> {
|
||||
// Ensure that the default Zcash parameters location exists.
|
||||
let params_dir = default_params_folder().ok_or(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Could not load default params folder",
|
||||
))?;
|
||||
let params_dir = default_params_folder().ok_or_else(|| {
|
||||
io::Error::new(io::ErrorKind::Other, "Could not load default params folder")
|
||||
})?;
|
||||
std::fs::create_dir_all(¶ms_dir)?;
|
||||
|
||||
let fetch_params = |name: &str, expected_hash: &str| -> Result<(), minreq::Error> {
|
||||
|
@ -111,17 +110,19 @@ pub fn download_parameters() -> Result<(), minreq::Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub struct ZcashParameters {
|
||||
pub spend_params: Parameters<Bls12>,
|
||||
pub spend_vk: PreparedVerifyingKey<Bls12>,
|
||||
pub output_params: Parameters<Bls12>,
|
||||
pub output_vk: PreparedVerifyingKey<Bls12>,
|
||||
pub sprout_vk: Option<PreparedVerifyingKey<Bls12>>,
|
||||
}
|
||||
|
||||
pub fn load_parameters(
|
||||
spend_path: &Path,
|
||||
output_path: &Path,
|
||||
sprout_path: Option<&Path>,
|
||||
) -> (
|
||||
Parameters<Bls12>,
|
||||
PreparedVerifyingKey<Bls12>,
|
||||
Parameters<Bls12>,
|
||||
PreparedVerifyingKey<Bls12>,
|
||||
Option<PreparedVerifyingKey<Bls12>>,
|
||||
) {
|
||||
) -> ZcashParameters {
|
||||
// Load from each of the paths
|
||||
let spend_fs = File::open(spend_path).expect("couldn't load Sapling spend parameters file");
|
||||
let output_fs = File::open(output_path).expect("couldn't load Sapling output parameters file");
|
||||
|
@ -142,13 +143,7 @@ pub fn parse_parameters<R: io::Read>(
|
|||
spend_fs: R,
|
||||
output_fs: R,
|
||||
sprout_fs: Option<R>,
|
||||
) -> (
|
||||
Parameters<Bls12>,
|
||||
PreparedVerifyingKey<Bls12>,
|
||||
Parameters<Bls12>,
|
||||
PreparedVerifyingKey<Bls12>,
|
||||
Option<PreparedVerifyingKey<Bls12>>,
|
||||
) {
|
||||
) -> ZcashParameters {
|
||||
let mut spend_fs = hashreader::HashReader::new(spend_fs);
|
||||
let mut output_fs = hashreader::HashReader::new(output_fs);
|
||||
let mut sprout_fs = sprout_fs.map(hashreader::HashReader::new);
|
||||
|
@ -201,5 +196,11 @@ pub fn parse_parameters<R: io::Read>(
|
|||
let output_vk = prepare_verifying_key(&output_params.vk);
|
||||
let sprout_vk = sprout_vk.map(|vk| prepare_verifying_key(&vk));
|
||||
|
||||
(spend_params, spend_vk, output_params, output_vk, sprout_vk)
|
||||
ZcashParameters {
|
||||
spend_params,
|
||||
spend_vk,
|
||||
output_params,
|
||||
output_vk,
|
||||
sprout_vk,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,12 +45,11 @@ impl LocalTxProver {
|
|||
/// This function will panic if the paths do not point to valid parameter files with
|
||||
/// the expected hashes.
|
||||
pub fn new(spend_path: &Path, output_path: &Path) -> Self {
|
||||
let (spend_params, spend_vk, output_params, _, _) =
|
||||
load_parameters(spend_path, output_path, None);
|
||||
let p = load_parameters(spend_path, output_path, None);
|
||||
LocalTxProver {
|
||||
spend_params,
|
||||
spend_vk,
|
||||
output_params,
|
||||
spend_params: p.spend_params,
|
||||
spend_vk: p.spend_vk,
|
||||
output_params: p.output_params,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,13 +69,12 @@ impl LocalTxProver {
|
|||
/// This function will panic if the byte arrays do not contain valid parameters with
|
||||
/// the expected hashes.
|
||||
pub fn from_bytes(spend_param_bytes: &[u8], output_param_bytes: &[u8]) -> Self {
|
||||
let (spend_params, spend_vk, output_params, _, _) =
|
||||
parse_parameters(spend_param_bytes, output_param_bytes, None);
|
||||
let p = parse_parameters(spend_param_bytes, output_param_bytes, None);
|
||||
|
||||
LocalTxProver {
|
||||
spend_params,
|
||||
spend_vk,
|
||||
output_params,
|
||||
spend_params: p.spend_params,
|
||||
spend_vk: p.spend_vk,
|
||||
output_params: p.output_params,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,13 +126,12 @@ impl LocalTxProver {
|
|||
#[cfg_attr(docsrs, doc(cfg(feature = "bundled-prover")))]
|
||||
pub fn bundled() -> Self {
|
||||
let (spend_buf, output_buf) = wagyu_zcash_parameters::load_sapling_parameters();
|
||||
let (spend_params, spend_vk, output_params, _, _) =
|
||||
parse_parameters(&spend_buf[..], &output_buf[..], None);
|
||||
let p = parse_parameters(&spend_buf[..], &output_buf[..], None);
|
||||
|
||||
LocalTxProver {
|
||||
spend_params,
|
||||
spend_vk,
|
||||
output_params,
|
||||
spend_params: p.spend_params,
|
||||
spend_vk: p.spend_vk,
|
||||
output_params: p.output_params,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ impl SaplingProvingContext {
|
|||
/// Create the value commitment, re-randomized key, and proof for a Sapling
|
||||
/// SpendDescription, while accumulating its value commitment randomness
|
||||
/// inside the context for later use.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn spend_proof(
|
||||
&mut self,
|
||||
proof_generation_key: ProofGenerationKey,
|
||||
|
|
|
@ -34,6 +34,7 @@ impl SaplingVerificationContext {
|
|||
|
||||
/// Perform consensus checks on a Sapling SpendDescription, while
|
||||
/// accumulating its value commitment inside the context for later use.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn check_spend(
|
||||
&mut self,
|
||||
cv: jubjub::ExtendedPoint,
|
||||
|
|
|
@ -15,6 +15,7 @@ const GROTH_PROOF_SIZE: usize = 48 // π_A
|
|||
pub const WITNESS_PATH_SIZE: usize = 1 + 33 * TREE_DEPTH + 8;
|
||||
|
||||
/// Sprout JoinSplit proof generation.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create_proof(
|
||||
phi: [u8; 32],
|
||||
rt: [u8; 32],
|
||||
|
@ -133,6 +134,7 @@ pub fn create_proof(
|
|||
}
|
||||
|
||||
/// Sprout JoinSplit proof verification.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn verify_proof(
|
||||
proof: &[u8; GROTH_PROOF_SIZE],
|
||||
rt: &[u8; 32],
|
||||
|
|
Loading…
Reference in New Issue