Skip to content

Commit b787440

Browse files
weikengchensunhuachuangPratyush
authored
Upgrade to work with latest ark-ff (#90)
Co-authored-by: Sun <[email protected]> Co-authored-by: Pratyush Mishra <[email protected]>
1 parent 50ab8ee commit b787440

File tree

36 files changed

+426
-388
lines changed

36 files changed

+426
-388
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,20 @@ jobs:
176176

177177
- name: Patch cargo.toml
178178
run: |
179-
if ! grep -q "\[patch.crates-io\]" Cargo.toml ; then
180-
echo "[patch.crates-io]" >> Cargo.toml
179+
if grep -q "\[patch.crates-io\]" Cargo.toml ; then
180+
MATCH=$(awk '/\[patch.crates-io\]/{ print NR; exit }' Cargo.toml);
181+
sed -i "$MATCH,\$d" Cargo.toml
181182
fi
182-
echo "ark-r1cs-std = { path = 'r1cs-std' }" >> Cargo.toml
183-
183+
{
184+
echo "[patch.crates-io]"
185+
echo "ark-std = { git = 'https://github.com/arkworks-rs/std' }"
186+
echo "ark-ec = { git = 'https://github.com/arkworks-rs/algebra' }"
187+
echo "ark-ff = { git = 'https://github.com/arkworks-rs/algebra' }"
188+
echo "ark-poly = { git = 'https://github.com/arkworks-rs/algebra' }"
189+
echo "ark-serialize = { git = 'https://github.com/arkworks-rs/algebra' }"
190+
echo "ark-algebra-test-templates = { git = 'https://github.com/arkworks-rs/algebra' }"
191+
echo "ark-r1cs-std = { path = 'r1cs-std' }"
192+
} >> Cargo.toml
193+
184194
- name: Test on ${{ matrix.curve }}
185195
run: "cd ${{ matrix.curve }} && cargo test --features 'r1cs'"

Cargo.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,20 @@ parallel = [ "std", "ark-ff/parallel", "ark-std/parallel"]
5050
[[bench]]
5151
name = "nonnative-bench"
5252
path = "benches/bench.rs"
53-
harness = false
53+
harness = false
54+
55+
# To be removed in the new release.
56+
[patch.crates-io]
57+
ark-std = { git = "https://github.com/arkworks-rs/std" }
58+
ark-ec = { git = "https://github.com/arkworks-rs/algebra" }
59+
ark-ff = { git = "https://github.com/arkworks-rs/algebra" }
60+
ark-poly = { git = "https://github.com/arkworks-rs/algebra" }
61+
ark-serialize = { git = "https://github.com/arkworks-rs/algebra" }
62+
ark-test-curves = { git = "https://github.com/arkworks-rs/algebra" }
63+
ark-bls12-381 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" }
64+
ark-bls12-377 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" }
65+
ark-mnt4-298 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" }
66+
ark-mnt4-753 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" }
67+
ark-mnt6-298 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" }
68+
ark-mnt6-753 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" }
69+
ark-pallas = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" }

benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn get_density<BaseField: PrimeField>(cs: &ConstraintSystemRef<BaseField>) -> us
1919
let matrices = cs_bak.to_matrices().unwrap();
2020

2121
matrices.a_num_non_zero + matrices.b_num_non_zero + matrices.c_num_non_zero
22-
}
22+
},
2323
}
2424
}
2525

src/bits/boolean.rs

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.

src/bits/uint.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ macro_rules! make_uint {
66
#[doc = $native_doc_name]
77
#[doc = " type."]
88
pub mod $mod_name {
9-
use ark_ff::{Field, FpParameters, One, PrimeField, Zero};
9+
use ark_ff::{Field, One, PrimeField, Zero};
1010
use core::borrow::Borrow;
1111
use core::convert::TryFrom;
1212
use num_bigint::BigUint;
@@ -103,17 +103,17 @@ macro_rules! make_uint {
103103
match *b {
104104
Boolean::Constant(b) => {
105105
value.as_mut().map(|v| *v |= $native::from(b));
106-
}
106+
},
107107
Boolean::Is(ref b) => match b.value() {
108108
Ok(b) => {
109109
value.as_mut().map(|v| *v |= $native::from(b));
110-
}
110+
},
111111
Err(_) => value = None,
112112
},
113113
Boolean::Not(ref b) => match b.value() {
114114
Ok(b) => {
115115
value.as_mut().map(|v| *v |= $native::from(!b));
116-
}
116+
},
117117
Err(_) => value = None,
118118
},
119119
}
@@ -171,13 +171,13 @@ macro_rules! make_uint {
171171
{
172172
// Make some arbitrary bounds for ourselves to avoid overflows
173173
// in the scalar field
174-
assert!(F::Params::MODULUS_BITS >= 2 * $size);
174+
assert!(F::MODULUS_BIT_SIZE >= 2 * $size);
175175

176176
// Support up to 128
177177
assert!($size <= 128);
178178

179179
assert!(operands.len() >= 1);
180-
assert!($size * operands.len() <= F::Params::MODULUS_BITS as usize);
180+
assert!($size * operands.len() <= F::MODULUS_BIT_SIZE as usize);
181181

182182
if operands.len() == 1 {
183183
return Ok(operands[0].clone());
@@ -202,13 +202,13 @@ macro_rules! make_uint {
202202
match op.value {
203203
Some(val) => {
204204
result_value.as_mut().map(|v| *v += BigUint::from(val));
205-
}
205+
},
206206

207207
None => {
208208
// If any of our operands have unknown value, we won't
209209
// know the value of the result
210210
result_value = None;
211-
}
211+
},
212212
}
213213

214214
// Iterate over each bit_gadget of the operand and add the operand to
@@ -221,18 +221,18 @@ macro_rules! make_uint {
221221

222222
// Add coeff * bit_gadget
223223
lc += (coeff, bit.variable());
224-
}
224+
},
225225
Boolean::Not(ref bit) => {
226226
all_constants = false;
227227

228228
// Add coeff * (1 - bit_gadget) = coeff * ONE - coeff * bit_gadget
229229
lc = lc + (coeff, Variable::One) - (coeff, bit.variable());
230-
}
230+
},
231231
Boolean::Constant(bit) => {
232232
if bit {
233233
lc += (coeff, Variable::One);
234234
}
235-
}
235+
},
236236
}
237237

238238
coeff.double_in_place();
@@ -407,7 +407,7 @@ macro_rules! make_uint {
407407
match bit {
408408
&Boolean::Constant(bit) => {
409409
assert_eq!(bit, ((b.value()? >> i) & 1 == 1));
410-
}
410+
},
411411
_ => unreachable!(),
412412
}
413413
}
@@ -416,8 +416,8 @@ macro_rules! make_uint {
416416

417417
for x in v.iter().zip(expected_to_be_same.iter()) {
418418
match x {
419-
(&Boolean::Constant(true), &Boolean::Constant(true)) => {}
420-
(&Boolean::Constant(false), &Boolean::Constant(false)) => {}
419+
(&Boolean::Constant(true), &Boolean::Constant(true)) => {},
420+
(&Boolean::Constant(false), &Boolean::Constant(false)) => {},
421421
_ => unreachable!(),
422422
}
423423
}

src/bits/uint8.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ark_ff::{Field, FpParameters, PrimeField, ToConstraintField};
1+
use ark_ff::{Field, PrimeField, ToConstraintField};
22

33
use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError};
44

@@ -152,7 +152,7 @@ impl<F: Field> UInt8<F> {
152152
let values_len = values.len();
153153
let field_elements: Vec<F> = ToConstraintField::<F>::to_field_elements(values).unwrap();
154154

155-
let max_size = 8 * (F::Params::CAPACITY / 8) as usize;
155+
let max_size = 8 * ((F::MODULUS_BIT_SIZE - 1) / 8) as usize;
156156
let mut allocated_bits = Vec::new();
157157
for field_element in field_elements.into_iter() {
158158
let fe = AllocatedFp::new_input(cs.clone(), || Ok(field_element))?;
@@ -335,15 +335,15 @@ impl<ConstraintF: Field> AllocVar<u8, ConstraintF> for UInt8<ConstraintF> {
335335
}
336336
}
337337

338-
/// Parses the `Vec<UInt8<ConstraintF>>` in fixed-sized `ConstraintF::Params::CAPACITY` chunks and
338+
/// Parses the `Vec<UInt8<ConstraintF>>` in fixed-sized `ConstraintF::MODULUS_BIT_SIZE - 1` chunks and
339339
/// converts each chunk, which is assumed to be little-endian, to its `FpVar<ConstraintF>`
340340
/// representation.
341341
/// This is the gadget counterpart to the `[u8]` implementation of
342342
/// [ToConstraintField](ark_ff::ToConstraintField).
343343
impl<ConstraintF: PrimeField> ToConstraintFieldGadget<ConstraintF> for [UInt8<ConstraintF>] {
344344
#[tracing::instrument(target = "r1cs")]
345345
fn to_constraint_field(&self) -> Result<Vec<FpVar<ConstraintF>>, SynthesisError> {
346-
let max_size = (ConstraintF::Params::CAPACITY / 8) as usize;
346+
let max_size = ((ConstraintF::MODULUS_BIT_SIZE - 1) / 8) as usize;
347347
self.chunks(max_size)
348348
.map(|chunk| Boolean::le_bits_to_fp_var(chunk.to_bits_le()?.as_slice()))
349349
.collect::<Result<Vec<_>, SynthesisError>>()
@@ -363,7 +363,7 @@ mod test {
363363
use crate::fields::fp::FpVar;
364364
use crate::prelude::AllocationMode::{Constant, Input, Witness};
365365
use crate::{prelude::*, ToConstraintFieldGadget, Vec};
366-
use ark_ff::{FpParameters, PrimeField, ToConstraintField};
366+
use ark_ff::{PrimeField, ToConstraintField};
367367
use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
368368
use ark_std::rand::distributions::Uniform;
369369
use ark_std::rand::Rng;
@@ -426,8 +426,8 @@ mod test {
426426

427427
for x in v.iter().zip(expected_to_be_same.iter()) {
428428
match x {
429-
(&Boolean::Constant(true), &Boolean::Constant(true)) => {}
430-
(&Boolean::Constant(false), &Boolean::Constant(false)) => {}
429+
(&Boolean::Constant(true), &Boolean::Constant(true)) => {},
430+
(&Boolean::Constant(false), &Boolean::Constant(false)) => {},
431431
_ => unreachable!(),
432432
}
433433
}
@@ -475,7 +475,7 @@ mod test {
475475
#[test]
476476
fn test_uint8_to_constraint_field() -> Result<(), SynthesisError> {
477477
let mut rng = ark_std::test_rng();
478-
let max_size = (<Fr as PrimeField>::Params::CAPACITY / 8) as usize;
478+
let max_size = ((<Fr as PrimeField>::MODULUS_BIT_SIZE - 1) / 8) as usize;
479479

480480
let modes = [Input, Witness, Constant];
481481
for mode in &modes {

0 commit comments

Comments
 (0)