Fix Clippy beta linting complaints.

This commit is contained in:
Kris Nuttycombe 2022-02-01 14:02:07 -07:00
parent 4f4a25252f
commit a304c3953b
31 changed files with 179 additions and 183 deletions

View File

@ -314,7 +314,7 @@ fn tree_validator(p: &Params, state: &Blake2bState, indices: &[u32]) -> Result<N
validate_subtrees(p, &a, &b).map_err(Error)?;
Ok(Node::from_children(a, b, p.collision_byte_length()))
} else {
Ok(Node::new(&p, &state, indices[0]))
Ok(Node::new(p, state, indices[0]))
}
}
@ -486,13 +486,13 @@ mod tests {
fn invalid_test_vectors() {
for tv in INVALID_TEST_VECTORS {
assert_eq!(
is_valid_solution_iterative(tv.params, tv.input, &tv.nonce, &tv.solution)
is_valid_solution_iterative(tv.params, tv.input, &tv.nonce, tv.solution)
.unwrap_err()
.0,
tv.error
);
assert_eq!(
is_valid_solution_recursive(tv.params, tv.input, &tv.nonce, &tv.solution)
is_valid_solution_recursive(tv.params, tv.input, &tv.nonce, tv.solution)
.unwrap_err()
.0,
tv.error

View File

@ -94,7 +94,7 @@ impl<'a> State<'a> {
let hash = Blake2bParams::new()
.hash_length(self.left.len())
.personal(&H_PERS!(i))
.hash(&self.right);
.hash(self.right);
xor(self.left, hash.as_bytes())
}
@ -103,7 +103,7 @@ impl<'a> State<'a> {
let hash = Blake2bParams::new()
.hash_length(OUTBYTES)
.personal(&G_PERS!(i, j as u16))
.hash(&self.left);
.hash(self.left);
xor(&mut self.right[j * OUTBYTES..], hash.as_bytes());
}
}
@ -198,11 +198,11 @@ mod common_tests {
#[cfg(feature = "std")]
let mut cache = vec![0u8; test_vectors::MAX_VECTOR_LENGTH];
for v in test_vectors::TEST_VECTORS {
let mut data = &mut cache[..v.normal.len()];
data.clone_from_slice(&v.normal);
f4jumble_mut(&mut data).unwrap();
let data = &mut cache[..v.normal.len()];
data.clone_from_slice(v.normal);
f4jumble_mut(data).unwrap();
assert_eq!(data, v.jumbled);
f4jumble_inv_mut(&mut data).unwrap();
f4jumble_inv_mut(data).unwrap();
assert_eq!(data, v.normal);
}
}
@ -246,9 +246,9 @@ mod std_tests {
#[test]
fn f4jumble_check_vectors() {
for v in test_vectors::TEST_VECTORS {
let jumbled = f4jumble(&v.normal).unwrap();
let jumbled = f4jumble(v.normal).unwrap();
assert_eq!(jumbled, v.jumbled);
let unjumbled = f4jumble_inv(&v.jumbled).unwrap();
let unjumbled = f4jumble_inv(v.jumbled).unwrap();
assert_eq!(unjumbled, v.normal);
}
}

View File

@ -475,7 +475,7 @@ impl<D: Domain> NoteEncryption<D> {
rng: &mut R,
) -> [u8; OUT_CIPHERTEXT_SIZE] {
let (ock, input) = if let Some(ovk) = &self.ovk {
let ock = D::derive_ock(ovk, &cv, &cmstar.into(), &D::epk_bytes(&self.epk));
let ock = D::derive_ock(ovk, cv, &cmstar.into(), &D::epk_bytes(&self.epk));
let input = D::outgoing_plaintext_bytes(&self.note, &self.esk);
(ock, input)
@ -563,7 +563,7 @@ fn parse_note_plaintext_without_memo_ivk<D: Domain>(
cmstar_bytes: &D::ExtractedCommitmentBytes,
plaintext: &[u8],
) -> Option<(D::Note, D::Recipient)> {
let (note, to) = domain.parse_note_plaintext_without_memo_ivk(ivk, &plaintext)?;
let (note, to) = domain.parse_note_plaintext_without_memo_ivk(ivk, plaintext)?;
if let NoteValidity::Valid = check_note_validity::<D>(&note, ephemeral_key, cmstar_bytes) {
Some((note, to))
@ -577,10 +577,10 @@ fn check_note_validity<D: Domain>(
ephemeral_key: &EphemeralKeyBytes,
cmstar_bytes: &D::ExtractedCommitmentBytes,
) -> NoteValidity {
if &D::ExtractedCommitmentBytes::from(&D::cmstar(&note)) == cmstar_bytes {
if &D::ExtractedCommitmentBytes::from(&D::cmstar(note)) == cmstar_bytes {
if let Some(derived_esk) = D::derive_esk(note) {
if D::epk_bytes(&D::ka_derive_public(&note, &derived_esk))
.ct_eq(&ephemeral_key)
if D::epk_bytes(&D::ka_derive_public(note, &derived_esk))
.ct_eq(ephemeral_key)
.into()
{
NoteValidity::Valid
@ -614,7 +614,7 @@ pub fn try_compact_note_decryption<D: Domain, Output: ShieldedOutput<D, COMPACT_
let ephemeral_key = output.ephemeral_key();
let epk = D::epk(&ephemeral_key)?;
let shared_secret = D::ka_agree_dec(&ivk, &epk);
let shared_secret = D::ka_agree_dec(ivk, &epk);
let key = D::kdf(shared_secret, &ephemeral_key);
try_compact_note_decryption_inner(domain, ivk, &ephemeral_key, output, key)
@ -659,7 +659,7 @@ pub fn try_output_recovery_with_ovk<D: Domain, Output: ShieldedOutput<D, ENC_CIP
cv: &D::ValueCommitment,
out_ciphertext: &[u8; OUT_CIPHERTEXT_SIZE],
) -> Option<(D::Note, D::Recipient, D::Memo)> {
let ock = D::derive_ock(ovk, &cv, &output.cmstar_bytes(), &output.ephemeral_key());
let ock = D::derive_ock(ovk, cv, &output.cmstar_bytes(), &output.ephemeral_key());
try_output_recovery_with_ock(domain, &ock, output, out_ciphertext)
}

View File

@ -347,7 +347,7 @@ where
Err(Error::MemoForbidden)
} else {
builder
.add_transparent_output(&to, payment.amount)
.add_transparent_output(to, payment.amount)
.map_err(Error::Builder)
}
}
@ -439,7 +439,7 @@ where
{
// Check that the ExtendedSpendingKey we have been given corresponds to the
// ExtendedFullViewingKey for the account we are spending from.
if !wallet_db.is_valid_account_extfvk(account, &extfvk)? {
if !wallet_db.is_valid_account_extfvk(account, extfvk)? {
return Err(E::from(Error::InvalidExtSk(account)));
}

View File

@ -32,7 +32,7 @@ where
{
match bech32::decode(s)? {
(decoded_hrp, data, Variant::Bech32) if decoded_hrp == hrp => {
Vec::<u8>::from_base32(&data).map(|data| read(data))
Vec::<u8>::from_base32(&data).map(read)
}
_ => Ok(None),
}

View File

@ -35,7 +35,7 @@ pub mod sapling {
}
ExtendedSpendingKey::from_path(
&ExtendedSpendingKey::master(&seed),
&ExtendedSpendingKey::master(seed),
&[
ChildIndex::Hardened(32),
ChildIndex::Hardened(coin_type),

View File

@ -68,7 +68,7 @@ fn scan_output<P: consensus::Parameters, K: ScanningKey>(
// - Change created by spending fractions of notes.
// - Notes created by consolidation transactions.
// - Notes sent from one account to itself.
let is_change = spent_from_accounts.contains(&account);
let is_change = spent_from_accounts.contains(account);
let witness = IncrementalWitness::from_tree(tree);
let nf = vk.nf(&note, &witness);

View File

@ -173,32 +173,32 @@ impl TransactionRequest {
payment
.memo
.as_ref()
.map(|m| render::memo_param(&m, payment_index)),
.map(|m| render::memo_param(m, payment_index)),
)
.chain(
payment
.label
.as_ref()
.map(|m| render::str_param("label", &m, payment_index)),
.map(|m| render::str_param("label", m, payment_index)),
)
.chain(
payment
.message
.as_ref()
.map(|m| render::str_param("message", &m, payment_index)),
.map(|m| render::str_param("message", m, payment_index)),
)
.chain(
payment
.other_params
.iter()
.map(move |(name, value)| render::str_param(&name, &value, payment_index)),
.map(move |(name, value)| render::str_param(name, value, payment_index)),
)
}
match &self.payments[..] {
[] => None,
[payment] => {
let query_params = payment_params(&payment, None)
let query_params = payment_params(payment, None)
.into_iter()
.collect::<Vec<String>>();
@ -217,7 +217,7 @@ impl TransactionRequest {
let primary_address = payment.recipient_address.clone();
std::iter::empty()
.chain(Some(render::addr_param(params, &primary_address, Some(i))))
.chain(payment_params(&payment, Some(i)))
.chain(payment_params(payment, Some(i)))
})
.collect::<Vec<String>>();
@ -255,7 +255,7 @@ impl TransactionRequest {
}
Some(current) => {
if parse::has_duplicate_param(&current, &p.param) {
if parse::has_duplicate_param(current, &p.param) {
return Err(Zip321Error::DuplicateParameter(p.param, p.payment_index));
} else {
current.push(p.param);
@ -775,12 +775,12 @@ mod tests {
#[test]
fn test_zip321_parse_simple() {
let uri = "zcash:ztestsapling1n65uaftvs2g7075q2x2a04shfk066u3lldzxsrprfrqtzxnhc9ps73v4lhx4l9yfxj46sl0q90k?amount=3768769.02796286&message=";
let parse_result = TransactionRequest::from_uri(&TEST_NETWORK, &uri).unwrap();
let parse_result = TransactionRequest::from_uri(&TEST_NETWORK, uri).unwrap();
let expected = TransactionRequest {
payments: vec![
Payment {
recipient_address: RecipientAddress::Shielded(decode_payment_address(&TEST_NETWORK.hrp_sapling_payment_address(), "ztestsapling1n65uaftvs2g7075q2x2a04shfk066u3lldzxsrprfrqtzxnhc9ps73v4lhx4l9yfxj46sl0q90k").unwrap().unwrap()),
recipient_address: RecipientAddress::Shielded(decode_payment_address(TEST_NETWORK.hrp_sapling_payment_address(), "ztestsapling1n65uaftvs2g7075q2x2a04shfk066u3lldzxsrprfrqtzxnhc9ps73v4lhx4l9yfxj46sl0q90k").unwrap().unwrap()),
amount: Amount::from_u64(376876902796286).unwrap(),
memo: None,
label: None,
@ -833,14 +833,14 @@ mod tests {
#[test]
fn test_zip321_spec_valid_examples() {
let valid_1 = "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=1&memo=VGhpcyBpcyBhIHNpbXBsZSBtZW1vLg&message=Thank%20you%20for%20your%20purchase";
let v1r = TransactionRequest::from_uri(&TEST_NETWORK, &valid_1).unwrap();
let v1r = TransactionRequest::from_uri(&TEST_NETWORK, valid_1).unwrap();
assert_eq!(
v1r.payments.get(0).map(|p| p.amount),
Some(Amount::from_u64(100000000).unwrap())
);
let valid_2 = "zcash:?address=tmEZhbWHTpdKMw5it8YDspUXSMGQyFwovpU&amount=123.456&address.1=ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez&amount.1=0.789&memo.1=VGhpcyBpcyBhIHVuaWNvZGUgbWVtbyDinKjwn6aE8J-PhvCfjok";
let mut v2r = TransactionRequest::from_uri(&TEST_NETWORK, &valid_2).unwrap();
let mut v2r = TransactionRequest::from_uri(&TEST_NETWORK, valid_2).unwrap();
v2r.normalize(&TEST_NETWORK);
assert_eq!(
v2r.payments.get(0).map(|p| p.amount),
@ -854,7 +854,7 @@ mod tests {
// valid; amount just less than MAX_MONEY
// 20999999.99999999
let valid_3 = "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=20999999.99999999";
let v3r = TransactionRequest::from_uri(&TEST_NETWORK, &valid_3).unwrap();
let v3r = TransactionRequest::from_uri(&TEST_NETWORK, valid_3).unwrap();
assert_eq!(
v3r.payments.get(0).map(|p| p.amount),
Some(Amount::from_u64(2099999999999999u64).unwrap())
@ -863,7 +863,7 @@ mod tests {
// valid; MAX_MONEY
// 21000000
let valid_4 = "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=21000000";
let v4r = TransactionRequest::from_uri(&TEST_NETWORK, &valid_4).unwrap();
let v4r = TransactionRequest::from_uri(&TEST_NETWORK, valid_4).unwrap();
assert_eq!(
v4r.payments.get(0).map(|p| p.amount),
Some(Amount::from_u64(2100000000000000u64).unwrap())
@ -874,63 +874,63 @@ mod tests {
fn test_zip321_spec_invalid_examples() {
// invalid; missing `address=`
let invalid_1 = "zcash:?amount=3491405.05201255&address.1=ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez&amount.1=5740296.87793245";
let i1r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_1);
let i1r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_1);
assert!(i1r.is_err());
// invalid; missing `address.1=`
let invalid_2 = "zcash:?address=tmEZhbWHTpdKMw5it8YDspUXSMGQyFwovpU&amount=1&amount.1=2&address.2=ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez";
let i2r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_2);
let i2r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_2);
assert!(i2r.is_err());
// invalid; `address.0=` and `amount.0=` are not permitted (leading 0s).
let invalid_3 = "zcash:?address.0=ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez&amount.0=2";
let i3r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_3);
let i3r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_3);
assert!(i3r.is_err());
// invalid; duplicate `amount=` field
let invalid_4 =
"zcash:?amount=1.234&amount=2.345&address=tmEZhbWHTpdKMw5it8YDspUXSMGQyFwovpU";
let i4r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_4);
let i4r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_4);
assert!(i4r.is_err());
// invalid; duplicate `amount.1=` field
let invalid_5 =
"zcash:?amount.1=1.234&amount.1=2.345&address.1=tmEZhbWHTpdKMw5it8YDspUXSMGQyFwovpU";
let i5r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_5);
let i5r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_5);
assert!(i5r.is_err());
//invalid; memo associated with t-addr
let invalid_6 = "zcash:?address=tmEZhbWHTpdKMw5it8YDspUXSMGQyFwovpU&amount=123.456&memo=eyAia2V5IjogIlRoaXMgaXMgYSBKU09OLXN0cnVjdHVyZWQgbWVtby4iIH0&address.1=ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez&amount.1=0.789&memo.1=VGhpcyBpcyBhIHVuaWNvZGUgbWVtbyDinKjwn6aE8J-PhvCfjok";
let i6r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_6);
let i6r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_6);
assert!(i6r.is_err());
// invalid; amount component exceeds an i64
// 9223372036854775808 = i64::MAX + 1
let invalid_7 = "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=9223372036854775808";
let i7r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_7);
let i7r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_7);
assert!(i7r.is_err());
// invalid; amount component wraps into a valid small positive i64
// 18446744073709551624
let invalid_7a = "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=18446744073709551624";
let i7ar = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_7a);
let i7ar = TransactionRequest::from_uri(&TEST_NETWORK, invalid_7a);
assert!(i7ar.is_err());
// invalid; amount component is MAX_MONEY
// 21000000.00000001
let invalid_8 = "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=21000000.00000001";
let i8r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_8);
let i8r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_8);
assert!(i8r.is_err());
// invalid; negative amount
let invalid_9 = "zcash:ztestsapling10yy2ex5dcqkclhc7z7yrnjq2z6feyjad56ptwlfgmy77dmaqqrl9gyhprdx59qgmsnyfska2kez?amount=-1";
let i9r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_9);
let i9r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_9);
assert!(i9r.is_err());
// invalid; parameter index too large
let invalid_10 =
"zcash:?amount.10000=1.23&address.10000=tmEZhbWHTpdKMw5it8YDspUXSMGQyFwovpU";
let i10r = TransactionRequest::from_uri(&TEST_NETWORK, &invalid_10);
let i10r = TransactionRequest::from_uri(&TEST_NETWORK, invalid_10);
assert!(i10r.is_err());
}

View File

@ -212,29 +212,29 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
fn block_height_extrema(&self) -> Result<Option<(BlockHeight, BlockHeight)>, Self::Error> {
#[allow(deprecated)]
wallet::block_height_extrema(&self).map_err(SqliteClientError::from)
wallet::block_height_extrema(self).map_err(SqliteClientError::from)
}
fn get_block_hash(&self, block_height: BlockHeight) -> Result<Option<BlockHash>, Self::Error> {
#[allow(deprecated)]
wallet::get_block_hash(&self, block_height).map_err(SqliteClientError::from)
wallet::get_block_hash(self, block_height).map_err(SqliteClientError::from)
}
fn get_tx_height(&self, txid: TxId) -> Result<Option<BlockHeight>, Self::Error> {
#[allow(deprecated)]
wallet::get_tx_height(&self, txid).map_err(SqliteClientError::from)
wallet::get_tx_height(self, txid).map_err(SqliteClientError::from)
}
fn get_extended_full_viewing_keys(
&self,
) -> Result<HashMap<AccountId, ExtendedFullViewingKey>, Self::Error> {
#[allow(deprecated)]
wallet::get_extended_full_viewing_keys(&self)
wallet::get_extended_full_viewing_keys(self)
}
fn get_address(&self, account: AccountId) -> Result<Option<PaymentAddress>, Self::Error> {
#[allow(deprecated)]
wallet::get_address(&self, account)
wallet::get_address(self, account)
}
fn is_valid_account_extfvk(
@ -243,7 +243,7 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
extfvk: &ExtendedFullViewingKey,
) -> Result<bool, Self::Error> {
#[allow(deprecated)]
wallet::is_valid_account_extfvk(&self, account, extfvk)
wallet::is_valid_account_extfvk(self, account, extfvk)
}
fn get_balance_at(
@ -252,12 +252,12 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
anchor_height: BlockHeight,
) -> Result<Amount, Self::Error> {
#[allow(deprecated)]
wallet::get_balance_at(&self, account, anchor_height)
wallet::get_balance_at(self, account, anchor_height)
}
fn get_transaction(&self, id_tx: i64) -> Result<Transaction, Self::Error> {
#[allow(deprecated)]
wallet::get_transaction(&self, id_tx)
wallet::get_transaction(self, id_tx)
}
fn get_memo(&self, id_note: Self::NoteRef) -> Result<Memo, Self::Error> {
@ -273,7 +273,7 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
block_height: BlockHeight,
) -> Result<Option<CommitmentTree<Node>>, Self::Error> {
#[allow(deprecated)]
wallet::get_commitment_tree(&self, block_height)
wallet::get_commitment_tree(self, block_height)
}
#[allow(clippy::type_complexity)]
@ -282,17 +282,17 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
block_height: BlockHeight,
) -> Result<Vec<(Self::NoteRef, IncrementalWitness<Node>)>, Self::Error> {
#[allow(deprecated)]
wallet::get_witnesses(&self, block_height)
wallet::get_witnesses(self, block_height)
}
fn get_nullifiers(&self) -> Result<Vec<(AccountId, Nullifier)>, Self::Error> {
#[allow(deprecated)]
wallet::get_nullifiers(&self)
wallet::get_nullifiers(self)
}
fn get_all_nullifiers(&self) -> Result<Vec<(AccountId, Nullifier)>, Self::Error> {
#[allow(deprecated)]
wallet::get_all_nullifiers(&self)
wallet::get_all_nullifiers(self)
}
fn get_spendable_sapling_notes(
@ -301,7 +301,7 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
anchor_height: BlockHeight,
) -> Result<Vec<SpendableNote>, Self::Error> {
#[allow(deprecated)]
wallet::transact::get_spendable_sapling_notes(&self, account, anchor_height)
wallet::transact::get_spendable_sapling_notes(self, account, anchor_height)
}
fn select_spendable_sapling_notes(
@ -311,12 +311,7 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
anchor_height: BlockHeight,
) -> Result<Vec<SpendableNote>, Self::Error> {
#[allow(deprecated)]
wallet::transact::select_spendable_sapling_notes(
&self,
account,
target_value,
anchor_height,
)
wallet::transact::select_spendable_sapling_notes(self, account, target_value, anchor_height)
}
}
@ -327,7 +322,7 @@ impl<P: consensus::Parameters> WalletReadTransparent for WalletDb<P> {
address: &TransparentAddress,
max_height: BlockHeight,
) -> Result<Vec<WalletTransparentOutput>, Self::Error> {
wallet::get_unspent_transparent_outputs(&self, address, max_height)
wallet::get_unspent_transparent_outputs(self, address, max_height)
}
}
@ -519,12 +514,12 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
block.block_height,
block.block_hash,
block.block_time,
&block.commitment_tree,
block.commitment_tree,
)?;
let mut new_witnesses = vec![];
for tx in block.transactions {
let tx_row = wallet::put_tx_meta(up, &tx, block.block_height)?;
let tx_row = wallet::put_tx_meta(up, tx, block.block_height)?;
// Mark notes as spent and remove them from the scanning cache
for spend in &tx.shielded_spends {
@ -624,7 +619,7 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
fn store_sent_tx(&mut self, sent_tx: &SentTransaction) -> Result<Self::TxRef, Self::Error> {
// Update the database atomically, to ensure the result is internally consistent.
self.transactionally(|up| {
let tx_ref = wallet::put_tx_data(up, &sent_tx.tx, Some(sent_tx.created))?;
let tx_ref = wallet::put_tx_data(up, sent_tx.tx, Some(sent_tx.created))?;
// Mark notes as spent.
//
@ -642,7 +637,7 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
#[cfg(feature = "transparent-inputs")]
for utxo_outpoint in &sent_tx.utxos_spent {
wallet::mark_transparent_utxo_spent(up, tx_ref, &utxo_outpoint)?;
wallet::mark_transparent_utxo_spent(up, tx_ref, utxo_outpoint)?;
}
for output in &sent_tx.outputs {
@ -652,7 +647,7 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
tx_ref,
output.output_index,
sent_tx.account,
&addr,
addr,
output.value,
output.memo.as_ref(),
)?,
@ -661,7 +656,7 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
tx_ref,
output.output_index,
sent_tx.account,
&addr,
addr,
output.value,
)?,
}

View File

@ -564,12 +564,12 @@ pub(crate) fn rewind_to_height<P: consensus::Parameters>(
.query_row("SELECT MAX(height) FROM blocks", NO_PARAMS, |row| {
row.get(0)
.map(|h: u32| h.into())
.or(Ok(sapling_activation_height - 1))
.or_else(|_| Ok(sapling_activation_height - 1))
})?;
if block_height < last_scanned_height - PRUNING_HEIGHT {
#[allow(deprecated)]
if let Some(h) = get_rewind_height(&wdb)? {
if let Some(h) = get_rewind_height(wdb)? {
if block_height > h {
return Err(SqliteClientError::RequestedRewindInvalid(h, block_height));
}
@ -920,14 +920,14 @@ pub(crate) fn mark_transparent_utxo_spent<'a, P>(
outpoint: &OutPoint,
) -> Result<(), SqliteClientError> {
let sql_args: &[(&str, &dyn ToSql)] = &[
(&":spent_in_tx", &tx_ref),
(&":prevout_txid", &outpoint.hash().to_vec()),
(&":prevout_idx", &outpoint.n()),
(":spent_in_tx", &tx_ref),
(":prevout_txid", &outpoint.hash().to_vec()),
(":prevout_idx", &outpoint.n()),
];
stmts
.stmt_mark_transparent_utxo_spent
.execute_named(&sql_args)?;
.execute_named(sql_args)?;
Ok(())
}
@ -940,19 +940,19 @@ pub(crate) fn put_received_transparent_utxo<'a, P: consensus::Parameters>(
) -> Result<UtxoId, SqliteClientError> {
let sql_args: &[(&str, &dyn ToSql)] = &[
(
&":address",
":address",
&output.address().encode(&stmts.wallet_db.params),
),
(&":prevout_txid", &output.outpoint.hash().to_vec()),
(&":prevout_idx", &output.outpoint.n()),
(&":script", &output.txout.script_pubkey.0),
(&":value_zat", &i64::from(output.txout.value)),
(&":height", &u32::from(output.height)),
(":prevout_txid", &output.outpoint.hash().to_vec()),
(":prevout_idx", &output.outpoint.n()),
(":script", &output.txout.script_pubkey.0),
(":value_zat", &i64::from(output.txout.value)),
(":height", &u32::from(output.height)),
];
stmts
.stmt_insert_received_transparent_utxo
.execute_named(&sql_args)?;
.execute_named(sql_args)?;
Ok(UtxoId(stmts.wallet_db.conn.last_insert_rowid()))
}
@ -969,11 +969,11 @@ pub fn delete_utxos_above<'a, P: consensus::Parameters>(
height: BlockHeight,
) -> Result<usize, SqliteClientError> {
let sql_args: &[(&str, &dyn ToSql)] = &[
(&":address", &taddr.encode(&stmts.wallet_db.params)),
(&":above_height", &u32::from(height)),
(":address", &taddr.encode(&stmts.wallet_db.params)),
(":above_height", &u32::from(height)),
];
let rows = stmts.stmt_delete_utxos.execute_named(&sql_args)?;
let rows = stmts.stmt_delete_utxos.execute_named(sql_args)?;
Ok(rows)
}
@ -1004,21 +1004,21 @@ pub fn put_received_note<'a, P, T: ShieldedOutput>(
let nf_bytes = output.nullifier().map(|nf| nf.0.to_vec());
let sql_args: &[(&str, &dyn ToSql)] = &[
(&":account", &account),
(&":diversifier", &diversifier),
(&":value", &value),
(&":rcm", &rcm),
(&":nf", &nf_bytes),
(&":memo", &memo),
(&":is_change", &is_change),
(&":tx", &tx),
(&":output_index", &output_index),
(":account", &account),
(":diversifier", &diversifier),
(":value", &value),
(":rcm", &rcm),
(":nf", &nf_bytes),
(":memo", &memo),
(":is_change", &is_change),
(":tx", &tx),
(":output_index", &output_index),
];
// First try updating an existing received note into the database.
if stmts.stmt_update_received_note.execute_named(&sql_args)? == 0 {
if stmts.stmt_update_received_note.execute_named(sql_args)? == 0 {
// It isn't there, so insert our note into the database.
stmts.stmt_insert_received_note.execute_named(&sql_args)?;
stmts.stmt_insert_received_note.execute_named(sql_args)?;
Ok(NoteId::ReceivedNoteId(
stmts.wallet_db.conn.last_insert_rowid(),
@ -1100,7 +1100,7 @@ pub fn put_sent_note<'a, P: consensus::Parameters>(
// Try updating an existing sent note.
if stmts.stmt_update_sent_note.execute(params![
account.0 as i64,
encode_payment_address_p(&stmts.wallet_db.params, &to),
encode_payment_address_p(&stmts.wallet_db.params, to),
ivalue,
&memo.map(|m| m.as_slice()),
tx_ref,
@ -1109,7 +1109,7 @@ pub fn put_sent_note<'a, P: consensus::Parameters>(
])? == 0
{
// It isn't there, so insert.
insert_sent_note(stmts, tx_ref, output_index, account, &to, value, memo)?
insert_sent_note(stmts, tx_ref, output_index, account, to, value, memo)?
}
Ok(())
@ -1135,7 +1135,7 @@ pub fn put_sent_utxo<'a, P: consensus::Parameters>(
// Try updating an existing sent UTXO.
if stmts.stmt_update_sent_note.execute(params![
account.0 as i64,
encode_transparent_address_p(&stmts.wallet_db.params, &to),
encode_transparent_address_p(&stmts.wallet_db.params, to),
ivalue,
(None::<&[u8]>),
tx_ref,
@ -1144,7 +1144,7 @@ pub fn put_sent_utxo<'a, P: consensus::Parameters>(
])? == 0
{
// It isn't there, so insert.
insert_sent_utxo(stmts, tx_ref, output_index, account, &to, value)?
insert_sent_utxo(stmts, tx_ref, output_index, account, to, value)?
}
Ok(())

View File

@ -97,6 +97,8 @@ and this library adheres to Rust's notion of
account values.
- The `zcash_primitives::zip32::AccountId`, a type-safe wrapper for ZIP 32
account indices.
- In `zcash_primitives::transaction::components::amount`:
- `impl Sum<&Amount> for Option<Amount>`
### Changed
- MSRV is now 1.51.0.

View File

@ -29,7 +29,7 @@ impl BlockHash {
pub fn from_slice(bytes: &[u8]) -> Self {
assert_eq!(bytes.len(), 32);
let mut hash = [0; 32];
hash.copy_from_slice(&bytes);
hash.copy_from_slice(bytes);
BlockHash(hash)
}
}

View File

@ -155,7 +155,7 @@ pub trait Extension<C> {
self.verify_inner(
&Self::Precondition::from_payload(precondition.mode, &precondition.payload)?,
&Self::Witness::from_payload(witness.mode, &witness.payload.0)?,
&context,
context,
)
}
}

View File

@ -26,7 +26,7 @@ impl AccountPrivKey {
seed: &[u8],
account: AccountId,
) -> Result<AccountPrivKey, hdwallet::error::Error> {
ExtendedPrivKey::with_seed(&seed)?
ExtendedPrivKey::with_seed(seed)?
.derive_private_key(KeyIndex::hardened_from_normalize_index(44)?)?
.derive_private_key(KeyIndex::hardened_from_normalize_index(params.coin_type())?)?
.derive_private_key(KeyIndex::hardened_from_normalize_index(account.0)?)

View File

@ -61,7 +61,7 @@ pub fn write_nonempty_frontier_v1<H: HashSer, W: Write>(
Optional::write(&mut writer, Some(b), |w, n| n.write(w))?;
}
}
Vector::write(&mut writer, &frontier.ommers(), |w, e| e.write(w))?;
Vector::write(&mut writer, frontier.ommers(), |w, e| e.write(w))?;
Ok(())
}

View File

@ -253,7 +253,7 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
ivk: &Self::IncomingViewingKey,
plaintext: &[u8],
) -> Option<(Self::Note, Self::Recipient)> {
sapling_parse_note_plaintext_without_memo(&self, plaintext, |diversifier| {
sapling_parse_note_plaintext_without_memo(self, plaintext, |diversifier| {
Some(diversifier.g_d()? * ivk.0)
})
}
@ -265,7 +265,7 @@ impl<P: consensus::Parameters> Domain for SaplingDomain<P> {
ephemeral_key: &EphemeralKeyBytes,
plaintext: &NotePlaintextBytes,
) -> Option<(Self::Note, Self::Recipient)> {
sapling_parse_note_plaintext_without_memo(&self, &plaintext.0, |diversifier| {
sapling_parse_note_plaintext_without_memo(self, &plaintext.0, |diversifier| {
if (diversifier.g_d()? * esk).to_bytes() == ephemeral_key.0 {
Some(*pk_d)
} else {
@ -595,7 +595,7 @@ mod tests {
out_ciphertext: &[u8; OUT_CIPHERTEXT_SIZE],
modify_plaintext: impl Fn(&mut [u8; NOTE_PLAINTEXT_SIZE]),
) {
let ock = prf_ock(&ovk, &cv, &cmu.to_repr(), ephemeral_key);
let ock = prf_ock(ovk, cv, &cmu.to_repr(), ephemeral_key);
let mut op = [0; OUT_PLAINTEXT_SIZE];
op.copy_from_slice(&out_ciphertext[..OUT_PLAINTEXT_SIZE]);

View File

@ -87,7 +87,7 @@ where
}
let mut table: &[Vec<jubjub::SubgroupPoint>] =
&generators.next().expect("we don't have enough generators");
generators.next().expect("we don't have enough generators");
let window = PEDERSEN_HASH_EXP_WINDOW_SIZE as usize;
let window_mask = (1u64 << window) - 1;

View File

@ -106,8 +106,8 @@ pub mod mock {
.commitment()
.into();
let rk = PublicKey(proof_generation_key.ak.clone().into())
.randomize(ar, SPENDING_KEY_GENERATOR);
let rk =
PublicKey(proof_generation_key.ak.into()).randomize(ar, SPENDING_KEY_GENERATOR);
Ok(([0u8; GROTH_PROOF_SIZE], cv, rk))
}

View File

@ -55,6 +55,7 @@ impl Signature {
}
impl PrivateKey {
#[must_use]
pub fn randomize(&self, alpha: jubjub::Fr) -> Self {
let mut tmp = self.0;
tmp.add_assign(&alpha);
@ -100,6 +101,7 @@ impl PublicKey {
PublicKey((p_g * privkey.0).into())
}
#[must_use]
pub fn randomize(&self, alpha: jubjub::Fr, p_g: SubgroupPoint) -> Self {
PublicKey(ExtendedPoint::from(p_g * alpha) + self.0)
}

View File

@ -12,10 +12,10 @@ pub(crate) struct TestVector {
pub epk: [u8; 32],
pub shared_secret: [u8; 32],
pub k_enc: [u8; 32],
pub p_enc: [u8; 564],
pub _p_enc: [u8; 564],
pub c_enc: [u8; 580],
pub ock: [u8; 32],
pub op: [u8; 64],
pub _op: [u8; 64],
pub c_out: [u8; 80],
}
@ -116,7 +116,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xb3, 0x3c, 0x3c, 0x32, 0x29, 0xfa, 0x0b, 0x91, 0x26, 0xf9, 0xdd, 0xdb, 0x43, 0x29,
0x66, 0x10, 0x00, 0x69,
],
p_enc: [
_p_enc: [
0x01, 0xf1, 0x9d, 0x9b, 0x79, 0x7e, 0x39, 0xf3, 0x37, 0x44, 0x58, 0x39, 0x00, 0xe1,
0xf5, 0x05, 0x00, 0x00, 0x00, 0x00, 0x39, 0x17, 0x6d, 0xac, 0x39, 0xac, 0xe4, 0x98,
0x0e, 0xcc, 0x8d, 0x77, 0x8e, 0x89, 0x86, 0x02, 0x55, 0xec, 0x36, 0x15, 0x06, 0x00,
@ -208,7 +208,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xca, 0x3a, 0xc6, 0x42, 0x2e, 0xc4, 0xfe, 0x21, 0xe5, 0xd1, 0x53, 0x86, 0x55, 0x8e,
0x4d, 0x37, 0x79, 0x6d,
],
op: [
_op: [
0xdb, 0x4c, 0xd2, 0xb0, 0xaa, 0xc4, 0xf7, 0xeb, 0x8c, 0xa1, 0x31, 0xf1, 0x65, 0x67,
0xc4, 0x45, 0xa9, 0x55, 0x51, 0x26, 0xd3, 0xc2, 0x9f, 0x14, 0xe3, 0xd7, 0x76, 0xe8,
0x41, 0xae, 0x74, 0x15, 0x81, 0xc7, 0xb2, 0x17, 0x1f, 0xf4, 0x41, 0x52, 0x50, 0xca,
@ -318,7 +318,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xa7, 0x02, 0x7a, 0x49, 0x36, 0x2a, 0xa2, 0xdd, 0x3b, 0x54, 0x36, 0xd8, 0x89, 0x75,
0xe0, 0x2a, 0xd0, 0xca,
],
p_enc: [
_p_enc: [
0x01, 0xae, 0xf1, 0x80, 0xf6, 0xe3, 0x4e, 0x35, 0x4b, 0x88, 0x8f, 0x81, 0x00, 0xc2,
0xeb, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x47, 0x8b, 0xa0, 0xee, 0x6e, 0x1a, 0x75, 0xb6,
0x00, 0x03, 0x6f, 0x26, 0xf1, 0x8b, 0x70, 0x15, 0xab, 0x55, 0x6b, 0xed, 0xdf, 0x8b,
@ -410,7 +410,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x4c, 0xa7, 0xe4, 0xa5, 0x82, 0x1d, 0x45, 0x5f, 0x0f, 0xa8, 0x2c, 0xd5, 0x44, 0xec,
0xb4, 0x20, 0x91, 0xfa,
],
op: [
_op: [
0xa6, 0xb1, 0x3e, 0xa3, 0x36, 0xdd, 0xb7, 0xa6, 0x7b, 0xb0, 0x9a, 0x0e, 0x68, 0xe9,
0xd3, 0xcf, 0xb3, 0x92, 0x10, 0x83, 0x1e, 0xa3, 0xa2, 0x96, 0xba, 0x09, 0xa9, 0x22,
0x06, 0x0f, 0xd3, 0x8b, 0xad, 0x4a, 0xd6, 0x24, 0x77, 0xc2, 0xc8, 0x83, 0xc8, 0xba,
@ -520,7 +520,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xa2, 0xd8, 0x06, 0x40, 0x53, 0x0a, 0x4c, 0xa9, 0x7b, 0x82, 0x92, 0xa5, 0xa5, 0x25,
0x0f, 0x1b, 0xf2, 0x40,
],
p_enc: [
_p_enc: [
0x01, 0x75, 0x99, 0xf0, 0xbf, 0x9b, 0x57, 0xcd, 0x2d, 0xc2, 0x99, 0xb6, 0x00, 0xa3,
0xe1, 0x11, 0x00, 0x00, 0x00, 0x00, 0x14, 0x7c, 0xf2, 0xb5, 0x1b, 0x4c, 0x7c, 0x63,
0xcb, 0x77, 0xb9, 0x9e, 0x8b, 0x78, 0x3e, 0x5b, 0x51, 0x11, 0xdb, 0x0a, 0x7c, 0xa0,
@ -612,7 +612,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xcf, 0x0e, 0x49, 0xc3, 0x66, 0xae, 0x72, 0xc9, 0x79, 0xc4, 0x90, 0x49, 0xc9, 0x4b,
0xd3, 0xc7, 0x5c, 0xf4,
],
op: [
_op: [
0x66, 0x14, 0x17, 0x39, 0x51, 0x4b, 0x28, 0xf0, 0x5d, 0xef, 0x8a, 0x18, 0xee, 0xee,
0x5e, 0xed, 0x4d, 0x44, 0xc6, 0x22, 0x5c, 0x3c, 0x65, 0xd8, 0x8d, 0xd9, 0x90, 0x77,
0x08, 0x01, 0x2f, 0x5a, 0x99, 0xaa, 0x10, 0xc0, 0x57, 0x88, 0x08, 0x1c, 0x0d, 0xa7,
@ -722,7 +722,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x33, 0x0c, 0xf9, 0xc8, 0x2b, 0x1e, 0xb1, 0xfe, 0xe6, 0xa1, 0xa5, 0x54, 0x4a, 0x82,
0xc7, 0xb3, 0x16, 0x82,
],
p_enc: [
_p_enc: [
0x01, 0x1b, 0x81, 0x61, 0x4f, 0x1d, 0xad, 0xea, 0x0f, 0x8d, 0x0a, 0x58, 0x00, 0x84,
0xd7, 0x17, 0x00, 0x00, 0x00, 0x00, 0x34, 0xa4, 0xb2, 0xa9, 0x14, 0x4f, 0xf5, 0xea,
0x54, 0xef, 0xee, 0x87, 0xcf, 0x90, 0x1b, 0x5b, 0xed, 0x5e, 0x35, 0xd2, 0x1f, 0xbb,
@ -814,7 +814,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xf1, 0x98, 0x4c, 0x9a, 0x8b, 0x98, 0xe0, 0x6e, 0xe5, 0xd8, 0x36, 0xce, 0x0e, 0x6c,
0x89, 0xab, 0x56, 0xfd,
],
op: [
_op: [
0x25, 0xeb, 0x55, 0xfc, 0xcf, 0x76, 0x1f, 0xc6, 0x4e, 0x85, 0xa5, 0x88, 0xef, 0xe6,
0xea, 0xd7, 0x83, 0x2f, 0xb1, 0xf0, 0xf7, 0xa8, 0x31, 0x65, 0x89, 0x5b, 0xdf, 0xf9,
0x42, 0x92, 0x5f, 0x5c, 0xbd, 0xde, 0x13, 0x81, 0xec, 0x9f, 0xf4, 0x21, 0xca, 0xfd,
@ -924,7 +924,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x7f, 0x26, 0x1f, 0xbb, 0x2d, 0xfa, 0xd8, 0x88, 0x66, 0xb4, 0x32, 0xff, 0x0d, 0xfa,
0xee, 0xc5, 0xb2, 0xcf,
],
p_enc: [
_p_enc: [
0x01, 0xfc, 0xfb, 0x68, 0xa4, 0x0d, 0x4b, 0xc6, 0xa0, 0x4b, 0x09, 0xc4, 0x00, 0x65,
0xcd, 0x1d, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x57, 0x85, 0x13, 0x55, 0x74, 0x7c, 0x09,
0xac, 0x59, 0x01, 0x3c, 0xbd, 0xe8, 0x59, 0x80, 0x96, 0x4e, 0xc1, 0x84, 0x4d, 0x9c,
@ -1016,7 +1016,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x3a, 0x4d, 0xb2, 0x81, 0x86, 0x37, 0x86, 0x88, 0xbe, 0xc6, 0x19, 0x56, 0x23, 0x2e,
0x42, 0xb7, 0x0a, 0xba,
],
op: [
_op: [
0x8b, 0x2a, 0x33, 0x7f, 0x03, 0x62, 0x2c, 0x24, 0xff, 0x38, 0x1d, 0x4c, 0x54, 0x6f,
0x69, 0x77, 0xf9, 0x05, 0x22, 0xe9, 0x2f, 0xde, 0x44, 0xc9, 0xd1, 0xbb, 0x09, 0x97,
0x14, 0xb9, 0xdb, 0x2b, 0x3d, 0xc1, 0x66, 0xd5, 0x6a, 0x1d, 0x62, 0xf5, 0xa8, 0xd7,
@ -1126,7 +1126,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x7c, 0xd0, 0x0c, 0xe0, 0xdc, 0x4b, 0x4d, 0x00, 0xcc, 0x8d, 0x8d, 0x3b, 0xa2, 0xce,
0x6e, 0xa9, 0xc2, 0x97,
],
p_enc: [
_p_enc: [
0x01, 0xeb, 0x51, 0x98, 0x82, 0xad, 0x1e, 0x5c, 0xc6, 0x54, 0xcd, 0x59, 0x00, 0x46,
0xc3, 0x23, 0x00, 0x00, 0x00, 0x00, 0x68, 0xf0, 0x61, 0x04, 0x60, 0x6b, 0x0c, 0x54,
0x49, 0x84, 0x5f, 0xf4, 0xc6, 0x5f, 0x73, 0xe9, 0x0f, 0x45, 0xef, 0x5a, 0x43, 0xc9,
@ -1218,7 +1218,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x5a, 0x11, 0x75, 0x86, 0xae, 0x8a, 0xdd, 0x64, 0x99, 0x7d, 0x02, 0xec, 0xb8, 0xb5,
0xcb, 0xac, 0x14, 0x87,
],
op: [
_op: [
0x6b, 0x27, 0xda, 0xcc, 0xb5, 0xa8, 0x20, 0x7f, 0x53, 0x2d, 0x10, 0xca, 0x23, 0x8f,
0x97, 0x86, 0x64, 0x8a, 0x11, 0xb5, 0x96, 0x6e, 0x51, 0xa2, 0xf7, 0xd8, 0x9e, 0x15,
0xd2, 0x9b, 0x8f, 0xdf, 0x4e, 0x41, 0x8c, 0x3c, 0x54, 0x3d, 0x6b, 0xf0, 0x15, 0x31,
@ -1328,7 +1328,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xba, 0x54, 0x76, 0x19, 0x8e, 0x29, 0x1d, 0xf7, 0x57, 0x8c, 0x2b, 0xef, 0x87, 0xe6,
0x4a, 0x71, 0x6a, 0xe7,
],
p_enc: [
_p_enc: [
0x01, 0xbe, 0xbb, 0x0f, 0xb4, 0x6b, 0x8a, 0xaf, 0xf8, 0x90, 0x40, 0xf6, 0x00, 0x27,
0xb9, 0x29, 0x00, 0x00, 0x00, 0x00, 0x49, 0xf9, 0x0b, 0x47, 0xfd, 0x52, 0xfe, 0xe7,
0xc1, 0xc8, 0x1f, 0x0d, 0xcb, 0x5b, 0x74, 0xc3, 0xfb, 0x9b, 0x3e, 0x03, 0x97, 0x6f,
@ -1420,7 +1420,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x14, 0x92, 0xd1, 0x8d, 0x5c, 0x85, 0x3c, 0x8f, 0x2f, 0x0c, 0xd5, 0xd1, 0x9d, 0x6d,
0x34, 0xcf, 0x7c, 0x2d,
],
op: [
_op: [
0xd1, 0x1d, 0xa0, 0x1f, 0x0b, 0x43, 0xbd, 0xd5, 0x28, 0x8d, 0x32, 0x38, 0x5b, 0x87,
0x71, 0xd2, 0x23, 0x49, 0x3c, 0x69, 0x80, 0x25, 0x44, 0x04, 0x3f, 0x77, 0xcf, 0x1d,
0x71, 0xc1, 0xcb, 0x8c, 0x6d, 0xa9, 0x45, 0xd3, 0x03, 0x81, 0xc2, 0xee, 0xd2, 0xb8,
@ -1530,7 +1530,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x39, 0x97, 0x42, 0xa9, 0x29, 0xbb, 0x23, 0x10, 0x0a, 0x7c, 0x51, 0xed, 0x32, 0xf9,
0xcb, 0x45, 0x96, 0xc6,
],
p_enc: [
_p_enc: [
0x01, 0xad, 0x6e, 0x2e, 0x18, 0x5a, 0x31, 0x00, 0xe3, 0xa6, 0xa8, 0xb3, 0x00, 0x08,
0xaf, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x51, 0x65, 0xaf, 0xf2, 0x2d, 0xd4, 0xed, 0x56,
0xb4, 0xd8, 0x1d, 0x1f, 0x17, 0x1c, 0xc3, 0xd6, 0x43, 0x2f, 0xed, 0x1b, 0xeb, 0xf2,
@ -1622,7 +1622,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x83, 0xa9, 0x27, 0x7c, 0x61, 0x82, 0xa8, 0x08, 0xcc, 0x53, 0xa1, 0xbe, 0xdd, 0xd2,
0x03, 0x68, 0xb1, 0x0a,
],
op: [
_op: [
0x32, 0xcb, 0x28, 0x06, 0xb8, 0x82, 0xf1, 0x36, 0x8b, 0x0d, 0x4a, 0x89, 0x8f, 0x72,
0xc4, 0xc8, 0xf7, 0x28, 0x13, 0x2c, 0xc1, 0x24, 0x56, 0x94, 0x6e, 0x7f, 0x4c, 0xb0,
0xfb, 0x05, 0x8d, 0xa9, 0xab, 0x2a, 0xff, 0x03, 0x32, 0xd5, 0x43, 0xfd, 0x1d, 0x80,
@ -1732,7 +1732,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xa6, 0xb9, 0xca, 0xbe, 0xfd, 0xba, 0x9e, 0x7a, 0x74, 0xf5, 0xba, 0x2f, 0x81, 0xb8,
0x71, 0x40, 0x1f, 0x08,
],
p_enc: [
_p_enc: [
0x01, 0x21, 0xc9, 0x0e, 0x1c, 0x65, 0x8b, 0x3e, 0xfe, 0x86, 0xaf, 0x58, 0x00, 0xe9,
0xa4, 0x35, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x3e, 0x56, 0x44, 0x9d, 0xc8, 0x63, 0x54,
0xd3, 0x3b, 0x02, 0x5e, 0xf2, 0x79, 0x34, 0x60, 0xbc, 0xb1, 0x69, 0xf3, 0x32, 0x4e,
@ -1824,7 +1824,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xa5, 0xf3, 0x58, 0x05, 0xba, 0x78, 0x5a, 0x2c, 0x92, 0xa9, 0xaa, 0x62, 0x32, 0xb0,
0x55, 0x1c, 0xf3, 0xf4,
],
op: [
_op: [
0x9e, 0x64, 0x17, 0x4b, 0x4a, 0xb9, 0x81, 0x40, 0x5c, 0x32, 0x3b, 0x5e, 0x12, 0x47,
0x59, 0x45, 0xa4, 0x6d, 0x4f, 0xed, 0xf8, 0x06, 0x08, 0x28, 0x04, 0x1c, 0xd2, 0x0e,
0x62, 0xfd, 0x2c, 0xef, 0xa5, 0x3d, 0x19, 0xf5, 0x69, 0x45, 0x95, 0xd5, 0xae, 0x63,
@ -1934,7 +1934,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0xc9, 0xc9, 0x60, 0xad, 0x7c, 0xcc, 0x59, 0x77, 0x43, 0x74, 0x4c, 0x18, 0xc9, 0xc2,
0xa5, 0x62, 0xf6, 0x3a,
],
p_enc: [
_p_enc: [
0x01, 0x23, 0x3c, 0x4a, 0xb8, 0x86, 0xa5, 0x5e, 0x3b, 0xa3, 0x74, 0xc0, 0x00, 0xca,
0x9a, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xbb, 0xed, 0x74, 0x36, 0x19, 0xa2, 0x56,
0xf9, 0xad, 0x2e, 0x85, 0x88, 0x0c, 0xfa, 0xa9, 0x09, 0x8a, 0x5f, 0xdb, 0x16, 0x29,
@ -2026,7 +2026,7 @@ pub(crate) fn make_test_vectors() -> Vec<TestVector> {
0x8c, 0xca, 0x55, 0x71, 0xee, 0xcc, 0x69, 0xb7, 0x22, 0xa0, 0xa3, 0xb8, 0x67, 0x50,
0x72, 0x92, 0x99, 0xa0,
],
op: [
_op: [
0xb6, 0x8e, 0x9e, 0xe0, 0xc0, 0x67, 0x8d, 0x7b, 0x30, 0x36, 0x93, 0x1c, 0x83, 0x1a,
0x25, 0x25, 0x5f, 0x7e, 0xe4, 0x87, 0x38, 0x5a, 0x30, 0x31, 0x6e, 0x15, 0xf6, 0x48,
0x2b, 0x87, 0x4f, 0xda, 0x29, 0x95, 0x89, 0x80, 0x69, 0x4f, 0x7f, 0x67, 0x08, 0x09,

View File

@ -1,6 +1,5 @@
//! Structs for building transactions.
use std::array;
use std::error;
use std::fmt;
use std::sync::mpsc::Sender;
@ -267,7 +266,7 @@ impl<'a, P: consensus::Parameters, R: RngCore> Builder<'a, P, R> {
.ok_or(Error::InvalidAmount)?,
];
array::IntoIter::new(value_balances)
IntoIterator::into_iter(&value_balances)
.sum::<Option<_>>()
.ok_or(Error::InvalidAmount)
}

View File

@ -200,6 +200,12 @@ impl Sum<Amount> for Option<Amount> {
}
}
impl<'a> Sum<&'a Amount> for Option<Amount> {
fn sum<I: Iterator<Item = &'a Amount>>(iter: I) -> Self {
iter.fold(Some(Amount::zero()), |acc, a| acc? + *a)
}
}
impl Neg for Amount {
type Output = Self;

View File

@ -236,11 +236,11 @@ pub fn write_action_without_auth<W: Write>(
mut writer: W,
act: &Action<<Authorized as Authorization>::SpendAuth>,
) -> io::Result<()> {
write_value_commitment(&mut writer, &act.cv_net())?;
write_nullifier(&mut writer, &act.nullifier())?;
write_verification_key(&mut writer, &act.rk())?;
write_cmx(&mut writer, &act.cmx())?;
write_note_ciphertext(&mut writer, &act.encrypted_note())?;
write_value_commitment(&mut writer, act.cv_net())?;
write_nullifier(&mut writer, act.nullifier())?;
write_verification_key(&mut writer, act.rk())?;
write_cmx(&mut writer, act.cmx())?;
write_note_ciphertext(&mut writer, act.encrypted_note())?;
Ok(())
}

View File

@ -18,9 +18,9 @@ pub struct Bundle {
}
#[derive(Clone)]
#[allow(clippy::upper_case_acronyms)]
pub(crate) enum SproutProof {
Groth([u8; GROTH_PROOF_SIZE]),
#[allow(clippy::upper_case_acronyms)]
PHGR([u8; PHGR_PROOF_SIZE]),
}

View File

@ -3,7 +3,7 @@
use std::fmt;
use crate::{
legacy::TransparentAddress,
legacy::{Script, TransparentAddress},
transaction::components::{
amount::Amount,
transparent::{self, Authorization, Authorized, Bundle, TxIn, TxOut},
@ -12,14 +12,11 @@ use crate::{
#[cfg(feature = "transparent-inputs")]
use {
crate::{
legacy::Script,
transaction::{
self as tx,
components::OutPoint,
sighash::{signature_hash, SignableInput, SIGHASH_ALL},
TransactionData, TxDigests,
},
crate::transaction::{
self as tx,
components::OutPoint,
sighash::{signature_hash, SignableInput, SIGHASH_ALL},
TransactionData, TxDigests,
},
blake2b_simd::Hash as Blake2bHash,
ripemd::Digest,
@ -196,7 +193,7 @@ impl Bundle<Unauthorized> {
#[cfg(feature = "transparent-inputs")] txid_parts_cache: &TxDigests<Blake2bHash>,
) -> Bundle<Authorized> {
#[cfg(feature = "transparent-inputs")]
let script_sigs: Vec<Script> = self
let script_sigs = self
.authorization
.inputs
.iter()
@ -218,19 +215,18 @@ impl Bundle<Unauthorized> {
// P2PKH scriptSig
Script::default() << &sig_bytes[..] << &info.pubkey[..]
})
.collect();
});
#[cfg(not(feature = "transparent-inputs"))]
let script_sigs = vec![];
let script_sigs = std::iter::empty::<Script>();
transparent::Bundle {
vin: self
.vin
.into_iter()
.zip(script_sigs.into_iter())
.iter()
.zip(script_sigs)
.map(|(txin, sig)| TxIn {
prevout: txin.prevout,
prevout: txin.prevout.clone(),
script_sig: sig,
sequence: txin.sequence,
})

View File

@ -70,7 +70,7 @@ impl<'a, BuildCtx> TzeBuilder<'a, BuildCtx> {
self.vin.push(TzeIn::new(outpoint, extension_id, mode));
self.signers.push(TzeSigner {
prevout,
builder: Box::new(move |ctx| witness_builder(&ctx).map(|x| x.to_payload())),
builder: Box::new(move |ctx| witness_builder(ctx).map(|x| x.to_payload())),
});
}

View File

@ -114,7 +114,7 @@ fn shielded_spends_hash<A: sapling::Authorization<Proof = GrothProofBytes>>(
for s_spend in shielded_spends {
data.extend_from_slice(&s_spend.cv.to_bytes());
data.extend_from_slice(s_spend.anchor.to_repr().as_ref());
data.extend_from_slice(&s_spend.nullifier.as_ref());
data.extend_from_slice(s_spend.nullifier.as_ref());
s_spend.rk.write(&mut data).unwrap();
data.extend_from_slice(&s_spend.zkproof);
}

View File

@ -144,7 +144,7 @@ pub(crate) fn hash_sapling_spends<A: sapling::Authorization>(
let mut nh = hasher(ZCASH_SAPLING_SPENDS_NONCOMPACT_HASH_PERSONALIZATION);
for s_spend in shielded_spends {
// we build the hash of nullifiers separately for compact blocks.
ch.write_all(&s_spend.nullifier.as_ref()).unwrap();
ch.write_all(s_spend.nullifier.as_ref()).unwrap();
nh.write_all(&s_spend.cv.to_bytes()).unwrap();
nh.write_all(&s_spend.anchor.to_repr()).unwrap();
@ -152,9 +152,9 @@ pub(crate) fn hash_sapling_spends<A: sapling::Authorization>(
}
let compact_digest = ch.finalize();
h.write_all(&compact_digest.as_bytes()).unwrap();
h.write_all(compact_digest.as_bytes()).unwrap();
let noncompact_digest = nh.finalize();
h.write_all(&noncompact_digest.as_bytes()).unwrap();
h.write_all(noncompact_digest.as_bytes()).unwrap();
}
h.finalize()
}
@ -172,7 +172,7 @@ pub(crate) fn hash_sapling_outputs<A>(shielded_outputs: &[OutputDescription<A>])
let mut mh = hasher(ZCASH_SAPLING_OUTPUTS_MEMOS_HASH_PERSONALIZATION);
let mut nh = hasher(ZCASH_SAPLING_OUTPUTS_NONCOMPACT_HASH_PERSONALIZATION);
for s_out in shielded_outputs {
ch.write_all(&s_out.cmu.to_repr().as_ref()).unwrap();
ch.write_all(s_out.cmu.to_repr().as_ref()).unwrap();
ch.write_all(s_out.ephemeral_key.as_ref()).unwrap();
ch.write_all(&s_out.enc_ciphertext[..52]).unwrap();
@ -183,9 +183,9 @@ pub(crate) fn hash_sapling_outputs<A>(shielded_outputs: &[OutputDescription<A>])
nh.write_all(&s_out.out_ciphertext).unwrap();
}
h.write_all(&ch.finalize().as_bytes()).unwrap();
h.write_all(&mh.finalize().as_bytes()).unwrap();
h.write_all(&nh.finalize().as_bytes()).unwrap();
h.write_all(ch.finalize().as_bytes()).unwrap();
h.write_all(mh.finalize().as_bytes()).unwrap();
h.write_all(nh.finalize().as_bytes()).unwrap();
}
h.finalize()
}

View File

@ -26,7 +26,7 @@ pub const ZIP32_SAPLING_FVFP_PERSONALIZATION: &[u8; 16] = b"ZcashSaplingFVFP";
pub const ZIP32_SAPLING_INT_PERSONALIZATION: &[u8; 16] = b"Zcash_SaplingInt";
/// A type-safe wrapper for account identifiers.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)]
pub struct AccountId(pub u32);
impl From<u32> for AccountId {
@ -35,12 +35,6 @@ impl From<u32> for AccountId {
}
}
impl Default for AccountId {
fn default() -> Self {
AccountId(0)
}
}
impl ConditionallySelectable for AccountId {
fn conditional_select(a0: &Self, a1: &Self, c: Choice) -> Self {
AccountId(u32::conditional_select(&a0.0, &a1.0, c))
@ -110,7 +104,7 @@ impl ChildIndex {
ChildIndex::from_index(0)
}
fn to_index(&self) -> u32 {
fn value(&self) -> u32 {
match *self {
ChildIndex::Hardened(i) => i + (1 << 31),
ChildIndex::NonHardened(i) => i,
@ -410,7 +404,7 @@ impl ExtendedSpendingKey {
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
writer.write_u8(self.depth)?;
writer.write_all(&self.parent_fvk_tag.0)?;
writer.write_u32::<LittleEndian>(self.child_index.to_index())?;
writer.write_u32::<LittleEndian>(self.child_index.value())?;
writer.write_all(&self.chain_code.0)?;
writer.write_all(&self.expsk.to_bytes())?;
writer.write_all(&self.dk.0)?;
@ -427,6 +421,7 @@ impl ExtendedSpendingKey {
xsk
}
#[must_use]
pub fn derive_child(&self, i: ChildIndex) -> Self {
let fvk = FullViewingKey::from_expanded_spending_key(&self.expsk);
let tmp = match i {
@ -477,6 +472,7 @@ impl ExtendedSpendingKey {
/// Derives an internal spending key given an external spending key.
///
/// Specified in [ZIP 32](https://zips.z.cash/zip-0032#deriving-a-sapling-internal-spending-key).
#[must_use]
pub fn derive_internal(&self) -> Self {
let i = {
let fvk = FullViewingKey::from_expanded_spending_key(&self.expsk);
@ -548,7 +544,7 @@ impl ExtendedFullViewingKey {
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
writer.write_u8(self.depth)?;
writer.write_all(&self.parent_fvk_tag.0)?;
writer.write_u32::<LittleEndian>(self.child_index.to_index())?;
writer.write_u32::<LittleEndian>(self.child_index.value())?;
writer.write_all(&self.chain_code.0)?;
writer.write_all(&self.fvk.to_bytes())?;
writer.write_all(&self.dk.0)?;
@ -619,6 +615,7 @@ impl ExtendedFullViewingKey {
/// only for internal transfers.
///
/// Specified in [ZIP 32](https://zips.z.cash/zip-0032#deriving-a-sapling-internal-full-viewing-key).
#[must_use]
pub fn derive_internal(&self) -> Self {
let (fvk_internal, dk_internal) = sapling_derive_internal_fvk(&self.fvk, &self.dk);

View File

@ -740,11 +740,11 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() {
jubjub::ExtendedPoint::from(value_commitment.commitment()).to_affine();
assert_eq!(
expected_value_commitment.get_u(),
bls12_381::Scalar::from_str_vartime(&expected_commitment_us[i as usize]).unwrap()
bls12_381::Scalar::from_str_vartime(expected_commitment_us[i as usize]).unwrap()
);
assert_eq!(
expected_value_commitment.get_v(),
bls12_381::Scalar::from_str_vartime(&expected_commitment_vs[i as usize]).unwrap()
bls12_381::Scalar::from_str_vartime(expected_commitment_vs[i as usize]).unwrap()
);
let note = Note {
value: value_commitment.value,

View File

@ -86,8 +86,7 @@ impl SaplingProvingContext {
let payment_address = viewing_key.to_payment_address(diversifier).ok_or(())?;
// This is the result of the re-randomization, we compute it for the caller
let rk =
PublicKey(proof_generation_key.ak.clone().into()).randomize(ar, SPENDING_KEY_GENERATOR);
let rk = PublicKey(proof_generation_key.ak.into()).randomize(ar, SPENDING_KEY_GENERATOR);
// Let's compute the nullifier while we have the position
let note = Note {