Make Field::double take &self and return Self

This commit is contained in:
Jack Grigg
2019-12-12 22:59:18 +00:00
parent 91c32f1c7c
commit 9dac748224
23 changed files with 87 additions and 111 deletions

View File

@@ -20,7 +20,7 @@ where
for bit in bits {
num = num.add_bool_with_coeff(CS::one(), bit, coeff);
coeff.double();
coeff = coeff.double();
}
let input = cs.alloc_input(|| format!("input {}", i), || Ok(*num.get_value().get()?))?;
@@ -63,7 +63,7 @@ pub fn compute_multipacking<E: ScalarEngine>(bits: &[bool]) -> Vec<E::Fr> {
cur.add_assign(&coeff);
}
coeff.double();
coeff = coeff.double();
}
result.push(cur);

View File

@@ -177,7 +177,7 @@ impl<E: ScalarEngine> AllocatedNum<E> {
for bit in result.iter().rev() {
lc = lc + (coeff, bit.get_variable());
coeff.double();
coeff = coeff.double();
}
lc = lc - self.variable;
@@ -203,7 +203,7 @@ impl<E: ScalarEngine> AllocatedNum<E> {
for bit in bits.iter() {
lc = lc + (coeff, bit.get_variable());
coeff.double();
coeff = coeff.double();
}
lc = lc - self.variable;

View File

@@ -330,7 +330,7 @@ impl UInt32 {
all_constants &= bit.is_constant();
coeff.double();
coeff = coeff.double();
}
}
@@ -368,7 +368,7 @@ impl UInt32 {
max_value >>= 1;
i += 1;
coeff.double();
coeff = coeff.double();
}
// Enforce equality between the sum and result

View File

@@ -144,8 +144,8 @@ impl Field for Fr {
self.0 = (self.0 * self.0) % MODULUS_R;
}
fn double(&mut self) {
self.0 = (self.0 << 1) % MODULUS_R;
fn double(&self) -> Self {
Fr((self.0 << 1) % MODULUS_R)
}
fn inverse(&self) -> Option<Self> {
@@ -406,7 +406,7 @@ impl CurveProjective for Fr {
}
fn double(&mut self) {
<Fr as Field>::double(self);
self.0 = <Fr as Field>::double(self).0;
}
fn add_assign(&mut self, other: &Self) {