Skip to content

Commit

Permalink
Use operator syntax
Browse files Browse the repository at this point in the history
eliminate a few redundant references
  • Loading branch information
huitseeker authored and Pratyush committed Dec 2, 2019
1 parent a95bcd0 commit 23ec653
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions algebra/src/curves/mnt6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl MNT6 {
ac.c_rz * &p.y_twist,
-(q.y_over_twist * &ac.c_rz + &(l1_coeff * &ac.c_l1)),
);
f = f * &g_rq_at_p;
f *= &g_rq_at_p;
}
}

Expand Down Expand Up @@ -272,7 +272,7 @@ impl MNT6 {
let mut elt_q3 = elt.clone();
elt_q3.frobenius_map(3);
// elt_q3_over_elt = elt^(q^3-1)
let elt_q3_over_elt = elt_q3 * &elt_inv;
let elt_q3_over_elt = elt_q3 * elt_inv;
// alpha = elt^((q^3-1) * q)
let mut alpha = elt_q3_over_elt.clone();
alpha.frobenius_map(1);
Expand Down
2 changes: 1 addition & 1 deletion algebra/src/fields/bls12_377/fq6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ use rand_xorshift::XorShiftRng;
for _ in 0..1000 {
let mut a = Fq2::rand(&mut rng);
let mut b = a;
a = a * &Fq6Parameters::NONRESIDUE;
a *= &Fq6Parameters::NONRESIDUE;
b *= &nqr;

assert_eq!(a, b);
Expand Down
4 changes: 2 additions & 2 deletions algebra/src/fields/models/fp6_2over3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ impl<P: Fp6Parameters> Fp6<P> {
found_nonzero = true;

if value > 0 {
res = res * self;
res *= self;
} else {
res = res * &self_inverse;
res *= &self_inverse;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crypto-primitives/src/crh/bowe_hopwood/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ impl<G: Group, W: PedersenWindow> FixedLengthCRH for BoweHopwoodPedersenCRH<G, W
.map(|(chunk_bits, generator)| {
let mut encoded = generator.clone();
if chunk_bits[0] {
encoded = encoded + &generator;
encoded = encoded + generator;
}
if chunk_bits[1] {
encoded = encoded + &generator.double();
encoded += &generator.double();
}
if chunk_bits[2] {
encoded = encoded.neg();
Expand Down
2 changes: 1 addition & 1 deletion crypto-primitives/src/crh/pedersen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<G: Group, W: PedersenWindow> FixedLengthCRH for PedersenCRH<G, W> {
let mut encoded = G::zero();
for (bit, base) in bits.iter().zip(generator_powers.iter()) {
if *bit {
encoded = encoded + base;
encoded += base;
}
}
encoded
Expand Down
2 changes: 1 addition & 1 deletion gm17/examples/snark-scalability/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<F: Field> ConstraintSynthesizer<F> for Benchmark<F> {
for (val, var) in assignments {
a_lc = a_lc + var;
b_lc = b_lc + var;
c_val = c_val + &val;
c_val += &val;
}
c_val = c_val.square();

Expand Down
6 changes: 3 additions & 3 deletions gm17/src/r1cs_to_sap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl R1CStoSAP {
Index::Aux(i) => assembly.num_inputs + i,
};

a[index] += &(u_add * &coeff);
a[index] += &(u_add * coeff);
}

for &(ref coeff, index) in assembly.bt[i].iter() {
Expand All @@ -58,7 +58,7 @@ impl R1CStoSAP {
Index::Aux(i) => assembly.num_inputs + i,
};

a[index] += &(u_sub * &coeff);
a[index] += &(u_sub * coeff);
}

for &(ref coeff, index) in assembly.ct[i].iter() {
Expand All @@ -67,7 +67,7 @@ impl R1CStoSAP {
Index::Aux(i) => assembly.num_inputs + i,
};

c[index] += &((u_2i * &coeff).double().double());
c[index] += &((u_2i * coeff).double().double());
}
c[extra_var_offset + i].add_assign(&u_add);
}
Expand Down
8 changes: 4 additions & 4 deletions groth16/src/r1cs_to_qap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ impl R1CStoQAP {
Index::Aux(i) => assembly.num_inputs + i,
};

a[index] += &(u[i] * &coeff);
a[index] += &(u[i] * coeff);
}
for &(ref coeff, index) in assembly.bt[i].iter() {
let index = match index {
Index::Input(i) => i,
Index::Aux(i) => assembly.num_inputs + i,
};

b[index] += &(u[i] * &coeff);
b[index] += &(u[i] * coeff);
}
for &(ref coeff, index) in assembly.ct[i].iter() {
let index = match index {
Index::Input(i) => i,
Index::Aux(i) => assembly.num_inputs + i,
};

c[index] += &(u[i] * &coeff);
c[index] += &(u[i] * coeff);
}
}

Expand Down Expand Up @@ -125,7 +125,7 @@ impl R1CStoQAP {
h.par_iter_mut()
.zip(&a)
.zip(&b)
.for_each(|((h_i, a_i), b_i)| *h_i *= &(*d2 * &a_i + &(*d1 * &b_i)));
.for_each(|((h_i, a_i), b_i)| *h_i *= &(*d2 * a_i + &(*d1 * b_i)));
h[0].sub_assign(&d3);
let d1d2 = *d1 * d2;
h[0].sub_assign(&d1d2);
Expand Down
4 changes: 2 additions & 2 deletions r1cs-std/src/bits/uint32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl UInt32 {
all_constants = false;

// Add coeff * bit_gadget
lc = lc + (coeff, bit.get_variable());
lc += (coeff, bit.get_variable());
},
Boolean::Not(ref bit) => {
all_constants = false;
Expand All @@ -215,7 +215,7 @@ impl UInt32 {
},
Boolean::Constant(bit) => {
if bit {
lc = lc + (coeff, CS::one());
lc += (coeff, CS::one());
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions r1cs-std/src/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl<F: PrimeField> ToBitsGadget<F> for FpGadget<F> {
let mut coeff = F::one();

for bit in bits.iter().rev() {
lc = lc + (coeff, bit.get_variable());
lc += (coeff, bit.get_variable());

coeff.double_in_place();
}
Expand Down Expand Up @@ -412,7 +412,7 @@ impl<F: PrimeField> ToBytesGadget<F> for FpGadget<F> {
{
match bit {
Boolean::Is(bit) => {
lc = lc + (coeff, bit.get_variable());
lc += (coeff, bit.get_variable());
coeff.double_in_place();
},
Boolean::Constant(_) | Boolean::Not(_) => unreachable!(),
Expand Down
2 changes: 1 addition & 1 deletion r1cs-std/src/groups/curves/twisted_edwards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ mod projective_impl {
let mut coords = vec![];
for _ in 0..4 {
coords.push(acc_power);
acc_power = acc_power + base_power;
acc_power += base_power;
}

let bits = bits.borrow().to_bits(
Expand Down

0 comments on commit 23ec653

Please sign in to comment.