Remove unnecessary clones
This commit is contained in:
parent
bc9ca20d56
commit
0cb51f963c
|
@ -258,7 +258,7 @@ fn generate_pedersen_hash_exp_table() -> Vec<Vec<Vec<SubgroupPoint>>> {
|
|||
let mut base = SubgroupPoint::identity();
|
||||
|
||||
for _ in 0..(1 << window) {
|
||||
table.push(base.clone());
|
||||
table.push(base);
|
||||
base += g;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,8 +110,8 @@ impl Clone for FullViewingKey {
|
|||
fn clone(&self) -> Self {
|
||||
FullViewingKey {
|
||||
vk: ViewingKey {
|
||||
ak: self.vk.ak.clone(),
|
||||
nk: self.vk.nk.clone(),
|
||||
ak: self.vk.ak,
|
||||
nk: self.vk.nk,
|
||||
},
|
||||
ovk: self.ovk,
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ pub struct ProofGenerationKey {
|
|||
impl ProofGenerationKey {
|
||||
pub fn to_viewing_key(&self) -> ViewingKey {
|
||||
ViewingKey {
|
||||
ak: self.ak.clone(),
|
||||
ak: self.ak,
|
||||
nk: constants::PROOF_GENERATION_KEY_GENERATOR * self.nsk,
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ impl PaymentAddress {
|
|||
value,
|
||||
rseed: randomness,
|
||||
g_d,
|
||||
pk_d: self.pk_d.clone(),
|
||||
pk_d: self.pk_d,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ impl SaplingOutput {
|
|||
|
||||
let note = Note {
|
||||
g_d,
|
||||
pk_d: to.pk_d().clone(),
|
||||
pk_d: *to.pk_d(),
|
||||
value: value.into(),
|
||||
rseed,
|
||||
};
|
||||
|
@ -140,7 +140,7 @@ impl SaplingOutput {
|
|||
|
||||
let (zkproof, cv) = prover.output_proof(
|
||||
ctx,
|
||||
encryptor.esk().clone(),
|
||||
*encryptor.esk(),
|
||||
self.to,
|
||||
self.note.rcm(),
|
||||
self.note.value,
|
||||
|
@ -590,7 +590,7 @@ impl<'a, P: consensus::Parameters, R: RngCore + CryptoRng> Builder<'a, P, R> {
|
|||
self.spends[0].extsk.expsk.ovk,
|
||||
PaymentAddress::from_parts(
|
||||
self.spends[0].diversifier,
|
||||
self.spends[0].note.pk_d.clone(),
|
||||
self.spends[0].note.pk_d,
|
||||
)
|
||||
.ok_or(Error::InvalidAddress)?,
|
||||
)
|
||||
|
@ -703,7 +703,7 @@ impl<'a, P: consensus::Parameters, R: RngCore + CryptoRng> Builder<'a, P, R> {
|
|||
let (pk_d, payment_address) = loop {
|
||||
let dummy_ivk = jubjub::Fr::random(&mut self.rng);
|
||||
let pk_d = g_d * dummy_ivk;
|
||||
if let Some(addr) = PaymentAddress::from_parts(diversifier, pk_d.clone()) {
|
||||
if let Some(addr) = PaymentAddress::from_parts(diversifier, pk_d) {
|
||||
break (pk_d, addr);
|
||||
}
|
||||
};
|
||||
|
@ -950,12 +950,7 @@ mod tests {
|
|||
|
||||
// Create a tx with a sapling spend. binding_sig should be present
|
||||
builder
|
||||
.add_sapling_spend(
|
||||
extsk.clone(),
|
||||
*to.diversifier(),
|
||||
note1.clone(),
|
||||
witness1.path().unwrap(),
|
||||
)
|
||||
.add_sapling_spend(extsk, *to.diversifier(), note1, witness1.path().unwrap())
|
||||
.unwrap();
|
||||
|
||||
builder
|
||||
|
@ -1008,12 +1003,7 @@ mod tests {
|
|||
{
|
||||
let mut builder = Builder::new(TEST_NETWORK, H0);
|
||||
builder
|
||||
.add_sapling_output(
|
||||
ovk.clone(),
|
||||
to.clone(),
|
||||
Amount::from_u64(50000).unwrap(),
|
||||
None,
|
||||
)
|
||||
.add_sapling_output(ovk, to.clone(), Amount::from_u64(50000).unwrap(), None)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
builder.build(consensus::BranchId::Sapling, &MockTxProver),
|
||||
|
@ -1058,12 +1048,7 @@ mod tests {
|
|||
)
|
||||
.unwrap();
|
||||
builder
|
||||
.add_sapling_output(
|
||||
ovk.clone(),
|
||||
to.clone(),
|
||||
Amount::from_u64(30000).unwrap(),
|
||||
None,
|
||||
)
|
||||
.add_sapling_output(ovk, to.clone(), Amount::from_u64(30000).unwrap(), None)
|
||||
.unwrap();
|
||||
builder
|
||||
.add_transparent_output(
|
||||
|
|
|
@ -167,52 +167,49 @@ mod tests {
|
|||
#[test]
|
||||
fn amount_in_range() {
|
||||
let zero = b"\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
assert_eq!(Amount::from_u64_le_bytes(zero.clone()).unwrap(), Amount(0));
|
||||
assert_eq!(Amount::from_u64_le_bytes(*zero).unwrap(), Amount(0));
|
||||
assert_eq!(
|
||||
Amount::from_nonnegative_i64_le_bytes(zero.clone()).unwrap(),
|
||||
Amount::from_nonnegative_i64_le_bytes(*zero).unwrap(),
|
||||
Amount(0)
|
||||
);
|
||||
assert_eq!(Amount::from_i64_le_bytes(zero.clone()).unwrap(), Amount(0));
|
||||
assert_eq!(Amount::from_i64_le_bytes(*zero).unwrap(), Amount(0));
|
||||
|
||||
let neg_one = b"\xff\xff\xff\xff\xff\xff\xff\xff";
|
||||
assert!(Amount::from_u64_le_bytes(neg_one.clone()).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(neg_one.clone()).is_err());
|
||||
assert_eq!(
|
||||
Amount::from_i64_le_bytes(neg_one.clone()).unwrap(),
|
||||
Amount(-1)
|
||||
);
|
||||
assert!(Amount::from_u64_le_bytes(*neg_one).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(*neg_one).is_err());
|
||||
assert_eq!(Amount::from_i64_le_bytes(*neg_one).unwrap(), Amount(-1));
|
||||
|
||||
let max_money = b"\x00\x40\x07\x5a\xf0\x75\x07\x00";
|
||||
assert_eq!(
|
||||
Amount::from_u64_le_bytes(max_money.clone()).unwrap(),
|
||||
Amount::from_u64_le_bytes(*max_money).unwrap(),
|
||||
Amount(MAX_MONEY)
|
||||
);
|
||||
assert_eq!(
|
||||
Amount::from_nonnegative_i64_le_bytes(max_money.clone()).unwrap(),
|
||||
Amount::from_nonnegative_i64_le_bytes(*max_money).unwrap(),
|
||||
Amount(MAX_MONEY)
|
||||
);
|
||||
assert_eq!(
|
||||
Amount::from_i64_le_bytes(max_money.clone()).unwrap(),
|
||||
Amount::from_i64_le_bytes(*max_money).unwrap(),
|
||||
Amount(MAX_MONEY)
|
||||
);
|
||||
|
||||
let max_money_p1 = b"\x01\x40\x07\x5a\xf0\x75\x07\x00";
|
||||
assert!(Amount::from_u64_le_bytes(max_money_p1.clone()).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(max_money_p1.clone()).is_err());
|
||||
assert!(Amount::from_i64_le_bytes(max_money_p1.clone()).is_err());
|
||||
assert!(Amount::from_u64_le_bytes(*max_money_p1).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(*max_money_p1).is_err());
|
||||
assert!(Amount::from_i64_le_bytes(*max_money_p1).is_err());
|
||||
|
||||
let neg_max_money = b"\x00\xc0\xf8\xa5\x0f\x8a\xf8\xff";
|
||||
assert!(Amount::from_u64_le_bytes(neg_max_money.clone()).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(neg_max_money.clone()).is_err());
|
||||
assert!(Amount::from_u64_le_bytes(*neg_max_money).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(*neg_max_money).is_err());
|
||||
assert_eq!(
|
||||
Amount::from_i64_le_bytes(neg_max_money.clone()).unwrap(),
|
||||
Amount::from_i64_le_bytes(*neg_max_money).unwrap(),
|
||||
Amount(-MAX_MONEY)
|
||||
);
|
||||
|
||||
let neg_max_money_m1 = b"\xff\xbf\xf8\xa5\x0f\x8a\xf8\xff";
|
||||
assert!(Amount::from_u64_le_bytes(neg_max_money_m1.clone()).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(neg_max_money_m1.clone()).is_err());
|
||||
assert!(Amount::from_i64_le_bytes(neg_max_money_m1.clone()).is_err());
|
||||
assert!(Amount::from_u64_le_bytes(*neg_max_money_m1).is_err());
|
||||
assert!(Amount::from_nonnegative_i64_le_bytes(*neg_max_money_m1).is_err());
|
||||
assert!(Amount::from_i64_le_bytes(*neg_max_money_m1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -52,7 +52,7 @@ impl InputNote {
|
|||
)?;
|
||||
|
||||
// Witness into the merkle tree
|
||||
let mut cur = cm.clone();
|
||||
let mut cur = cm;
|
||||
|
||||
for (i, layer) in auth_path.iter().enumerate() {
|
||||
let cs = &mut cs.namespace(|| format!("layer {}", i));
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn generate_circuit_generator(mut gen: jubjub::SubgroupPoint) -> FixedGenera
|
|||
|
||||
for _ in 0..FIXED_BASE_CHUNKS_PER_GENERATOR {
|
||||
let mut coeffs = vec![(Scalar::zero(), Scalar::one())];
|
||||
let mut g = gen.clone();
|
||||
let mut g = gen;
|
||||
for _ in 0..7 {
|
||||
let g_affine = jubjub::ExtendedPoint::from(g).to_affine();
|
||||
coeffs.push((g_affine.get_u(), g_affine.get_v()));
|
||||
|
@ -143,7 +143,7 @@ fn generate_pedersen_circuit_generators() -> Vec<Vec<Vec<(Scalar, Scalar)>>> {
|
|||
for _ in 0..PEDERSEN_HASH_CHUNKS_PER_GENERATOR {
|
||||
// Create (x, y) coeffs for this chunk
|
||||
let mut coeffs = vec![];
|
||||
let mut g = gen.clone();
|
||||
let mut g = gen;
|
||||
|
||||
// coeffs = g, g*2, g*3, g*4
|
||||
for _ in 0..4 {
|
||||
|
|
|
@ -85,7 +85,7 @@ impl SaplingProvingContext {
|
|||
let note = Note {
|
||||
value,
|
||||
g_d: diversifier.g_d().expect("was a valid diversifier before"),
|
||||
pk_d: payment_address.pk_d().clone(),
|
||||
pk_d: *payment_address.pk_d(),
|
||||
rseed,
|
||||
};
|
||||
|
||||
|
@ -187,7 +187,7 @@ impl SaplingProvingContext {
|
|||
// We now have a full witness for the output proof.
|
||||
let instance = Output {
|
||||
value_commitment: Some(value_commitment.clone()),
|
||||
payment_address: Some(payment_address.clone()),
|
||||
payment_address: Some(payment_address),
|
||||
commitment_randomness: Some(rcm),
|
||||
esk: Some(esk),
|
||||
};
|
||||
|
|
|
@ -137,7 +137,7 @@ impl SaplingVerificationContext {
|
|||
binding_sig: Signature,
|
||||
) -> bool {
|
||||
// Obtain current cv_sum from the context
|
||||
let mut bvk = PublicKey(self.cv_sum.clone());
|
||||
let mut bvk = PublicKey(self.cv_sum);
|
||||
|
||||
// Compute value balance
|
||||
let value_balance = match compute_value_balance(value_balance) {
|
||||
|
|
Loading…
Reference in New Issue