Address various clippy warnings/errors in zcash_proofs

This commit is contained in:
Jack Grigg 2019-08-02 11:40:10 +01:00
parent 3a8efd9e67
commit 91541675e2
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
8 changed files with 39 additions and 46 deletions

View File

@ -41,16 +41,16 @@ where
{ {
let chunk_a = chunk let chunk_a = chunk
.get(0) .get(0)
.map(|e| e.clone()) .cloned()
.unwrap_or(Boolean::constant(false)); .unwrap_or_else(|| Boolean::constant(false));
let chunk_b = chunk let chunk_b = chunk
.get(1) .get(1)
.map(|e| e.clone()) .cloned()
.unwrap_or(Boolean::constant(false)); .unwrap_or_else(|| Boolean::constant(false));
let chunk_c = chunk let chunk_c = chunk
.get(2) .get(2)
.map(|e| e.clone()) .cloned()
.unwrap_or(Boolean::constant(false)); .unwrap_or_else(|| Boolean::constant(false));
let (x, y) = lookup3_xy( let (x, y) = lookup3_xy(
cs.namespace(|| format!("window table lookup {}", i)), cs.namespace(|| format!("window table lookup {}", i)),
@ -58,7 +58,7 @@ where
window, window,
)?; )?;
let p = EdwardsPoint { x: x, y: y }; let p = EdwardsPoint { x, y };
if result.is_none() { if result.is_none() {
result = Some(p); result = Some(p);
@ -570,7 +570,7 @@ impl<E: JubjubEngine> MontgomeryPoint<E> {
/// on the curve. Useful for constants and /// on the curve. Useful for constants and
/// window table lookups. /// window table lookups.
pub fn interpret_unchecked(x: Num<E>, y: Num<E>) -> Self { pub fn interpret_unchecked(x: Num<E>, y: Num<E>) -> Self {
MontgomeryPoint { x: x, y: y } MontgomeryPoint { x, y }
} }
/// Performs an affine point addition, not defined for /// Performs an affine point addition, not defined for

View File

@ -9,7 +9,7 @@ fn get_constant_bools(person: &Personalization) -> Vec<Boolean> {
person person
.get_bits() .get_bits()
.into_iter() .into_iter()
.map(|e| Boolean::constant(e)) .map(Boolean::constant)
.collect() .collect()
} }
@ -65,7 +65,7 @@ where
segment_windows = &segment_windows[1..]; segment_windows = &segment_windows[1..];
if segment_windows.len() == 0 { if segment_windows.is_empty() {
break; break;
} }

View File

@ -150,7 +150,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for Spend<'a, E> {
// Witness nsk as bits // Witness nsk as bits
let nsk = boolean::field_into_boolean_vec_le( let nsk = boolean::field_into_boolean_vec_le(
cs.namespace(|| "nsk"), cs.namespace(|| "nsk"),
self.proof_generation_key.as_ref().map(|k| k.nsk.clone()), self.proof_generation_key.as_ref().map(|k| k.nsk),
)?; )?;
// NB: We don't ensure that the bit representation of nsk // NB: We don't ensure that the bit representation of nsk
@ -642,7 +642,7 @@ fn test_input_circuit_with_bls12_381() {
let mut cs = TestConstraintSystem::<Bls12>::new(); let mut cs = TestConstraintSystem::<Bls12>::new();
let instance = Spend { let instance = Spend {
params: params, params,
value_commitment: Some(value_commitment.clone()), value_commitment: Some(value_commitment.clone()),
proof_generation_key: Some(proof_generation_key.clone()), proof_generation_key: Some(proof_generation_key.clone()),
payment_address: Some(payment_address.clone()), payment_address: Some(payment_address.clone()),
@ -738,7 +738,7 @@ fn test_output_circuit_with_bls12_381() {
let mut cs = TestConstraintSystem::<Bls12>::new(); let mut cs = TestConstraintSystem::<Bls12>::new();
let instance = Output { let instance = Output {
params: params, params,
value_commitment: Some(value_commitment.clone()), value_commitment: Some(value_commitment.clone()),
payment_address: Some(payment_address.clone()), payment_address: Some(payment_address.clone()),
commitment_randomness: Some(commitment_randomness), commitment_randomness: Some(commitment_randomness),

View File

@ -54,7 +54,7 @@ impl InputNote {
// Witness into the merkle tree // Witness into the merkle tree
let mut cur = cm.clone(); let mut cur = cm.clone();
for (i, layer) in auth_path.into_iter().enumerate() { for (i, layer) in auth_path.iter().enumerate() {
let cs = &mut cs.namespace(|| format!("layer {}", i)); let cs = &mut cs.namespace(|| format!("layer {}", i));
let cur_is_right = AllocatedBit::alloc( let cur_is_right = AllocatedBit::alloc(
@ -112,7 +112,7 @@ impl InputNote {
); );
} }
Ok(InputNote { mac: mac, nf: nf }) Ok(InputNote { mac, nf })
} }
} }

View File

@ -234,10 +234,7 @@ impl NoteValue {
)?); )?);
} }
Ok(NoteValue { Ok(NoteValue { value, bits })
value: value,
bits: bits,
})
} }
/// Encodes the bits of the value into little-endian /// Encodes the bits of the value into little-endian
@ -247,7 +244,7 @@ impl NoteValue {
.chunks(8) .chunks(8)
.flat_map(|v| v.iter().rev()) .flat_map(|v| v.iter().rev())
.cloned() .cloned()
.map(|e| Boolean::from(e)) .map(Boolean::from)
.collect() .collect()
} }
@ -379,11 +376,11 @@ fn test_sprout_constraints() {
let a_sk = Some(SpendingKey(get_u256(&mut test_vector))); let a_sk = Some(SpendingKey(get_u256(&mut test_vector)));
inputs.push(JSInput { inputs.push(JSInput {
value: value, value,
a_sk: a_sk, a_sk,
rho: rho, rho,
r: r, r,
auth_path: auth_path, auth_path,
}); });
} }
@ -395,11 +392,7 @@ fn test_sprout_constraints() {
get_u256(&mut test_vector); get_u256(&mut test_vector);
let r = Some(CommitmentRandomness(get_u256(&mut test_vector))); let r = Some(CommitmentRandomness(get_u256(&mut test_vector)));
outputs.push(JSOutput { outputs.push(JSOutput { value, a_pk, r });
value: value,
a_pk: a_pk,
r: r,
});
} }
let vpub_old = Some(test_vector.read_u64::<LittleEndian>().unwrap()); let vpub_old = Some(test_vector.read_u64::<LittleEndian>().unwrap());
@ -415,13 +408,13 @@ fn test_sprout_constraints() {
let mac2 = get_u256(&mut test_vector); let mac2 = get_u256(&mut test_vector);
let js = JoinSplit { let js = JoinSplit {
vpub_old: vpub_old, vpub_old,
vpub_new: vpub_new, vpub_new,
h_sig: h_sig, h_sig,
phi: phi, phi,
inputs: inputs, inputs,
outputs: outputs, outputs,
rt: rt, rt,
}; };
js.synthesize(&mut cs).unwrap(); js.synthesize(&mut cs).unwrap();

View File

@ -11,7 +11,7 @@ pub struct OutputNote {
} }
impl OutputNote { impl OutputNote {
pub fn compute<'a, E, CS>( pub fn compute<E, CS>(
mut cs: CS, mut cs: CS,
a_pk: Option<PayingKey>, a_pk: Option<PayingKey>,
value: &NoteValue, value: &NoteValue,
@ -41,6 +41,6 @@ impl OutputNote {
&r, &r,
)?; )?;
Ok(OutputNote { cm: cm }) Ok(OutputNote { cm })
} }
} }

View File

@ -11,7 +11,7 @@ impl<R: Read> HashReader<R> {
/// Construct a new `HashReader` given an existing `reader` by value. /// Construct a new `HashReader` given an existing `reader` by value.
pub fn new(reader: R) -> Self { pub fn new(reader: R) -> Self {
HashReader { HashReader {
reader: reader, reader,
hasher: State::new(), hasher: State::new(),
} }
} }

View File

@ -65,7 +65,7 @@ impl SaplingProvingContext {
// Accumulate the value commitment randomness in the context // Accumulate the value commitment randomness in the context
{ {
let mut tmp = rcv.clone(); let mut tmp = rcv;
tmp.add_assign(&self.bsk); tmp.add_assign(&self.bsk);
// Update the context // Update the context
@ -74,7 +74,7 @@ impl SaplingProvingContext {
// Construct the value commitment // Construct the value commitment
let value_commitment = ValueCommitment::<Bls12> { let value_commitment = ValueCommitment::<Bls12> {
value: value, value,
randomness: rcv, randomness: rcv,
}; };
@ -96,7 +96,7 @@ impl SaplingProvingContext {
// Let's compute the nullifier while we have the position // Let's compute the nullifier while we have the position
let note = Note { let note = Note {
value: value, value,
g_d: diversifier g_d: diversifier
.g_d::<Bls12>(params) .g_d::<Bls12>(params)
.expect("was a valid diversifier before"), .expect("was a valid diversifier before"),
@ -200,7 +200,7 @@ impl SaplingProvingContext {
// Accumulate the value commitment randomness in the context // Accumulate the value commitment randomness in the context
{ {
let mut tmp = rcv.clone(); let mut tmp = rcv;
tmp.negate(); // Outputs subtract from the total. tmp.negate(); // Outputs subtract from the total.
tmp.add_assign(&self.bsk); tmp.add_assign(&self.bsk);
@ -210,7 +210,7 @@ impl SaplingProvingContext {
// Construct the value commitment for the proof instance // Construct the value commitment for the proof instance
let value_commitment = ValueCommitment::<Bls12> { let value_commitment = ValueCommitment::<Bls12> {
value: value, value,
randomness: rcv, randomness: rcv,
}; };
@ -220,7 +220,7 @@ impl SaplingProvingContext {
value_commitment: Some(value_commitment.clone()), value_commitment: Some(value_commitment.clone()),
payment_address: Some(payment_address.clone()), payment_address: Some(payment_address.clone()),
commitment_randomness: Some(rcm), commitment_randomness: Some(rcm),
esk: Some(esk.clone()), esk: Some(esk),
}; };
// Create proof // Create proof