Skip to content

Commit

Permalink
Fixed clippy issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Murisi Tarusenga committed Apr 15, 2023
1 parent 700619c commit 6a7c0eb
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 37 deletions.
2 changes: 1 addition & 1 deletion masp_primitives/src/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Consensus logic and parameters.
use borsh::{BorshDeserialize, BorshSerialize};
use memuse::DynamicUsage;
use std::cmp::{Ord, Ordering};
use std::convert::TryFrom;
use std::fmt;
use std::ops::{Add, Bound, RangeBounds, Sub};
use borsh::{BorshSerialize, BorshDeserialize};

/// A wrapper type representing blockchain heights. Safe conversion from
/// various integer types, as well as addition and subtraction, are provided.
Expand Down
4 changes: 2 additions & 2 deletions masp_primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ pub mod sapling;
pub mod transaction;
pub mod zip32;

pub use group;
pub use bls12_381;
pub use ff;
pub use group;
pub use jubjub;
pub use bls12_381;

#[cfg(test)]
mod test_vectors;
4 changes: 3 additions & 1 deletion masp_primitives/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ pub enum Rseed {
}

/// Typesafe wrapper for nullifier values.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, BorshSerialize, BorshDeserialize)]
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, BorshSerialize, BorshDeserialize,
)]
pub struct Nullifier(pub [u8; 32]);

impl Nullifier {
Expand Down
2 changes: 1 addition & 1 deletion masp_primitives/src/sapling/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
constants::{PROOF_GENERATION_KEY_GENERATOR, SPENDING_KEY_GENERATOR},
keys::prf_expand,
};
use borsh::{BorshDeserialize, BorshSerialize};
use ff::PrimeField;
use group::{Group, GroupEncoding};
use std::{
Expand All @@ -17,7 +18,6 @@ use std::{
str::FromStr,
};
use subtle::CtOption;
use borsh::{BorshSerialize, BorshDeserialize};

use super::{NullifierDerivingKey, ProofGenerationKey, ViewingKey};

Expand Down
7 changes: 4 additions & 3 deletions masp_primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,11 @@ impl BorshDeserialize for Transaction {
impl borsh::BorshSchema for Transaction {
fn add_definitions_recursively(
_definitions: &mut std::collections::HashMap<
borsh::schema::Declaration,
borsh::schema::Declaration,
borsh::schema::Definition,
>,
) {}
>,
) {
}

fn declaration() -> borsh::schema::Declaration {
"Transaction".into()
Expand Down
17 changes: 6 additions & 11 deletions masp_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::error;
use std::fmt;
use std::sync::mpsc::Sender;

use borsh::{BorshSerialize, BorshDeserialize};
use borsh::{BorshDeserialize, BorshSerialize};

use rand::{rngs::OsRng, CryptoRng, RngCore};

Expand All @@ -29,7 +29,7 @@ use crate::{
fees::FeeRule,
sighash::{signature_hash, SignableInput},
txid::TxIdDigester,
Transaction, TransactionData, TxVersion, Unauthorized, TransparentAddress,
Transaction, TransactionData, TransparentAddress, TxVersion, Unauthorized,
},
zip32::ExtendedSpendingKey,
};
Expand Down Expand Up @@ -440,8 +440,8 @@ mod testing {
#[cfg(test)]
mod tests {
use ff::Field;
use rand_core::OsRng;
use rand::Rng;
use rand_core::OsRng;

use crate::{
asset_type::AssetType,
Expand Down Expand Up @@ -492,7 +492,7 @@ mod tests {
#[test]
fn binding_sig_present_if_shielded_spend() {
let mut rng = OsRng;

let transparent_address = TransparentAddress(rng.gen::<[u8; 20]>());

let extsk = ExtendedSpendingKey::master(&[]);
Expand Down Expand Up @@ -538,7 +538,7 @@ mod tests {
#[test]
fn fails_on_negative_transparent_output() {
let mut rng = OsRng;

let transparent_address = TransparentAddress(rng.gen::<[u8; 20]>());
let tx_height = TEST_NETWORK
.activation_height(NetworkUpgrade::MASP)
Expand Down Expand Up @@ -622,12 +622,7 @@ mod tests {
{
let mut builder = Builder::new(TEST_NETWORK, tx_height);
builder
.add_sapling_spend(
extsk,
*to.diversifier(),
note1.clone(),
witness1.path().unwrap(),
)
.add_sapling_spend(extsk, *to.diversifier(), note1, witness1.path().unwrap())
.unwrap();
builder
.add_sapling_output(ovk, to, zec(), 30000, MemoBytes::empty())
Expand Down
2 changes: 1 addition & 1 deletion masp_primitives/src/transaction/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod sapling;
pub mod transparent;
pub use self::{
amount::Amount,
sapling::{OutputDescription, SpendDescription, ConvertDescription},
sapling::{ConvertDescription, OutputDescription, SpendDescription},
transparent::{TxIn, TxOut},
};

Expand Down
25 changes: 16 additions & 9 deletions masp_primitives/src/transaction/components/sapling/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use crate::{
},
zip32::ExtendedSpendingKey,
};
use borsh::{BorshDeserialize, BorshSerialize};
use borsh::maybestd::io::Write;
use borsh::{BorshDeserialize, BorshSerialize};

/// If there are any shielded inputs, always have at least two shielded outputs, padding
/// with dummy outputs if necessary. See <https://github.com/zcash/zcash/issues/3615>.
Expand Down Expand Up @@ -93,7 +93,13 @@ impl<Key: BorshDeserialize> BorshDeserialize for SpendDescriptionInfo<Key> {
let alpha: Option<_> = jubjub::Fr::from_bytes(&<[u8; 32]>::deserialize(buf)?).into();
let alpha = alpha.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::InvalidData))?;
let merkle_path = MerklePath::<Node>::deserialize(buf)?;
Ok(SpendDescriptionInfo { extsk, diversifier, note, alpha, merkle_path })
Ok(SpendDescriptionInfo {
extsk,
diversifier,
note,
alpha,
merkle_path,
})
}
}

Expand Down Expand Up @@ -162,8 +168,7 @@ impl SaplingOutputInfo {
ctx: &mut Pr::SaplingProvingContext,
rng: &mut R,
) -> OutputDescription<GrothProofBytes> {
let encryptor =
sapling_note_encryption::<P>(self.ovk, self.note.clone(), self.to, self.memo);
let encryptor = sapling_note_encryption::<P>(self.ovk, self.note, self.to, self.memo);

let (zkproof, cv) = prover.output_proof(
ctx,
Expand Down Expand Up @@ -267,7 +272,9 @@ impl<P: BorshSerialize, Key: BorshSerialize> BorshSerialize for SaplingBuilder<P
self.spend_anchor.map(|x| x.to_bytes()).serialize(writer)?;
self.target_height.serialize(writer)?;
self.value_balance.serialize(writer)?;
self.convert_anchor.map(|x| x.to_bytes()).serialize(writer)?;
self.convert_anchor
.map(|x| x.to_bytes())
.serialize(writer)?;
self.spends.serialize(writer)?;
self.converts.serialize(writer)?;
self.outputs.serialize(writer)
Expand All @@ -277,15 +284,15 @@ impl<P: BorshSerialize, Key: BorshSerialize> BorshSerialize for SaplingBuilder<P
impl<P: BorshDeserialize, Key: BorshDeserialize> BorshDeserialize for SaplingBuilder<P, Key> {
fn deserialize(buf: &mut &[u8]) -> borsh::maybestd::io::Result<Self> {
let params = P::deserialize(buf)?;
let spend_anchor: Option<Option<_>> = Option::<[u8; 32]>::deserialize(buf)?
.map(|x| bls12_381::Scalar::from_bytes(&x).into());
let spend_anchor: Option<Option<_>> =
Option::<[u8; 32]>::deserialize(buf)?.map(|x| bls12_381::Scalar::from_bytes(&x).into());
let spend_anchor = spend_anchor
.map(|x| x.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::InvalidData)))
.transpose()?;
let target_height = BlockHeight::deserialize(buf)?;
let value_balance: Amount = Amount::deserialize(buf)?;
let convert_anchor: Option<Option<_>> = Option::<[u8; 32]>::deserialize(buf)?
.map(|x| bls12_381::Scalar::from_bytes(&x).into());
let convert_anchor: Option<Option<_>> =
Option::<[u8; 32]>::deserialize(buf)?.map(|x| bls12_381::Scalar::from_bytes(&x).into());
let convert_anchor = convert_anchor
.map(|x| x.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::InvalidData)))
.transpose()?;
Expand Down
9 changes: 7 additions & 2 deletions masp_primitives/src/transaction/components/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ impl TxIn<Authorized> {
TransparentAddress(tmp)
};

Ok(TxIn { asset_type, value, address, transparent_sig: () })
Ok(TxIn {
asset_type,
value,
address,
transparent_sig: (),
})
}

pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
Expand Down Expand Up @@ -181,7 +186,7 @@ impl TxOut {
writer.write_all(&self.value.to_le_bytes())?;
writer.write_all(&self.address.0)
}

/// Returns the address to which the TxOut was sent, if this is a valid P2SH or P2PKH output.
pub fn recipient_address(&self) -> TransparentAddress {
self.address
Expand Down
13 changes: 9 additions & 4 deletions masp_primitives/src/transaction/txid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ pub(crate) fn transparent_outputs_hash<T: Borrow<TxOut>>(vout: &[T]) -> Blake2bH
/// to a hash personalized by ZCASH_INPUTS_HASH_PERSONALIZATION.
/// In the case that no inputs are provided, this produces a default
/// hash from just the personalization string.
pub(crate) fn transparent_inputs_hash<TransparentAuth: transparent::Authorization, T: Borrow<TxIn<TransparentAuth>>>(vin: &[T]) -> Blake2bHash {
pub(crate) fn transparent_inputs_hash<
TransparentAuth: transparent::Authorization,
T: Borrow<TxIn<TransparentAuth>>,
>(
vin: &[T],
) -> Blake2bHash {
let mut h = hasher(ZCASH_INPUTS_HASH_PERSONALIZATION);
for t_in in vin {
let t_in = t_in.borrow();
h.write(t_in.asset_type.get_identifier()).unwrap();
h.write(&t_in.value.to_le_bytes()).unwrap();
h.write(&t_in.address.0).unwrap();
h.write_all(t_in.asset_type.get_identifier()).unwrap();
h.write_all(&t_in.value.to_le_bytes()).unwrap();
h.write_all(&t_in.address.0).unwrap();
}
h.finalize()
}
Expand Down
4 changes: 2 additions & 2 deletions masp_proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use std::fs::File;
use std::io::{self, BufReader};
use std::path::Path;

pub use group;
pub use bellman;
pub use jubjub;
pub use bls12_381;
pub use group;
pub use jubjub;

#[cfg(feature = "directories")]
use directories::BaseDirs;
Expand Down

0 comments on commit 6a7c0eb

Please sign in to comment.