Skip to content

Commit 71b6a6e

Browse files
committed
chore: update to ff/group 0.13 and associated dependencies
Updates: - zkcrypto/ff, zkcrypto/group to 0.13, - bellperson to 0.25, - pasta_curves to 0.5.1, and removes the fil_pasta_curves fork - pasta-msm should no longer need a fork (WIP) Adapts source in function, mostly for const usage and API updates.
1 parent b76d7aa commit 71b6a6e

22 files changed

Lines changed: 259 additions & 263 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ license-file = "LICENSE"
1111
keywords = ["zkSNARKs", "cryptography", "proofs"]
1212

1313
[dependencies]
14-
bellperson = { version = "0.24", default-features = false }
15-
ff = { version = "0.12.0", features = ["derive"] }
14+
bellperson = { version = "0.25", default-features = false }
15+
ff = { version = "0.13.0", features = ["derive"] }
1616
digest = "0.8.1"
1717
sha3 = "0.8.2"
1818
rayon = "1.3.0"
1919
rand_core = { version = "0.6.0", default-features = false }
2020
rand_chacha = "0.3"
2121
itertools = "0.9.0"
2222
subtle = "2.4"
23-
pasta_curves = { version = "0.5.2", features = ["repr-c", "serde"], package = "fil_pasta_curves" }
24-
neptune = { version = "8.1.0", default-features = false }
23+
pasta_curves = { version = "0.5", features = ["repr-c", "serde"] }
24+
neptune = { version = "9.0.0", default-features = false }
2525
generic-array = "0.14.4"
2626
num-bigint = { version = "0.4", features = ["serde", "rand"] }
2727
num-traits = "0.2"
@@ -34,7 +34,7 @@ byteorder = "1.4.3"
3434
thiserror = "1.0"
3535

3636
[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dependencies]
37-
pasta-msm = { version = "0.1.0", package = "lurk-pasta-msm" }
37+
pasta-msm = { version = "0.1.0", path="../pasta-msm" }
3838

3939
[dev-dependencies]
4040
criterion = "0.3.1"

examples/signature.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ where
7373
}
7474

7575
fn mul_bits<B: AsRef<[u64]>>(s: &G::Scalar, bits: BitIterator<B>) -> G::Scalar {
76-
let mut x = G::Scalar::zero();
76+
let mut x = G::Scalar::ZERO;
7777
for bit in bits {
7878
x = x.double();
7979

@@ -88,14 +88,14 @@ where
8888
assert_eq!(digest.len(), 64);
8989
let mut bits: [u64; 8] = [0; 8];
9090
LittleEndian::read_u64_into(digest, &mut bits);
91-
Self::mul_bits(&G::Scalar::one(), BitIterator::new(bits))
91+
Self::mul_bits(&G::Scalar::ONE, BitIterator::new(bits))
9292
}
9393

9494
pub fn to_uniform_32(digest: &[u8]) -> G::Scalar {
9595
assert_eq!(digest.len(), 32);
9696
let mut bits: [u64; 4] = [0; 4];
9797
LittleEndian::read_u64_into(digest, &mut bits);
98-
Self::mul_bits(&G::Scalar::one(), BitIterator::new(bits))
98+
Self::mul_bits(&G::Scalar::ONE, BitIterator::new(bits))
9999
}
100100

101101
pub fn hash_to_scalar(persona: &[u8], a: &[u8], b: &[u8]) -> G::Scalar {

src/bellperson/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ mod tests {
2020
cs: &mut CS,
2121
) -> Result<(), SynthesisError> {
2222
// get two bits as input and check that they are indeed bits
23-
let a = AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Fr::one()))?;
23+
let a = AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Fr::ONE))?;
2424
let _ = a.inputize(cs.namespace(|| "a is input"));
2525
cs.enforce(
2626
|| "check a is 0 or 1",
2727
|lc| lc + CS::one() - a.get_variable(),
2828
|lc| lc + a.get_variable(),
2929
|lc| lc,
3030
);
31-
let b = AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Fr::one()))?;
31+
let b = AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Fr::ONE))?;
3232
let _ = b.inputize(cs.namespace(|| "b is input"));
3333
cs.enforce(
3434
|| "check b is 0 or 1",

src/bellperson/r1cs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn add_constraint<S: PrimeField>(
102102
) {
103103
let (A, B, C, nn) = X;
104104
let n = **nn;
105-
let one = S::one();
105+
let one = S::ONE;
106106

107107
let add_constraint_component = |index: Index, coeff, V: &mut Vec<_>| {
108108
match index {

src/bellperson/shape_cs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn proc_lc<Scalar: PrimeField>(
7373
for (var, &coeff) in terms.iter() {
7474
map
7575
.entry(OrderedVariable(var))
76-
.or_insert_with(Scalar::zero)
76+
.or_insert_with(|| Scalar::ZERO)
7777
.add_assign(&coeff);
7878
}
7979

@@ -144,7 +144,7 @@ where
144144
writeln!(s, "INPUT {}", &input).unwrap()
145145
}
146146

147-
let negone = -<G::Scalar>::one();
147+
let negone = -<G::Scalar>::ONE;
148148

149149
let powers_of_two = (0..G::Scalar::NUM_BITS)
150150
.map(|i| G::Scalar::from(2u64).pow_vartime([u64::from(i)]))
@@ -161,7 +161,7 @@ where
161161
}
162162
is_first = false;
163163

164-
if coeff != <G::Scalar>::one() && coeff != negone {
164+
if coeff != <G::Scalar>::ONE && coeff != negone {
165165
for (i, x) in powers_of_two.iter().enumerate() {
166166
if x == &coeff {
167167
write!(s, "2^{i} . ").unwrap();

src/bellperson/solver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ where
9191
type Root = Self;
9292

9393
fn new() -> Self {
94-
let input_assignment = vec![G::Scalar::one()];
94+
let input_assignment = vec![G::Scalar::ONE];
9595
let mut d = DensityTracker::new();
9696
d.add_element();
9797

src/circuit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<G: Group, SC: StepCircuit<G::Base>> NovaAugmentedCircuit<G, SC> {
146146
.collect::<Result<Vec<AllocatedNum<G::Base>>, _>>()?;
147147

148148
// Allocate zi. If inputs.zi is not provided (base case) allocate default value 0
149-
let zero = vec![G::Base::zero(); arity];
149+
let zero = vec![G::Base::ZERO; arity];
150150
let z_i = (0..arity)
151151
.map(|i| {
152152
AllocatedNum::alloc(cs.namespace(|| format!("zi_{i}")), || {
@@ -318,7 +318,7 @@ impl<G: Group, SC: StepCircuit<G::Base>> Circuit<<G as Group>::Base>
318318

319319
// Compute i + 1
320320
let i_new = AllocatedNum::alloc(cs.namespace(|| "i + 1"), || {
321-
Ok(*i.get_value().get()? + G::Base::one())
321+
Ok(*i.get_value().get()? + G::Base::ONE)
322322
})?;
323323
cs.enforce(
324324
|| "check i + 1",
@@ -417,7 +417,7 @@ mod tests {
417417
assert_eq!(cs.num_constraints(), 10347);
418418

419419
// Execute the base case for the primary
420-
let zero1 = <<G2 as Group>::Base as Field>::zero();
420+
let zero1 = <<G2 as Group>::Base as Field>::ZERO;
421421
let mut cs1: SatisfyingAssignment<G1> = SatisfyingAssignment::new();
422422
let inputs1: NovaAugmentedCircuitInputs<G2> = NovaAugmentedCircuitInputs::new(
423423
shape2.get_digest(),
@@ -441,7 +441,7 @@ mod tests {
441441
assert!(shape1.is_sat(&ck1, &inst1, &witness1).is_ok());
442442

443443
// Execute the base case for the secondary
444-
let zero2 = <<G1 as Group>::Base as Field>::zero();
444+
let zero2 = <<G1 as Group>::Base as Field>::ZERO;
445445
let mut cs2: SatisfyingAssignment<G2> = SatisfyingAssignment::new();
446446
let inputs2: NovaAugmentedCircuitInputs<G1> = NovaAugmentedCircuitInputs::new(
447447
shape1.get_digest(),

src/gadgets/ecc.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ where
4343
CS: ConstraintSystem<G::Base>,
4444
{
4545
let x = AllocatedNum::alloc(cs.namespace(|| "x"), || {
46-
Ok(coords.map_or(G::Base::zero(), |c| c.0))
46+
Ok(coords.map_or(G::Base::ZERO, |c| c.0))
4747
})?;
4848
let y = AllocatedNum::alloc(cs.namespace(|| "y"), || {
49-
Ok(coords.map_or(G::Base::zero(), |c| c.1))
49+
Ok(coords.map_or(G::Base::ZERO, |c| c.1))
5050
})?;
5151
let is_infinity = AllocatedNum::alloc(cs.namespace(|| "is_infinity"), || {
5252
Ok(if coords.map_or(true, |c| c.2) {
53-
G::Base::one()
53+
G::Base::ONE
5454
} else {
55-
G::Base::zero()
55+
G::Base::ZERO
5656
})
5757
})?;
5858
cs.enforce(
@@ -177,9 +177,9 @@ where
177177
// NOT(NOT(self.is_ifninity) AND NOT(other.is_infinity))
178178
let at_least_one_inf = AllocatedNum::alloc(cs.namespace(|| "at least one inf"), || {
179179
Ok(
180-
G::Base::one()
181-
- (G::Base::one() - *self.is_infinity.get_value().get()?)
182-
* (G::Base::one() - *other.is_infinity.get_value().get()?),
180+
G::Base::ONE
181+
- (G::Base::ONE - *self.is_infinity.get_value().get()?)
182+
* (G::Base::ONE - *other.is_infinity.get_value().get()?),
183183
)
184184
})?;
185185
cs.enforce(
@@ -193,7 +193,7 @@ where
193193
let x_diff_is_actual =
194194
AllocatedNum::alloc(cs.namespace(|| "allocate x_diff_is_actual"), || {
195195
Ok(if *equal_x.get_value().get()? {
196-
G::Base::one()
196+
G::Base::ONE
197197
} else {
198198
*at_least_one_inf.get_value().get()?
199199
})
@@ -215,9 +215,9 @@ where
215215
)?;
216216

217217
let lambda = AllocatedNum::alloc(cs.namespace(|| "lambda"), || {
218-
let x_diff_inv = if *x_diff_is_actual.get_value().get()? == G::Base::one() {
218+
let x_diff_inv = if *x_diff_is_actual.get_value().get()? == G::Base::ONE {
219219
// Set to default
220-
G::Base::one()
220+
G::Base::ONE
221221
} else {
222222
// Set to the actual inverse
223223
(*other.x.get_value().get()? - *self.x.get_value().get()?)
@@ -328,7 +328,7 @@ where
328328
// * (G::Base::from(2)) * self.y).invert().unwrap();
329329
/*************************************************************/
330330

331-
// Compute tmp = (G::Base::one() + G::Base::one())* self.y ? self != inf : 1
331+
// Compute tmp = (G::Base::ONE + G::Base::ONE)* self.y ? self != inf : 1
332332
let tmp_actual = AllocatedNum::alloc(cs.namespace(|| "tmp_actual"), || {
333333
Ok(*self.y.get_value().get()? + *self.y.get_value().get()?)
334334
})?;
@@ -354,9 +354,9 @@ where
354354
);
355355

356356
let lambda = AllocatedNum::alloc(cs.namespace(|| "alloc lambda"), || {
357-
let tmp_inv = if *self.is_infinity.get_value().get()? == G::Base::one() {
357+
let tmp_inv = if *self.is_infinity.get_value().get()? == G::Base::ONE {
358358
// Return default value 1
359-
G::Base::one()
359+
G::Base::ONE
360360
} else {
361361
// Return the actual inverse
362362
(*tmp.get_value().get()?).invert().unwrap()
@@ -622,7 +622,7 @@ where
622622
// allocate a free variable that an honest prover sets to lambda = (y2-y1)/(x2-x1)
623623
let lambda = AllocatedNum::alloc(cs.namespace(|| "lambda"), || {
624624
if *other.x.get_value().get()? == *self.x.get_value().get()? {
625-
Ok(G::Base::one())
625+
Ok(G::Base::ONE)
626626
} else {
627627
Ok(
628628
(*other.y.get_value().get()? - *self.y.get_value().get()?)
@@ -688,8 +688,8 @@ where
688688
let lambda = AllocatedNum::alloc(cs.namespace(|| "lambda"), || {
689689
let n = G::Base::from(3) * x_sq.get_value().get()? + G::get_curve_params().0;
690690
let d = G::Base::from(2) * *self.y.get_value().get()?;
691-
if d == G::Base::zero() {
692-
Ok(G::Base::one())
691+
if d == G::Base::ZERO {
692+
Ok(G::Base::ONE)
693693
} else {
694694
Ok(n * d.invert().unwrap())
695695
}
@@ -803,8 +803,8 @@ mod tests {
803803
} else {
804804
// if self.x == other.x and self.y != other.y then return infinity
805805
Self {
806-
x: G::Base::zero(),
807-
y: G::Base::zero(),
806+
x: G::Base::ZERO,
807+
y: G::Base::ZERO,
808808
is_infinity: true,
809809
}
810810
}
@@ -836,16 +836,16 @@ mod tests {
836836
pub fn double(&self) -> Self {
837837
if self.is_infinity {
838838
return Self {
839-
x: G::Base::zero(),
840-
y: G::Base::zero(),
839+
x: G::Base::ZERO,
840+
y: G::Base::ZERO,
841841
is_infinity: true,
842842
};
843843
}
844844

845845
let lambda = G::Base::from(3)
846846
* self.x
847847
* self.x
848-
* ((G::Base::one() + G::Base::one()) * self.y)
848+
* ((G::Base::ONE + G::Base::ONE) * self.y)
849849
.invert()
850850
.unwrap();
851851
let x = lambda * lambda - self.x - self.x;
@@ -859,8 +859,8 @@ mod tests {
859859

860860
pub fn scalar_mul(&self, scalar: &G::Scalar) -> Self {
861861
let mut res = Self {
862-
x: G::Base::zero(),
863-
y: G::Base::zero(),
862+
x: G::Base::ZERO,
863+
y: G::Base::ZERO,
864864
is_infinity: true,
865865
};
866866

@@ -985,12 +985,12 @@ mod tests {
985985
let a_p: Point<G1> = Point::new(
986986
a.x.get_value().unwrap(),
987987
a.y.get_value().unwrap(),
988-
a.is_infinity.get_value().unwrap() == <G1 as Group>::Base::one(),
988+
a.is_infinity.get_value().unwrap() == <G1 as Group>::Base::ONE,
989989
);
990990
let e_p: Point<G1> = Point::new(
991991
e.x.get_value().unwrap(),
992992
e.y.get_value().unwrap(),
993-
e.is_infinity.get_value().unwrap() == <G1 as Group>::Base::one(),
993+
e.is_infinity.get_value().unwrap() == <G1 as Group>::Base::ONE,
994994
);
995995
let e_new = a_p.scalar_mul(&s);
996996
assert!(e_p.x == e_new.x && e_p.y == e_new.y);
@@ -1025,12 +1025,12 @@ mod tests {
10251025
let a_p: Point<G1> = Point::new(
10261026
a.x.get_value().unwrap(),
10271027
a.y.get_value().unwrap(),
1028-
a.is_infinity.get_value().unwrap() == <G1 as Group>::Base::one(),
1028+
a.is_infinity.get_value().unwrap() == <G1 as Group>::Base::ONE,
10291029
);
10301030
let e_p: Point<G1> = Point::new(
10311031
e.x.get_value().unwrap(),
10321032
e.y.get_value().unwrap(),
1033-
e.is_infinity.get_value().unwrap() == <G1 as Group>::Base::one(),
1033+
e.is_infinity.get_value().unwrap() == <G1 as Group>::Base::ONE,
10341034
);
10351035
let e_new = a_p.add(&a_p);
10361036
assert!(e_p.x == e_new.x && e_p.y == e_new.y);
@@ -1047,7 +1047,7 @@ mod tests {
10471047
inputize_allocted_point(&a, cs.namespace(|| "inputize a")).unwrap();
10481048
let mut b = a.clone();
10491049
b.y = AllocatedNum::alloc(cs.namespace(|| "allocate negation of a"), || {
1050-
Ok(G::Base::zero())
1050+
Ok(G::Base::ZERO)
10511051
})
10521052
.unwrap();
10531053
inputize_allocted_point(&b, cs.namespace(|| "inputize b")).unwrap();
@@ -1070,7 +1070,7 @@ mod tests {
10701070
let e_p: Point<G1> = Point::new(
10711071
e.x.get_value().unwrap(),
10721072
e.y.get_value().unwrap(),
1073-
e.is_infinity.get_value().unwrap() == <G1 as Group>::Base::one(),
1073+
e.is_infinity.get_value().unwrap() == <G1 as Group>::Base::ONE,
10741074
);
10751075
assert!(e_p.is_infinity);
10761076
// Make sure that it is satisfiable

0 commit comments

Comments
 (0)