Make Field::square take &self and return Self

This commit is contained in:
Jack Grigg 2019-12-12 23:09:28 +00:00
parent c84d48ec04
commit c716dfdd63
4 changed files with 10 additions and 14 deletions

View File

@ -63,7 +63,7 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
// Compute omega, the 2^exp primitive root of unity
let mut omega = E::Fr::root_of_unity();
for _ in exp..E::Fr::S {
omega.square();
omega = omega.square();
}
// Extend the coeffs vector with zeroes if necessary

View File

@ -254,8 +254,7 @@ impl<E: ScalarEngine> AllocatedNum<E> {
let var = cs.alloc(
|| "squared num",
|| {
let mut tmp = *self.value.get()?;
tmp.square();
let tmp = self.value.get()?.square();
value = Some(tmp);

View File

@ -140,8 +140,8 @@ impl Field for Fr {
(self.0).0 == 0
}
fn square(&mut self) {
self.0 = (self.0 * self.0) % MODULUS_R;
fn square(&self) -> Self {
Fr((self.0 * self.0) % MODULUS_R)
}
fn double(&self) -> Self {
@ -191,22 +191,21 @@ impl SqrtField for Fr {
while t != <Fr as Field>::one() {
let mut i = 1;
{
let mut t2i = t;
t2i.square();
let mut t2i = t.square();
loop {
if t2i == <Fr as Field>::one() {
break;
}
t2i.square();
t2i = t2i.square();
i += 1;
}
}
for _ in 0..(m - i - 1) {
c.square();
c = c.square();
}
MulAssign::mul_assign(&mut r, &c);
c.square();
c = c.square();
MulAssign::mul_assign(&mut t, &c);
m = i;
}

View File

@ -41,8 +41,7 @@ fn mimc<E: Engine>(mut xl: E::Fr, mut xr: E::Fr, constants: &[E::Fr]) -> E::Fr {
for i in 0..MIMC_ROUNDS {
let mut tmp1 = xl;
tmp1.add_assign(&constants[i]);
let mut tmp2 = tmp1;
tmp2.square();
let mut tmp2 = tmp1.square();
tmp2.mul_assign(&tmp1);
tmp2.add_assign(&xr);
xr = xl;
@ -88,8 +87,7 @@ impl<'a, E: Engine> Circuit<E> for MiMCDemo<'a, E> {
// tmp = (xL + Ci)^2
let tmp_value = xl_value.map(|mut e| {
e.add_assign(&self.constants[i]);
e.square();
e
e.square()
});
let tmp = cs.alloc(
|| "tmp",