Browse Source

Remove a few unnecessary `.into_iter()` explicit calls, and some cloning.

See https://rust-lang.github.io/rust-clippy/master/#explicit_into_iter_loop
master
François Garillot 5 years ago
committed by Pratyush Mishra
parent
commit
10c6e85c1a
11 changed files with 17 additions and 17 deletions
  1. +3
    -3
      crypto-primitives/src/commitment/blake2s/constraints.rs
  2. +1
    -1
      crypto-primitives/src/commitment/pedersen/constraints.rs
  3. +2
    -2
      crypto-primitives/src/crh/bowe_hopwood/constraints.rs
  4. +1
    -1
      crypto-primitives/src/crh/pedersen/constraints.rs
  5. +1
    -1
      crypto-primitives/src/prf/blake2s/constraints.rs
  6. +1
    -1
      r1cs-std/src/bits/boolean.rs
  7. +1
    -1
      r1cs-std/src/bits/uint32.rs
  8. +3
    -3
      r1cs-std/src/bits/uint8.rs
  9. +1
    -1
      r1cs-std/src/fields/mod.rs
  10. +2
    -2
      r1cs-std/src/groups/curves/twisted_edwards/mod.rs
  11. +1
    -1
      r1cs-std/src/pairing/bls12/mod.rs

+ 3
- 3
crypto-primitives/src/commitment/blake2s/constraints.rs

@ -32,7 +32,7 @@ impl CommitmentGadget
r: &Self::RandomnessGadget, r: &Self::RandomnessGadget,
) -> Result<Self::OutputGadget, SynthesisError> { ) -> Result<Self::OutputGadget, SynthesisError> {
let mut input_bits = Vec::with_capacity(512); let mut input_bits = Vec::with_capacity(512);
for byte in input.into_iter().chain(r.0.iter()) {
for byte in input.iter().chain(r.0.iter()) {
input_bits.extend_from_slice(&byte.into_bits_le()); input_bits.extend_from_slice(&byte.into_bits_le());
} }
let mut result = Vec::new(); let mut result = Vec::new();
@ -141,13 +141,13 @@ mod test {
let primitive_result = Blake2sCommitment::commit(&parameters, &input, &randomness).unwrap(); let primitive_result = Blake2sCommitment::commit(&parameters, &input, &randomness).unwrap();
let mut input_bytes = vec![]; let mut input_bytes = vec![];
for (byte_i, input_byte) in input.into_iter().enumerate() {
for (byte_i, input_byte) in input.iter().enumerate() {
let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i)); let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i));
input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap()); input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap());
} }
let mut randomness_bytes = vec![]; let mut randomness_bytes = vec![];
for (byte_i, random_byte) in randomness.into_iter().enumerate() {
for (byte_i, random_byte) in randomness.iter().enumerate() {
let cs = cs.ns(|| format!("randomness_byte_gadget_{}", byte_i)); let cs = cs.ns(|| format!("randomness_byte_gadget_{}", byte_i));
randomness_bytes.push(UInt8::alloc(cs, || Ok(*random_byte)).unwrap()); randomness_bytes.push(UInt8::alloc(cs, || Ok(*random_byte)).unwrap());
} }

+ 1
- 1
crypto-primitives/src/commitment/pedersen/constraints.rs

@ -218,7 +218,7 @@ mod test {
PedersenCommitment::<JubJub, Window>::commit(&parameters, &input, &randomness).unwrap(); PedersenCommitment::<JubJub, Window>::commit(&parameters, &input, &randomness).unwrap();
let mut input_bytes = vec![]; let mut input_bytes = vec![];
for (byte_i, input_byte) in input.into_iter().enumerate() {
for (byte_i, input_byte) in input.iter().enumerate() {
let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i)); let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i));
input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap()); input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap());
} }

+ 2
- 2
crypto-primitives/src/crh/bowe_hopwood/constraints.rs

@ -72,7 +72,7 @@ where
// Allocate new variable for the result. // Allocate new variable for the result.
let input_in_bits = input_in_bits let input_in_bits = input_in_bits
.chunks(W::WINDOW_SIZE * CHUNK_SIZE) .chunks(W::WINDOW_SIZE * CHUNK_SIZE)
.map(|x| x.chunks(CHUNK_SIZE).into_iter().collect::<Vec<_>>())
.map(|x| x.chunks(CHUNK_SIZE).collect::<Vec<_>>())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let result = GG::precomputed_base_3_bit_signed_digit_scalar_mul( let result = GG::precomputed_base_3_bit_signed_digit_scalar_mul(
cs, cs,
@ -159,7 +159,7 @@ mod test {
rng.fill_bytes(&mut input); rng.fill_bytes(&mut input);
let mut input_bytes = vec![]; let mut input_bytes = vec![];
for (byte_i, input_byte) in input.into_iter().enumerate() {
for (byte_i, input_byte) in input.iter().enumerate() {
let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i)); let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i));
input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap()); input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap());
} }

+ 1
- 1
crypto-primitives/src/crh/pedersen/constraints.rs

@ -147,7 +147,7 @@ mod test {
rng.fill_bytes(&mut input); rng.fill_bytes(&mut input);
let mut input_bytes = vec![]; let mut input_bytes = vec![];
for (byte_i, input_byte) in input.into_iter().enumerate() {
for (byte_i, input_byte) in input.iter().enumerate() {
let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i)); let cs = cs.ns(|| format!("input_byte_gadget_{}", byte_i));
input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap()); input_bytes.push(UInt8::alloc(cs, || Ok(*input_byte)).unwrap());
} }

+ 1
- 1
crypto-primitives/src/prf/blake2s/constraints.rs

@ -482,7 +482,7 @@ impl PRFGadget for Blake2sGadget
assert_eq!(seed.len(), 32); assert_eq!(seed.len(), 32);
// assert_eq!(input.len(), 32); // assert_eq!(input.len(), 32);
let mut gadget_input = Vec::with_capacity(512); let mut gadget_input = Vec::with_capacity(512);
for byte in seed.into_iter().chain(input) {
for byte in seed.iter().chain(input) {
gadget_input.extend_from_slice(&byte.into_bits_le()); gadget_input.extend_from_slice(&byte.into_bits_le());
} }
let mut result = Vec::new(); let mut result = Vec::new();

+ 1
- 1
r1cs-std/src/bits/boolean.rs

@ -371,7 +371,7 @@ impl Boolean {
values: &[u8], values: &[u8],
) -> Vec<Self> { ) -> Vec<Self> {
let mut input_bits = vec![]; let mut input_bits = vec![];
for (byte_i, input_byte) in values.into_iter().enumerate() {
for (byte_i, input_byte) in values.iter().enumerate() {
for bit_i in (0..8).rev() { for bit_i in (0..8).rev() {
let cs = cs.ns(|| format!("input_bit_gadget {} {}", byte_i, bit_i)); let cs = cs.ns(|| format!("input_bit_gadget {} {}", byte_i, bit_i));
input_bits.push( input_bits.push(

+ 1
- 1
r1cs-std/src/bits/uint32.rs

@ -291,7 +291,7 @@ impl ToBytesGadget for UInt32 {
None => [None, None, None, None], None => [None, None, None, None],
}; };
let mut bytes = Vec::new(); let mut bytes = Vec::new();
for (i, chunk8) in self.to_bits_le().chunks(8).into_iter().enumerate() {
for (i, chunk8) in self.to_bits_le().chunks(8).enumerate() {
let byte = UInt8 { let byte = UInt8 {
bits: chunk8.to_vec(), bits: chunk8.to_vec(),
value: value_chunks[i], value: value_chunks[i],

+ 3
- 3
r1cs-std/src/bits/uint8.rs

@ -60,7 +60,7 @@ impl UInt8 {
T: Into<Option<u8>> + Copy, T: Into<Option<u8>> + Copy,
{ {
let mut output_vec = Vec::with_capacity(values.len()); let mut output_vec = Vec::with_capacity(values.len());
for (i, value) in values.into_iter().enumerate() {
for (i, value) in values.iter().enumerate() {
let byte: Option<u8> = Into::into(*value); let byte: Option<u8> = Into::into(*value);
let alloc_byte = Self::alloc(&mut cs.ns(|| format!("byte_{}", i)), || byte.get())?; let alloc_byte = Self::alloc(&mut cs.ns(|| format!("byte_{}", i)), || byte.get())?;
output_vec.push(alloc_byte); output_vec.push(alloc_byte);
@ -115,7 +115,7 @@ impl UInt8 {
/// LSB-first means that we can easily get the corresponding field element /// LSB-first means that we can easily get the corresponding field element
/// via double and add. /// via double and add.
pub fn into_bits_le(&self) -> Vec<Boolean> { pub fn into_bits_le(&self) -> Vec<Boolean> {
self.bits.iter().cloned().collect()
self.bits.to_vec()
} }
/// Converts a little-endian byte order representation of bits into a /// Converts a little-endian byte order representation of bits into a
@ -317,7 +317,7 @@ mod test {
#[test] #[test]
fn test_uint8_alloc_input_vec() { fn test_uint8_alloc_input_vec() {
let mut cs = TestConstraintSystem::<Fr>::new(); let mut cs = TestConstraintSystem::<Fr>::new();
let byte_vals = (64u8..128u8).into_iter().collect::<Vec<_>>();
let byte_vals = (64u8..128u8).collect::<Vec<_>>();
let bytes = UInt8::alloc_input_vec(cs.ns(|| "alloc value"), &byte_vals).unwrap(); let bytes = UInt8::alloc_input_vec(cs.ns(|| "alloc value"), &byte_vals).unwrap();
for (native_byte, gadget_byte) in byte_vals.into_iter().zip(bytes) { for (native_byte, gadget_byte) in byte_vals.into_iter().zip(bytes) {
let bits = gadget_byte.into_bits_le(); let bits = gadget_byte.into_bits_le();

+ 1
- 1
r1cs-std/src/fields/mod.rs

@ -217,7 +217,7 @@ pub trait FieldGadget:
bits: &[Boolean], bits: &[Boolean],
) -> Result<Self, SynthesisError> { ) -> Result<Self, SynthesisError> {
let mut res = Self::one(cs.ns(|| "Alloc result"))?; let mut res = Self::one(cs.ns(|| "Alloc result"))?;
for (i, bit) in bits.into_iter().enumerate() {
for (i, bit) in bits.iter().enumerate() {
res = res.square(cs.ns(|| format!("Double {}", i)))?; res = res.square(cs.ns(|| format!("Double {}", i)))?;
let tmp = res.mul(cs.ns(|| format!("Add {}-th base power", i)), self)?; let tmp = res.mul(cs.ns(|| format!("Add {}-th base power", i)), self)?;
res = Self::conditionally_select( res = Self::conditionally_select(

+ 2
- 2
r1cs-std/src/groups/curves/twisted_edwards/mod.rs

@ -983,11 +983,11 @@ mod projective_impl {
// Compute ∏(h_i^{m_i}) for all i. // Compute ∏(h_i^{m_i}) for all i.
for (segment_i, (segment_bits_chunks, segment_powers)) in for (segment_i, (segment_bits_chunks, segment_powers)) in
scalars.into_iter().zip(bases.iter()).enumerate()
scalars.iter().zip(bases.iter()).enumerate()
{ {
for (i, (bits, base_power)) in segment_bits_chunks for (i, (bits, base_power)) in segment_bits_chunks
.borrow() .borrow()
.into_iter()
.iter()
.zip(segment_powers.borrow().iter()) .zip(segment_powers.borrow().iter())
.enumerate() .enumerate()
{ {

+ 1
- 1
r1cs-std/src/pairing/bls12/mod.rs

@ -102,7 +102,7 @@ where
qs: &[Self::G2PreparedGadget], qs: &[Self::G2PreparedGadget],
) -> Result<Self::GTGadget, SynthesisError> { ) -> Result<Self::GTGadget, SynthesisError> {
let mut pairs = vec![]; let mut pairs = vec![];
for (p, q) in ps.into_iter().zip(qs.into_iter()) {
for (p, q) in ps.iter().zip(qs.iter()) {
pairs.push((p, q.ell_coeffs.iter())); pairs.push((p, q.ell_coeffs.iter()));
} }
let mut f = Self::GTGadget::one(cs.ns(|| "one"))?; let mut f = Self::GTGadget::one(cs.ns(|| "one"))?;

Loading…
Cancel
Save