diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index add7096..8364904 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,10 +176,20 @@ jobs: - name: Patch cargo.toml run: | - if ! grep -q "\[patch.crates-io\]" Cargo.toml ; then - echo "[patch.crates-io]" >> Cargo.toml + if grep -q "\[patch.crates-io\]" Cargo.toml ; then + MATCH=$(awk '/\[patch.crates-io\]/{ print NR; exit }' Cargo.toml); + sed -i "$MATCH,\$d" Cargo.toml fi - echo "ark-r1cs-std = { path = 'r1cs-std' }" >> Cargo.toml - + { + echo "[patch.crates-io]" + echo "ark-std = { git = 'https://github.com/arkworks-rs/std' }" + echo "ark-ec = { git = 'https://github.com/arkworks-rs/algebra' }" + echo "ark-ff = { git = 'https://github.com/arkworks-rs/algebra' }" + echo "ark-poly = { git = 'https://github.com/arkworks-rs/algebra' }" + echo "ark-serialize = { git = 'https://github.com/arkworks-rs/algebra' }" + echo "ark-algebra-test-templates = { git = 'https://github.com/arkworks-rs/algebra' }" + echo "ark-r1cs-std = { path = 'r1cs-std' }" + } >> Cargo.toml + - name: Test on ${{ matrix.curve }} run: "cd ${{ matrix.curve }} && cargo test --features 'r1cs'" diff --git a/Cargo.toml b/Cargo.toml index d760eeb..cfbdde0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,4 +50,20 @@ parallel = [ "std", "ark-ff/parallel", "ark-std/parallel"] [[bench]] name = "nonnative-bench" path = "benches/bench.rs" -harness = false \ No newline at end of file +harness = false + +# To be removed in the new release. +[patch.crates-io] +ark-std = { git = "https://github.com/arkworks-rs/std" } +ark-ec = { git = "https://github.com/arkworks-rs/algebra" } +ark-ff = { git = "https://github.com/arkworks-rs/algebra" } +ark-poly = { git = "https://github.com/arkworks-rs/algebra" } +ark-serialize = { git = "https://github.com/arkworks-rs/algebra" } +ark-test-curves = { git = "https://github.com/arkworks-rs/algebra" } +ark-bls12-381 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" } +ark-bls12-377 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" } +ark-mnt4-298 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" } +ark-mnt4-753 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" } +ark-mnt6-298 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" } +ark-mnt6-753 = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" } +ark-pallas = { git = "https://github.com/sunhuachuang/curves", branch = "upgrade-ff" } diff --git a/benches/bench.rs b/benches/bench.rs index 8765a01..07fe3c5 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -19,7 +19,7 @@ fn get_density(cs: &ConstraintSystemRef) -> us let matrices = cs_bak.to_matrices().unwrap(); matrices.a_num_non_zero + matrices.b_num_non_zero + matrices.c_num_non_zero - } + }, } } diff --git a/src/bits/boolean.rs b/src/bits/boolean.rs index 3e25b3f..8b7d003 100644 --- a/src/bits/boolean.rs +++ b/src/bits/boolean.rs @@ -1,4 +1,4 @@ -use ark_ff::{BitIteratorBE, Field, FpParameters, PrimeField}; +use ark_ff::{BitIteratorBE, Field, PrimeField}; use crate::{fields::fp::FpVar, prelude::*, Assignment, ToConstraintFieldGadget, Vec}; use ark_relations::r1cs::{ @@ -396,7 +396,7 @@ impl Boolean { // a XOR (NOT b) = NOT(a XOR b) (is @ &Is(_), not @ &Not(_)) | (not @ &Not(_), is @ &Is(_)) => { Ok(is.xor(¬.not())?.not()) - } + }, // a XOR b = (NOT a) XOR (NOT b) (&Is(ref a), &Is(ref b)) | (&Not(ref a), &Not(ref b)) => Ok(Is(a.xor(b)?)), } @@ -438,7 +438,7 @@ impl Boolean { // a OR b = NOT ((NOT a) AND (NOT b)) (a @ &Is(_), b @ &Not(_)) | (b @ &Not(_), a @ &Is(_)) | (b @ &Not(_), a @ &Not(_)) => { Ok(a.not().and(&b.not())?.not()) - } + }, (&Is(ref a), &Is(ref b)) => a.or(b).map(From::from), } } @@ -604,7 +604,7 @@ impl Boolean { Is(_) | Not(_) => { r.cs() .enforce_constraint(r.lc(), lc!() + Variable::One, lc!() + Variable::One) - } + }, } } @@ -651,7 +651,7 @@ impl Boolean { // If the number of bits is less than the size of the field, // then we do not need to enforce that the element is less than // the modulus. - if bits.len() >= F::Params::MODULUS_BITS as usize { + if bits.len() >= F::MODULUS_BIT_SIZE as usize { Self::enforce_in_field_le(bits)?; } Ok(crate::fields::fp::AllocatedFp::new(value, variable, cs.clone()).into()) @@ -946,7 +946,7 @@ impl CondSelectGadget for Boolean { )?; Ok(result) - } + }, }, } } @@ -1247,30 +1247,30 @@ mod test { (OpType::AllocatedTrue, OpType::False, Boolean::Is(_)) => (), (OpType::AllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedTrue, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedTrue, OpType::NegatedAllocatedFalse, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedFalse, OpType::True, Boolean::Not(_)) => (), (OpType::AllocatedFalse, OpType::False, Boolean::Is(_)) => (), (OpType::AllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedFalse, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, ( OpType::AllocatedFalse, OpType::NegatedAllocatedFalse, @@ -1278,18 +1278,18 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedTrue, OpType::True, Boolean::Is(_)) => (), (OpType::NegatedAllocatedTrue, OpType::False, Boolean::Not(_)) => (), (OpType::NegatedAllocatedTrue, OpType::AllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedTrue, OpType::AllocatedFalse, Boolean::Not(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, ( OpType::NegatedAllocatedTrue, OpType::NegatedAllocatedTrue, @@ -1297,7 +1297,7 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedTrue, OpType::NegatedAllocatedFalse, @@ -1305,14 +1305,14 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, (OpType::NegatedAllocatedFalse, OpType::True, Boolean::Is(_)) => (), (OpType::NegatedAllocatedFalse, OpType::False, Boolean::Not(_)) => (), (OpType::NegatedAllocatedFalse, OpType::AllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::AllocatedFalse, @@ -1320,7 +1320,7 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::NegatedAllocatedTrue, @@ -1328,7 +1328,7 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::NegatedAllocatedFalse, @@ -1336,7 +1336,7 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, _ => unreachable!(), } @@ -1409,85 +1409,85 @@ mod test { (OpType::AllocatedTrue, OpType::False, Boolean::Is(_)) => (), (OpType::AllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedTrue, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedTrue, OpType::NegatedAllocatedFalse, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedFalse, OpType::True, Boolean::Constant(true)) => (), (OpType::AllocatedFalse, OpType::False, Boolean::Is(_)) => (), (OpType::AllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedFalse, OpType::NegatedAllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(true)); - } + }, ( OpType::AllocatedFalse, OpType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedTrue, OpType::True, Boolean::Constant(true)) => (), (OpType::NegatedAllocatedTrue, OpType::False, Boolean::Not(_)) => (), (OpType::NegatedAllocatedTrue, OpType::AllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedTrue, OpType::AllocatedFalse, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(true)); - } + }, ( OpType::NegatedAllocatedTrue, OpType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value(), Ok(true)); - } + }, ( OpType::NegatedAllocatedTrue, OpType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedFalse, OpType::True, Boolean::Constant(true)) => (), (OpType::NegatedAllocatedFalse, OpType::False, Boolean::Not(_)) => (), (OpType::NegatedAllocatedFalse, OpType::AllocatedTrue, Boolean::Not(ref v)) => { assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::AllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { assert_eq!(v.value(), Ok(false)); - } + }, _ => panic!( "this should never be encountered, in case: (a = {:?}, b = {:?}, c = {:?})", @@ -1531,49 +1531,49 @@ mod test { (OpType::AllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedTrue, OpType::NegatedAllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedTrue, OpType::NegatedAllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, (OpType::AllocatedFalse, OpType::True, Boolean::Is(_)) => (), (OpType::AllocatedFalse, OpType::False, Boolean::Constant(false)) => (), (OpType::AllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedFalse, OpType::NegatedAllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::AllocatedFalse, OpType::NegatedAllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedTrue, OpType::True, Boolean::Not(_)) => (), (OpType::NegatedAllocatedTrue, OpType::False, Boolean::Constant(false)) => (), (OpType::NegatedAllocatedTrue, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedTrue, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedTrue, OpType::NegatedAllocatedTrue, @@ -1581,7 +1581,7 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedTrue, OpType::NegatedAllocatedFalse, @@ -1589,18 +1589,18 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, (OpType::NegatedAllocatedFalse, OpType::True, Boolean::Not(_)) => (), (OpType::NegatedAllocatedFalse, OpType::False, Boolean::Constant(false)) => (), (OpType::NegatedAllocatedFalse, OpType::AllocatedTrue, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, (OpType::NegatedAllocatedFalse, OpType::AllocatedFalse, Boolean::Is(ref v)) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::NegatedAllocatedTrue, @@ -1608,7 +1608,7 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::zero()); assert_eq!(v.value(), Ok(false)); - } + }, ( OpType::NegatedAllocatedFalse, OpType::NegatedAllocatedFalse, @@ -1616,14 +1616,14 @@ mod test { ) => { assert_eq!(cs.assigned_value(v.variable()).unwrap(), Fr::one()); assert_eq!(v.value(), Ok(true)); - } + }, _ => { panic!( "unexpected behavior at {:?} AND {:?}", first_operand, second_operand ); - } + }, } } } @@ -1642,9 +1642,9 @@ mod test { let cs = ConstraintSystem::::new_ref(); - let native_bits: Vec<_> = BitIteratorLE::new(r.into_repr()).collect(); + let native_bits: Vec<_> = BitIteratorLE::new(r.into_bigint()).collect(); let bits = Vec::new_witness(cs.clone(), || Ok(native_bits))?; - Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_repr())?; + Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_bigint())?; assert!(cs.is_satisfied().unwrap()); } @@ -1658,11 +1658,11 @@ mod test { let s2 = r.double(); let cs = ConstraintSystem::::new_ref(); - let native_bits: Vec<_> = BitIteratorLE::new(r.into_repr()).collect(); + let native_bits: Vec<_> = BitIteratorLE::new(r.into_bigint()).collect(); let bits = Vec::new_witness(cs.clone(), || Ok(native_bits))?; - Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_repr())?; + Boolean::enforce_smaller_or_equal_than_le(&bits, s.into_bigint())?; if r < s2 { - Boolean::enforce_smaller_or_equal_than_le(&bits, s2.into_repr())?; + Boolean::enforce_smaller_or_equal_than_le(&bits, s2.into_bigint())?; } assert!(cs.is_satisfied().unwrap()); @@ -1693,7 +1693,7 @@ mod test { let cs = ConstraintSystem::::new_ref(); let mut bits = vec![]; - for b in BitIteratorBE::new(r.into_repr()).skip(1) { + for b in BitIteratorBE::new(r.into_bigint()).skip(1) { bits.push(Boolean::new_witness(cs.clone(), || Ok(b))?); } bits.reverse(); @@ -1796,7 +1796,7 @@ mod test { for &mode in modes.iter() { for _ in 0..1000 { let f = Fr::rand(rng); - let bits = BitIteratorLE::new(f.into_repr()).collect::>(); + let bits = BitIteratorLE::new(f.into_bigint()).collect::>(); let bits: Vec<_> = AllocVar::new_variable(cs.clone(), || Ok(bits.as_slice()), mode)?; let f = AllocVar::new_variable(cs.clone(), || Ok(f), mode)?; @@ -1806,7 +1806,7 @@ mod test { for _ in 0..1000 { let f = Fr::from(u64::rand(rng)); - let bits = BitIteratorLE::new(f.into_repr()).collect::>(); + let bits = BitIteratorLE::new(f.into_bigint()).collect::>(); let bits: Vec<_> = AllocVar::new_variable(cs.clone(), || Ok(bits.as_slice()), mode)?; let f = AllocVar::new_variable(cs.clone(), || Ok(f), mode)?; diff --git a/src/bits/uint.rs b/src/bits/uint.rs index cc5053e..320dd4d 100644 --- a/src/bits/uint.rs +++ b/src/bits/uint.rs @@ -6,7 +6,7 @@ macro_rules! make_uint { #[doc = $native_doc_name] #[doc = " type."] pub mod $mod_name { - use ark_ff::{Field, FpParameters, One, PrimeField, Zero}; + use ark_ff::{Field, One, PrimeField, Zero}; use core::borrow::Borrow; use core::convert::TryFrom; use num_bigint::BigUint; @@ -103,17 +103,17 @@ macro_rules! make_uint { match *b { Boolean::Constant(b) => { value.as_mut().map(|v| *v |= $native::from(b)); - } + }, Boolean::Is(ref b) => match b.value() { Ok(b) => { value.as_mut().map(|v| *v |= $native::from(b)); - } + }, Err(_) => value = None, }, Boolean::Not(ref b) => match b.value() { Ok(b) => { value.as_mut().map(|v| *v |= $native::from(!b)); - } + }, Err(_) => value = None, }, } @@ -171,13 +171,13 @@ macro_rules! make_uint { { // Make some arbitrary bounds for ourselves to avoid overflows // in the scalar field - assert!(F::Params::MODULUS_BITS >= 2 * $size); + assert!(F::MODULUS_BIT_SIZE >= 2 * $size); // Support up to 128 assert!($size <= 128); assert!(operands.len() >= 1); - assert!($size * operands.len() <= F::Params::MODULUS_BITS as usize); + assert!($size * operands.len() <= F::MODULUS_BIT_SIZE as usize); if operands.len() == 1 { return Ok(operands[0].clone()); @@ -202,13 +202,13 @@ macro_rules! make_uint { match op.value { Some(val) => { result_value.as_mut().map(|v| *v += BigUint::from(val)); - } + }, None => { // If any of our operands have unknown value, we won't // know the value of the result result_value = None; - } + }, } // Iterate over each bit_gadget of the operand and add the operand to @@ -221,18 +221,18 @@ macro_rules! make_uint { // Add coeff * bit_gadget lc += (coeff, bit.variable()); - } + }, Boolean::Not(ref bit) => { all_constants = false; // Add coeff * (1 - bit_gadget) = coeff * ONE - coeff * bit_gadget lc = lc + (coeff, Variable::One) - (coeff, bit.variable()); - } + }, Boolean::Constant(bit) => { if bit { lc += (coeff, Variable::One); } - } + }, } coeff.double_in_place(); @@ -407,7 +407,7 @@ macro_rules! make_uint { match bit { &Boolean::Constant(bit) => { assert_eq!(bit, ((b.value()? >> i) & 1 == 1)); - } + }, _ => unreachable!(), } } @@ -416,8 +416,8 @@ macro_rules! make_uint { for x in v.iter().zip(expected_to_be_same.iter()) { match x { - (&Boolean::Constant(true), &Boolean::Constant(true)) => {} - (&Boolean::Constant(false), &Boolean::Constant(false)) => {} + (&Boolean::Constant(true), &Boolean::Constant(true)) => {}, + (&Boolean::Constant(false), &Boolean::Constant(false)) => {}, _ => unreachable!(), } } diff --git a/src/bits/uint8.rs b/src/bits/uint8.rs index dd479d0..b6a9483 100644 --- a/src/bits/uint8.rs +++ b/src/bits/uint8.rs @@ -1,4 +1,4 @@ -use ark_ff::{Field, FpParameters, PrimeField, ToConstraintField}; +use ark_ff::{Field, PrimeField, ToConstraintField}; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; @@ -152,7 +152,7 @@ impl UInt8 { let values_len = values.len(); let field_elements: Vec = ToConstraintField::::to_field_elements(values).unwrap(); - let max_size = 8 * (F::Params::CAPACITY / 8) as usize; + let max_size = 8 * ((F::MODULUS_BIT_SIZE - 1) / 8) as usize; let mut allocated_bits = Vec::new(); for field_element in field_elements.into_iter() { let fe = AllocatedFp::new_input(cs.clone(), || Ok(field_element))?; @@ -335,7 +335,7 @@ impl AllocVar for UInt8 { } } -/// Parses the `Vec>` in fixed-sized `ConstraintF::Params::CAPACITY` chunks and +/// Parses the `Vec>` in fixed-sized `ConstraintF::MODULUS_BIT_SIZE - 1` chunks and /// converts each chunk, which is assumed to be little-endian, to its `FpVar` /// representation. /// This is the gadget counterpart to the `[u8]` implementation of @@ -343,7 +343,7 @@ impl AllocVar for UInt8 { impl ToConstraintFieldGadget for [UInt8] { #[tracing::instrument(target = "r1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { - let max_size = (ConstraintF::Params::CAPACITY / 8) as usize; + let max_size = ((ConstraintF::MODULUS_BIT_SIZE - 1) / 8) as usize; self.chunks(max_size) .map(|chunk| Boolean::le_bits_to_fp_var(chunk.to_bits_le()?.as_slice())) .collect::, SynthesisError>>() @@ -363,7 +363,7 @@ mod test { use crate::fields::fp::FpVar; use crate::prelude::AllocationMode::{Constant, Input, Witness}; use crate::{prelude::*, ToConstraintFieldGadget, Vec}; - use ark_ff::{FpParameters, PrimeField, ToConstraintField}; + use ark_ff::{PrimeField, ToConstraintField}; use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_std::rand::distributions::Uniform; use ark_std::rand::Rng; @@ -426,8 +426,8 @@ mod test { for x in v.iter().zip(expected_to_be_same.iter()) { match x { - (&Boolean::Constant(true), &Boolean::Constant(true)) => {} - (&Boolean::Constant(false), &Boolean::Constant(false)) => {} + (&Boolean::Constant(true), &Boolean::Constant(true)) => {}, + (&Boolean::Constant(false), &Boolean::Constant(false)) => {}, _ => unreachable!(), } } @@ -475,7 +475,7 @@ mod test { #[test] fn test_uint8_to_constraint_field() -> Result<(), SynthesisError> { let mut rng = ark_std::test_rng(); - let max_size = (::Params::CAPACITY / 8) as usize; + let max_size = ((::MODULUS_BIT_SIZE - 1) / 8) as usize; let modes = [Input, Witness, Constant]; for mode in &modes { diff --git a/src/fields/cubic_extension.rs b/src/fields/cubic_extension.rs index 5a5f5af..a446581 100644 --- a/src/fields/cubic_extension.rs +++ b/src/fields/cubic_extension.rs @@ -1,6 +1,6 @@ use ark_ff::{ - fields::{CubicExtField, CubicExtParameters, Field}, - Zero, + fields::{CubicExtField, Field}, + CubicExtConfig, Zero, }; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use core::{borrow::Borrow, marker::PhantomData}; @@ -16,7 +16,7 @@ use crate::{ #[derive(Derivative)] #[derivative(Debug(bound = "BF: core::fmt::Debug"), Clone(bound = "BF: Clone"))] #[must_use] -pub struct CubicExtVar, P: CubicExtVarParams> +pub struct CubicExtVar, P: CubicExtVarConfig> where for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, { @@ -32,8 +32,8 @@ where /// This trait describes parameters that are used to implement arithmetic for /// `CubicExtVar`. -pub trait CubicExtVarParams>: - CubicExtParameters +pub trait CubicExtVarConfig>: + CubicExtConfig where for<'a> &'a BF: FieldOpsBounds<'a, Self::BaseField, BF>, { @@ -43,7 +43,7 @@ where fn mul_base_field_vars_by_frob_coeff(c1: &mut BF, c2: &mut BF, power: usize); } -impl, P: CubicExtVarParams> CubicExtVar +impl, P: CubicExtVarConfig> CubicExtVar where for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, { @@ -86,7 +86,7 @@ impl R1CSVar for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { type Value = CubicExtField

; @@ -107,7 +107,7 @@ impl From> for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { fn from(other: Boolean) -> Self { let c0 = BF::from(other); @@ -121,14 +121,14 @@ impl<'a, BF, P> FieldOpsBounds<'a, CubicExtField

, CubicExtVar> for Cub where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { } impl<'a, BF, P> FieldOpsBounds<'a, CubicExtField

, CubicExtVar> for &'a CubicExtVar where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { } @@ -136,7 +136,7 @@ impl FieldVar, P::BasePrimeField> for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { fn constant(other: CubicExtField

) -> Self { let c0 = BF::constant(other.c0); @@ -301,7 +301,7 @@ impl_bounded_ops!( |this: &'a CubicExtVar, other: CubicExtField

| { this + CubicExtVar::constant(other) }, - (BF: FieldVar, P: CubicExtVarParams), + (BF: FieldVar, P: CubicExtVarConfig), for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, ); impl_bounded_ops!( @@ -320,7 +320,7 @@ impl_bounded_ops!( |this: &'a CubicExtVar, other: CubicExtField

| { this - CubicExtVar::constant(other) }, - (BF: FieldVar, P: CubicExtVarParams), + (BF: FieldVar, P: CubicExtVarConfig), for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, ); impl_bounded_ops!( @@ -357,7 +357,7 @@ impl_bounded_ops!( |this: &'a CubicExtVar, other: CubicExtField

| { this * CubicExtVar::constant(other) }, - (BF: FieldVar, P: CubicExtVarParams), + (BF: FieldVar, P: CubicExtVarConfig), for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, ); @@ -365,7 +365,7 @@ impl EqGadget for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { #[tracing::instrument(target = "r1cs")] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { @@ -406,7 +406,7 @@ impl ToBitsGadget for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { #[tracing::instrument(target = "r1cs")] fn to_bits_le(&self) -> Result>, SynthesisError> { @@ -433,7 +433,7 @@ impl ToBytesGadget for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { #[tracing::instrument(target = "r1cs")] fn to_bytes(&self) -> Result>, SynthesisError> { @@ -463,7 +463,7 @@ impl ToConstraintFieldGadget for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, BF: ToConstraintFieldGadget, { #[tracing::instrument(target = "r1cs")] @@ -482,7 +482,7 @@ impl CondSelectGadget for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { #[inline] #[tracing::instrument(target = "r1cs")] @@ -503,7 +503,7 @@ where BF: FieldVar + TwoBitLookupGadget, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { type TableConstant = CubicExtField

; @@ -527,7 +527,7 @@ where BF: FieldVar + ThreeBitCondNegLookupGadget, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { type TableConstant = CubicExtField

; @@ -551,7 +551,7 @@ impl AllocVar, P::BasePrimeField> for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: CubicExtVarParams, + P: CubicExtVarConfig, { fn new_variable>>( cs: impl Into>, diff --git a/src/fields/fp/cmp.rs b/src/fields/fp/cmp.rs index 5a82635..0c77d56 100644 --- a/src/fields/fp/cmp.rs +++ b/src/fields/fp/cmp.rs @@ -106,7 +106,7 @@ impl FpVar { // self <= (p-1)/2, which implies self < p. let _ = Boolean::enforce_smaller_or_equal_than_le( &self.to_non_unique_bits_le()?, - F::modulus_minus_one_div_two(), + F::MODULUS_MINUS_ONE_DIV_TWO, )?; Ok(()) } @@ -165,7 +165,7 @@ mod test { fn test_cmp() { let mut rng = ark_std::test_rng(); fn rand_in_range(rng: &mut R) -> Fr { - let pminusonedivtwo: Fr = Fr::modulus_minus_one_div_two().into(); + let pminusonedivtwo: Fr = Fr::MODULUS_MINUS_ONE_DIV_TWO.into(); let mut r; loop { r = Fr::rand(rng); @@ -186,12 +186,12 @@ mod test { Ordering::Less => { a_var.enforce_cmp(&b_var, Ordering::Less, false).unwrap(); a_var.enforce_cmp(&b_var, Ordering::Less, true).unwrap(); - } + }, Ordering::Greater => { a_var.enforce_cmp(&b_var, Ordering::Greater, false).unwrap(); a_var.enforce_cmp(&b_var, Ordering::Greater, true).unwrap(); - } - _ => {} + }, + _ => {}, } if i == 0 { @@ -212,12 +212,12 @@ mod test { Ordering::Less => { a_var.enforce_cmp(&b_var, Ordering::Less, false).unwrap(); a_var.enforce_cmp(&b_var, Ordering::Less, true).unwrap(); - } + }, Ordering::Greater => { a_var.enforce_cmp(&b_var, Ordering::Greater, false).unwrap(); a_var.enforce_cmp(&b_var, Ordering::Greater, true).unwrap(); - } - _ => {} + }, + _ => {}, } assert!(!cs.is_satisfied().unwrap()); diff --git a/src/fields/fp/mod.rs b/src/fields/fp/mod.rs index 69782e3..99b5c99 100644 --- a/src/fields/fp/mod.rs +++ b/src/fields/fp/mod.rs @@ -1,4 +1,4 @@ -use ark_ff::{BigInteger, FpParameters, PrimeField}; +use ark_ff::{BigInteger, PrimeField}; use ark_relations::r1cs::{ ConstraintSystemRef, LinearCombination, Namespace, SynthesisError, Variable, }; @@ -468,15 +468,15 @@ impl ToBitsGadget for AllocatedFp { use ark_ff::BitIteratorBE; let mut bits = if let Some(value) = self.value { let field_char = BitIteratorBE::new(F::characteristic()); - let bits: Vec<_> = BitIteratorBE::new(value.into_repr()) + let bits: Vec<_> = BitIteratorBE::new(value.into_bigint()) .zip(field_char) .skip_while(|(_, c)| !c) .map(|(b, _)| Some(b)) .collect(); - assert_eq!(bits.len(), F::Params::MODULUS_BITS as usize); + assert_eq!(bits.len(), F::MODULUS_BIT_SIZE as usize); bits } else { - vec![None; F::Params::MODULUS_BITS as usize] + vec![None; F::MODULUS_BIT_SIZE as usize] }; // Convert to little-endian @@ -573,7 +573,7 @@ impl CondSelectGadget for AllocatedFp { )?; Ok(result) - } + }, } } } @@ -717,13 +717,13 @@ impl FieldVar for FpVar { (Constant(_), Constant(_), Constant(_)) => Ok(()), (Constant(_), Constant(_), _) | (Constant(_), Var(_), _) | (Var(_), Constant(_), _) => { result.enforce_equal(&(self * other)) - } // this multiplication should be free + }, // this multiplication should be free (Var(v1), Var(v2), Var(v3)) => v1.mul_equals(v2, v3), (Var(v1), Var(v2), Constant(f)) => { let cs = v1.cs.clone(); let v3 = AllocatedFp::new_constant(cs, f).unwrap(); v1.mul_equals(v2, &v3) - } + }, } } @@ -737,12 +737,12 @@ impl FieldVar for FpVar { let cs = r.cs.clone(); let v = AllocatedFp::new_witness(cs, || Ok(f))?; v.square_equals(&r) - } + }, (Var(v), Constant(f)) => { let cs = v.cs.clone(); let r = AllocatedFp::new_witness(cs, || Ok(f))?; v.square_equals(&r) - } + }, (Var(v1), Var(v2)) => v1.square_equals(v2), } } @@ -763,7 +763,7 @@ impl FieldVar for FpVar { let mut f = *f; f.frobenius_map(power); Ok(FpVar::Constant(f)) - } + }, } } @@ -850,7 +850,7 @@ impl EqGadget for FpVar { let cs = v.cs.clone(); let c = AllocatedFp::new_constant(cs, c)?; c.is_eq(v) - } + }, (Self::Var(v1), Self::Var(v2)) => v1.is_eq(v2), } } @@ -867,7 +867,7 @@ impl EqGadget for FpVar { let cs = v.cs.clone(); let c = AllocatedFp::new_constant(cs, c)?; c.conditional_enforce_equal(v, should_enforce) - } + }, (Self::Var(v1), Self::Var(v2)) => v1.conditional_enforce_equal(v2, should_enforce), } } @@ -884,7 +884,7 @@ impl EqGadget for FpVar { let cs = v.cs.clone(); let c = AllocatedFp::new_constant(cs, c)?; c.conditional_enforce_not_equal(v, should_enforce) - } + }, (Self::Var(v1), Self::Var(v2)) => v1.conditional_enforce_not_equal(v2, should_enforce), } } @@ -903,8 +903,8 @@ impl ToBitsGadget for FpVar { fn to_non_unique_bits_le(&self) -> Result>, SynthesisError> { use ark_ff::BitIteratorLE; match self { - Self::Constant(c) => Ok(BitIteratorLE::new(&c.into_repr()) - .take((F::Params::MODULUS_BITS) as usize) + Self::Constant(c) => Ok(BitIteratorLE::new(&c.into_bigint()) + .take((F::MODULUS_BIT_SIZE) as usize) .map(Boolean::constant) .collect::>()), Self::Var(v) => v.to_non_unique_bits_le(), @@ -956,7 +956,7 @@ impl CondSelectGadget for FpVar { let not = AllocatedFp::from(cond.not()); // cond * t + (1 - cond) * f Ok(is.mul_constant(*t).add(¬.mul_constant(*f)).into()) - } + }, (..) => { let cs = cond.cs(); let true_value = match true_value { @@ -968,9 +968,9 @@ impl CondSelectGadget for FpVar { Self::Var(v) => v.clone(), }; cond.select(&true_value, &false_value).map(Self::Var) - } + }, } - } + }, } } } @@ -1049,7 +1049,7 @@ impl<'a, F: PrimeField> Sum<&'a FpVar> for FpVar { FpVar::Constant(c) => { sum_constants += c; None - } + }, FpVar::Var(v) => Some(v), }))); diff --git a/src/fields/fp12.rs b/src/fields/fp12.rs index 3f60c20..7feeda9 100644 --- a/src/fields/fp12.rs +++ b/src/fields/fp12.rs @@ -1,31 +1,33 @@ use crate::fields::{fp2::Fp2Var, fp6_3over2::Fp6Var, quadratic_extension::*, FieldVar}; -use ark_ff::fields::{fp12_2over3over2::*, fp6_3over2::Fp6Parameters, Field, QuadExtParameters}; +use ark_ff::fields::{fp12_2over3over2::*, Field}; +use ark_ff::fp6_3over2::Fp6Config; +use ark_ff::QuadExtConfig; use ark_relations::r1cs::SynthesisError; /// A degree-12 extension field constructed as the tower of a /// quadratic extension over a cubic extension over a quadratic extension field. /// This is the R1CS equivalent of `ark_ff::fp12_2over3over2::Fp12

`. -pub type Fp12Var

= QuadExtVar::Fp6Params>, Fp12ParamsWrapper

>; +pub type Fp12Var

= QuadExtVar::Fp6Config>, Fp12ConfigWrapper

>; -type Fp2Params

= <

::Fp6Params as Fp6Parameters>::Fp2Params; +type Fp2Config

= <

::Fp6Config as Fp6Config>::Fp2Config; -impl QuadExtVarParams> for Fp12ParamsWrapper

{ - fn mul_base_field_var_by_frob_coeff(fe: &mut Fp6Var, power: usize) { +impl QuadExtVarConfig> for Fp12ConfigWrapper

{ + fn mul_base_field_var_by_frob_coeff(fe: &mut Fp6Var, power: usize) { fe.c0 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; fe.c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; fe.c2 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; } } -impl Fp12Var

{ +impl Fp12Var

{ /// Multiplies by a sparse element of the form `(c0 = (c0, c1, 0), c1 = (0, /// d1, 0))`. #[inline] pub fn mul_by_014( &self, - c0: &Fp2Var>, - c1: &Fp2Var>, - d1: &Fp2Var>, + c0: &Fp2Var>, + c1: &Fp2Var>, + d1: &Fp2Var>, ) -> Result { let v0 = self.c0.mul_by_c0_c1_0(&c0, &c1)?; let v1 = self.c1.mul_by_0_c1_0(&d1)?; @@ -40,9 +42,9 @@ impl Fp12Var

{ #[inline] pub fn mul_by_034( &self, - c0: &Fp2Var>, - d0: &Fp2Var>, - d1: &Fp2Var>, + c0: &Fp2Var>, + d0: &Fp2Var>, + d1: &Fp2Var>, ) -> Result { let a0 = &self.c0.c0 * c0; let a1 = &self.c0.c1 * c0; @@ -62,7 +64,7 @@ impl Fp12Var

{ /// Squares `self` when `self` is in the cyclotomic subgroup. pub fn cyclotomic_square(&self) -> Result { if characteristic_square_mod_6_is_one(Fp12::

::characteristic()) { - let fp2_nr = ::NONRESIDUE; + let fp2_nr = ::NONRESIDUE; let z0 = &self.c0.c0; let z4 = &self.c0.c1; @@ -143,12 +145,12 @@ impl Fp12Var

{ &self, exponent: impl AsRef<[u64]>, ) -> Result { - use ark_ff::biginteger::arithmetic::find_wnaf; + use ark_ff::biginteger::arithmetic::find_naf; let mut res = Self::one(); let self_inverse = self.unitary_inverse()?; let mut found_nonzero = false; - let naf = find_wnaf(exponent.as_ref()); + let naf = find_naf(exponent.as_ref()); for &value in naf.iter().rev() { if found_nonzero { diff --git a/src/fields/fp2.rs b/src/fields/fp2.rs index f1183df..13d8868 100644 --- a/src/fields/fp2.rs +++ b/src/fields/fp2.rs @@ -1,11 +1,11 @@ use crate::fields::{fp::FpVar, quadratic_extension::*}; -use ark_ff::fields::{Fp2Parameters, Fp2ParamsWrapper, QuadExtParameters}; +use ark_ff::fields::{Fp2Config, Fp2ConfigWrapper, QuadExtConfig}; /// A quadratic extension field constructed over a prime field. /// This is the R1CS equivalent of `ark_ff::Fp2

`. -pub type Fp2Var

= QuadExtVar::Fp>, Fp2ParamsWrapper

>; +pub type Fp2Var

= QuadExtVar::Fp>, Fp2ConfigWrapper

>; -impl QuadExtVarParams> for Fp2ParamsWrapper

{ +impl QuadExtVarConfig> for Fp2ConfigWrapper

{ fn mul_base_field_var_by_frob_coeff(fe: &mut FpVar, power: usize) { *fe *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; } diff --git a/src/fields/fp3.rs b/src/fields/fp3.rs index b20b80c..6e04084 100644 --- a/src/fields/fp3.rs +++ b/src/fields/fp3.rs @@ -1,11 +1,12 @@ use crate::fields::{cubic_extension::*, fp::FpVar}; -use ark_ff::fields::{CubicExtParameters, Fp3Parameters, Fp3ParamsWrapper}; +use ark_ff::fields::{CubicExtConfig, Fp3ConfigWrapper}; +use ark_ff::Fp3Config; /// A cubic extension field constructed over a prime field. /// This is the R1CS equivalent of `ark_ff::Fp3

`. -pub type Fp3Var

= CubicExtVar::Fp>, Fp3ParamsWrapper

>; +pub type Fp3Var

= CubicExtVar::Fp>, Fp3ConfigWrapper

>; -impl CubicExtVarParams> for Fp3ParamsWrapper

{ +impl CubicExtVarConfig> for Fp3ConfigWrapper

{ fn mul_base_field_vars_by_frob_coeff( c1: &mut FpVar, c2: &mut FpVar, diff --git a/src/fields/fp4.rs b/src/fields/fp4.rs index 1023873..3efd82d 100644 --- a/src/fields/fp4.rs +++ b/src/fields/fp4.rs @@ -1,13 +1,14 @@ use crate::fields::{fp2::Fp2Var, quadratic_extension::*}; -use ark_ff::fields::{Fp4Parameters, Fp4ParamsWrapper, QuadExtParameters}; +use ark_ff::fields::{Fp4ConfigWrapper, QuadExtConfig}; +use ark_ff::Fp4Config; /// A quartic extension field constructed as the tower of a /// quadratic extension over a quadratic extension field. /// This is the R1CS equivalent of `ark_ff::Fp4

`. -pub type Fp4Var

= QuadExtVar::Fp2Params>, Fp4ParamsWrapper

>; +pub type Fp4Var

= QuadExtVar::Fp2Config>, Fp4ConfigWrapper

>; -impl QuadExtVarParams> for Fp4ParamsWrapper

{ - fn mul_base_field_var_by_frob_coeff(fe: &mut Fp2Var, power: usize) { +impl QuadExtVarConfig> for Fp4ConfigWrapper

{ + fn mul_base_field_var_by_frob_coeff(fe: &mut Fp2Var, power: usize) { fe.c0 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; fe.c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; } diff --git a/src/fields/fp6_2over3.rs b/src/fields/fp6_2over3.rs index 07b172b..f651495 100644 --- a/src/fields/fp6_2over3.rs +++ b/src/fields/fp6_2over3.rs @@ -1,13 +1,14 @@ use crate::fields::{fp3::Fp3Var, quadratic_extension::*}; -use ark_ff::fields::{fp6_2over3::*, QuadExtParameters}; +use ark_ff::fields::fp6_2over3::*; +use ark_ff::QuadExtConfig; /// A sextic extension field constructed as the tower of a /// quadratic extension over a cubic extension field. /// This is the R1CS equivalent of `ark_ff::fp6_2over3::Fp6

`. -pub type Fp6Var

= QuadExtVar::Fp3Params>, Fp6ParamsWrapper

>; +pub type Fp6Var

= QuadExtVar::Fp3Config>, Fp6ConfigWrapper

>; -impl QuadExtVarParams> for Fp6ParamsWrapper

{ - fn mul_base_field_var_by_frob_coeff(fe: &mut Fp3Var, power: usize) { +impl QuadExtVarConfig> for Fp6ConfigWrapper

{ + fn mul_base_field_var_by_frob_coeff(fe: &mut Fp3Var, power: usize) { fe.c0 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; fe.c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; fe.c2 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; diff --git a/src/fields/fp6_3over2.rs b/src/fields/fp6_3over2.rs index fdef07d..948bebe 100644 --- a/src/fields/fp6_3over2.rs +++ b/src/fields/fp6_3over2.rs @@ -1,17 +1,18 @@ use crate::fields::{cubic_extension::*, fp2::*}; -use ark_ff::fields::{fp6_3over2::*, CubicExtParameters, Fp2}; +use ark_ff::fields::{fp6_3over2::*, Fp2}; +use ark_ff::CubicExtConfig; use ark_relations::r1cs::SynthesisError; -use core::ops::MulAssign; +use ark_std::ops::MulAssign; /// A sextic extension field constructed as the tower of a /// cubic extension over a quadratic extension field. /// This is the R1CS equivalent of `ark_ff::fp6_3over3::Fp6

`. -pub type Fp6Var

= CubicExtVar::Fp2Params>, Fp6ParamsWrapper

>; +pub type Fp6Var

= CubicExtVar::Fp2Config>, Fp6ConfigWrapper

>; -impl CubicExtVarParams> for Fp6ParamsWrapper

{ +impl CubicExtVarConfig> for Fp6ConfigWrapper

{ fn mul_base_field_vars_by_frob_coeff( - c1: &mut Fp2Var, - c2: &mut Fp2Var, + c1: &mut Fp2Var, + c2: &mut Fp2Var, power: usize, ) { *c1 *= Self::FROBENIUS_COEFF_C1[power % Self::DEGREE_OVER_BASE_PRIME_FIELD]; @@ -19,9 +20,9 @@ impl CubicExtVarParams> for Fp6ParamsWrap } } -impl Fp6Var

{ +impl Fp6Var

{ /// Multiplies `self` by a sparse element which has `c0 == c2 == zero`. - pub fn mul_by_0_c1_0(&self, c1: &Fp2Var) -> Result { + pub fn mul_by_0_c1_0(&self, c1: &Fp2Var) -> Result { // Karatsuba multiplication // v0 = a0 * b0 = 0 @@ -51,8 +52,8 @@ impl Fp6Var

{ /// Multiplies `self` by a sparse element which has `c2 == zero`. pub fn mul_by_c0_c1_0( &self, - c0: &Fp2Var, - c1: &Fp2Var, + c0: &Fp2Var, + c1: &Fp2Var, ) -> Result { let v0 = &self.c0 * c0; let v1 = &self.c1 * c1; @@ -76,8 +77,8 @@ impl Fp6Var

{ } } -impl MulAssign> for Fp6Var

{ - fn mul_assign(&mut self, other: Fp2) { +impl MulAssign> for Fp6Var

{ + fn mul_assign(&mut self, other: Fp2) { self.c0 *= other; self.c1 *= other; self.c2 *= other; diff --git a/src/fields/mod.rs b/src/fields/mod.rs index a199d73..c98f4fa 100644 --- a/src/fields/mod.rs +++ b/src/fields/mod.rs @@ -190,7 +190,7 @@ pub trait FieldVar: })?; result.mul_equals(d, self)?; Ok(result) - } + }, } } diff --git a/src/fields/nonnative/allocated_field_var.rs b/src/fields/nonnative/allocated_field_var.rs index 4c6220b..5158111 100644 --- a/src/fields/nonnative/allocated_field_var.rs +++ b/src/fields/nonnative/allocated_field_var.rs @@ -4,7 +4,7 @@ use super::AllocatedNonNativeFieldMulResultVar; use crate::fields::fp::FpVar; use crate::prelude::*; use crate::ToConstraintFieldGadget; -use ark_ff::{BigInteger, FpParameters, PrimeField}; +use ark_ff::{BigInteger, PrimeField}; use ark_relations::r1cs::{OptimizationGoal, Result as R1CSResult}; use ark_relations::{ ns, @@ -44,17 +44,17 @@ impl optimization_type: OptimizationType, ) -> TargetField { let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, optimization_type, ); - let mut base_repr: ::BigInt = TargetField::one().into_repr(); + let mut base_repr: ::BigInt = TargetField::one().into_bigint(); // Convert 2^{(params.bits_per_limb - 1)} into the TargetField and then double the base // This is because 2^{(params.bits_per_limb)} might indeed be larger than the target field's prime. base_repr.muln((params.bits_per_limb - 1) as u32); - let mut base: TargetField = TargetField::from_repr(base_repr).unwrap(); + let mut base: TargetField = TargetField::from_bigint(base_repr).unwrap(); base = base + &base; let mut result = TargetField::zero(); @@ -64,7 +64,7 @@ impl let mut val = TargetField::zero(); let mut cur = TargetField::one(); - for bit in limb.into_repr().to_bits_be().iter().rev() { + for bit in limb.into_bigint().to_bits_be().iter().rev() { if *bit { val += &cur; } @@ -182,18 +182,19 @@ impl assert_eq!(self.get_optimization_type(), other.get_optimization_type()); let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, self.get_optimization_type(), ); // Step 1: reduce the `other` if needed let mut surfeit = overhead!(other.num_of_additions_over_normal_form + BaseField::one()) + 1; let mut other = other.clone(); - if (surfeit + params.bits_per_limb > BaseField::size_in_bits() - 1) + if (surfeit + params.bits_per_limb > BaseField::MODULUS_BIT_SIZE as usize - 1) || (surfeit - + (TargetField::size_in_bits() - params.bits_per_limb * (params.num_limbs - 1)) - > BaseField::size_in_bits() - 1) + + (TargetField::MODULUS_BIT_SIZE as usize + - params.bits_per_limb * (params.num_limbs - 1)) + > BaseField::MODULUS_BIT_SIZE as usize - 1) { Reducer::reduce(&mut other)?; surfeit = overhead!(other.num_of_additions_over_normal_form + BaseField::one()) + 1; @@ -201,18 +202,18 @@ impl // Step 2: construct the padding let mut pad_non_top_limb_repr: ::BigInt = - BaseField::one().into_repr(); + BaseField::one().into_bigint(); let mut pad_top_limb_repr: ::BigInt = pad_non_top_limb_repr; pad_non_top_limb_repr.muln((surfeit + params.bits_per_limb) as u32); - let pad_non_top_limb = BaseField::from_repr(pad_non_top_limb_repr).unwrap(); + let pad_non_top_limb = BaseField::from_bigint(pad_non_top_limb_repr).unwrap(); pad_top_limb_repr.muln( (surfeit - + (TargetField::size_in_bits() - params.bits_per_limb * (params.num_limbs - 1))) - as u32, + + (TargetField::MODULUS_BIT_SIZE as usize + - params.bits_per_limb * (params.num_limbs - 1))) as u32, ); - let pad_top_limb = BaseField::from_repr(pad_top_limb_repr).unwrap(); + let pad_top_limb = BaseField::from_bigint(pad_top_limb_repr).unwrap(); let mut pad_limbs = Vec::new(); pad_limbs.push(pad_top_limb); @@ -307,7 +308,7 @@ impl elem: &TargetField, optimization_type: OptimizationType, ) -> R1CSResult> { - Self::get_limbs_representations_from_big_integer(&elem.into_repr(), optimization_type) + Self::get_limbs_representations_from_big_integer(&elem.into_bigint(), optimization_type) } /// Obtain the limbs directly from a big int @@ -316,8 +317,8 @@ impl optimization_type: OptimizationType, ) -> R1CSResult> { let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, optimization_type, ); @@ -329,7 +330,7 @@ impl let cur_mod_r = ::BigInt::from_bits_be( &cur_bits[cur_bits.len() - params.bits_per_limb..], ); // therefore, the lowest `bits_per_non_top_limb` bits is what we want. - limbs.push(BaseField::from_repr(cur_mod_r).unwrap()); + limbs.push(BaseField::from_bigint(cur_mod_r).unwrap()); cur.divn(params.bits_per_limb as u32); } @@ -349,8 +350,8 @@ impl assert_eq!(self.get_optimization_type(), other.get_optimization_type()); let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, self.get_optimization_type(), ); @@ -443,15 +444,15 @@ impl assert_eq!(self.get_optimization_type(), other.get_optimization_type()); let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, self.get_optimization_type(), ); // Get p let p_representations = AllocatedNonNativeFieldVar::::get_limbs_representations_from_big_integer( - &::Params::MODULUS, + &::MODULUS, self.get_optimization_type() )?; let p_bigint = limbs_to_bigint(params.bits_per_limb, &p_representations); @@ -594,8 +595,8 @@ impl OptimizationGoal::Weight => OptimizationType::Weight, }; let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, optimization_type, ); let mut bits = Vec::new(); @@ -610,7 +611,8 @@ impl bits.extend( Reducer::::limb_to_bits( &self.limbs[0], - TargetField::size_in_bits() - (params.num_limbs - 1) * params.bits_per_limb, + TargetField::MODULUS_BIT_SIZE as usize + - (params.num_limbs - 1) * params.bits_per_limb, )? .into_iter() .rev(), @@ -640,8 +642,8 @@ impl ToBitsGadget #[tracing::instrument(target = "r1cs")] fn to_bits_le(&self) -> R1CSResult>> { let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, self.get_optimization_type(), ); @@ -746,8 +748,8 @@ impl TwoBitLookupGadget ThreeBitCondNegLookupGadget }; let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, optimization_type, ); @@ -874,8 +876,8 @@ impl ToConstraintFieldGadget { fn from(src: &AllocatedNonNativeFieldVar) -> Self { let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, src.get_optimization_type(), ); @@ -62,14 +62,14 @@ impl /// Get the value of the multiplication result pub fn value(&self) -> R1CSResult { let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, self.get_optimization_type(), ); let p_representations = AllocatedNonNativeFieldVar::::get_limbs_representations_from_big_integer( - &::Params::MODULUS, + &::MODULUS, self.get_optimization_type() )?; let p_bigint = limbs_to_bigint(params.bits_per_limb, &p_representations); @@ -87,15 +87,15 @@ impl /// Constraints for reducing the result of a multiplication mod p, to get an original representation. pub fn reduce(&self) -> R1CSResult> { let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, self.get_optimization_type(), ); // Step 1: get p let p_representations = AllocatedNonNativeFieldVar::::get_limbs_representations_from_big_integer( - &::Params::MODULUS, + &::MODULUS, self.get_optimization_type() )?; let p_bigint = limbs_to_bigint(params.bits_per_limb, &p_representations); @@ -127,7 +127,7 @@ impl let value_bigint = limbs_to_bigint(params.bits_per_limb, &limbs_values); let mut k_cur = value_bigint / p_bigint; - let total_len = TargetField::size_in_bits() + surfeit; + let total_len = TargetField::MODULUS_BIT_SIZE as usize + surfeit; for _ in 0..total_len { res.push(Boolean::::new_witness(self.cs(), || { @@ -184,8 +184,8 @@ impl )?; let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, self.get_optimization_type(), ); diff --git a/src/fields/nonnative/field_var.rs b/src/fields/nonnative/field_var.rs index eb7ccf1..c03310d 100644 --- a/src/fields/nonnative/field_var.rs +++ b/src/fields/nonnative/field_var.rs @@ -5,8 +5,8 @@ use crate::fields::fp::FpVar; use crate::fields::FieldVar; use crate::prelude::*; use crate::{R1CSVar, ToConstraintFieldGadget}; +use ark_ff::to_bytes; use ark_ff::PrimeField; -use ark_ff::{to_bytes, FpParameters}; use ark_relations::r1cs::Result as R1CSResult; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use ark_std::hash::{Hash, Hasher}; @@ -248,12 +248,12 @@ impl EqGadget should_enforce.enforce_equal(&Boolean::FALSE)?; } Ok(()) - } + }, (Self::Constant(c), Self::Var(v)) | (Self::Var(v), Self::Constant(c)) => { let cs = v.cs(); let c = AllocatedNonNativeFieldVar::new_constant(cs, c)?; c.conditional_enforce_equal(v, should_enforce) - } + }, (Self::Var(v1), Self::Var(v2)) => v1.conditional_enforce_equal(v2, should_enforce), } } @@ -270,12 +270,12 @@ impl EqGadget should_enforce.enforce_equal(&Boolean::FALSE)?; } Ok(()) - } + }, (Self::Constant(c), Self::Var(v)) | (Self::Var(v), Self::Constant(c)) => { let cs = v.cs(); let c = AllocatedNonNativeFieldVar::new_constant(cs, c)?; c.conditional_enforce_not_equal(v, should_enforce) - } + }, (Self::Var(v1), Self::Var(v2)) => v1.conditional_enforce_not_equal(v2, should_enforce), } } @@ -296,8 +296,8 @@ impl ToBitsGadget fn to_non_unique_bits_le(&self) -> R1CSResult>> { use ark_ff::BitIteratorLE; match self { - Self::Constant(c) => Ok(BitIteratorLE::new(&c.into_repr()) - .take((TargetField::Params::MODULUS_BITS) as usize) + Self::Constant(c) => Ok(BitIteratorLE::new(&c.into_bigint()) + .take((TargetField::MODULUS_BIT_SIZE) as usize) .map(Boolean::constant) .collect::>()), Self::Var(v) => v.to_non_unique_bits_le(), @@ -350,7 +350,7 @@ impl CondSelectGadget Self::Var(v) => v.clone(), }; cond.select(&true_value, &false_value).map(Self::Var) - } + }, } } } @@ -473,7 +473,7 @@ impl NonNativeFieldVar { let other_v = match other { @@ -482,13 +482,13 @@ impl NonNativeFieldVar other_v.clone(), }; Ok(NonNativeFieldMulResultVar::Var( v.mul_without_reduce(&other_v)?, )) - } + }, } } } diff --git a/src/fields/nonnative/mod.rs b/src/fields/nonnative/mod.rs index 45e2b90..7d6522c 100644 --- a/src/fields/nonnative/mod.rs +++ b/src/fields/nonnative/mod.rs @@ -130,7 +130,7 @@ macro_rules! overhead { ($x:expr) => {{ use ark_ff::BigInteger; let num = $x; - let num_bits = num.into_repr().to_bits_be(); + let num_bits = num.into_bigint().to_bits_be(); let mut skipped_bits = 0; for b in num_bits.iter() { if *b == false { @@ -159,7 +159,7 @@ pub(crate) use overhead; /// Parameters for a specific `NonNativeFieldVar` instantiation #[derive(Clone, Debug)] -pub struct NonNativeFieldParams { +pub struct NonNativeFieldConfig { /// The number of limbs (`BaseField` elements) used to represent a `TargetField` element. Highest limb first. pub num_limbs: usize, diff --git a/src/fields/nonnative/mul_result.rs b/src/fields/nonnative/mul_result.rs index b1eb58c..25ec310 100644 --- a/src/fields/nonnative/mul_result.rs +++ b/src/fields/nonnative/mul_result.rs @@ -53,7 +53,7 @@ impl TargetField, BaseField, >::from(v)) - } + }, } } } diff --git a/src/fields/nonnative/params.rs b/src/fields/nonnative/params.rs index 6345547..160a273 100644 --- a/src/fields/nonnative/params.rs +++ b/src/fields/nonnative/params.rs @@ -1,4 +1,4 @@ -use super::NonNativeFieldParams; +use super::NonNativeFieldConfig; /// Obtain the parameters from a `ConstraintSystem`'s cache or generate a new one #[must_use] @@ -6,10 +6,10 @@ pub const fn get_params( target_field_size: usize, base_field_size: usize, optimization_type: OptimizationType, -) -> NonNativeFieldParams { +) -> NonNativeFieldConfig { let (num_of_limbs, limb_size) = find_parameters(base_field_size, target_field_size, optimization_type); - NonNativeFieldParams { + NonNativeFieldConfig { num_limbs: num_of_limbs, bits_per_limb: limb_size, } @@ -54,10 +54,10 @@ pub const fn find_parameters( match optimization_type { OptimizationType::Constraints => { this_cost += 2 * num_of_limbs - 1; - } + }, OptimizationType::Weight => { this_cost += 6 * num_of_limbs * num_of_limbs; - } + }, }; match optimization_type { @@ -67,7 +67,7 @@ pub const fn find_parameters( //this_cost += 2 * num_of_limbs - 1; // compute kp this_cost += num_of_groups + (num_of_groups - 1) * (limb_size * 2 + surfeit) + 1; // equality check - } + }, OptimizationType::Weight => { this_cost += target_field_prime_bit_length * 3 + target_field_prime_bit_length; // allocation of k this_cost += target_field_prime_bit_length * 3 @@ -79,7 +79,7 @@ pub const fn find_parameters( + 6 * num_of_groups + (num_of_groups - 1) * (2 * limb_size + surfeit) * 4 + 2; // equality check - } + }, }; if !found || this_cost < min_cost { diff --git a/src/fields/nonnative/reduce.rs b/src/fields/nonnative/reduce.rs index c5d2089..0fea085 100644 --- a/src/fields/nonnative/reduce.rs +++ b/src/fields/nonnative/reduce.rs @@ -5,7 +5,7 @@ use crate::eq::EqGadget; use crate::fields::fp::FpVar; use crate::fields::FieldVar; use crate::{alloc::AllocVar, boolean::Boolean, R1CSVar}; -use ark_ff::{biginteger::BigInteger, fields::FpParameters, BitIteratorBE, One, PrimeField, Zero}; +use ark_ff::{biginteger::BigInteger, BitIteratorBE, One, PrimeField, Zero}; use ark_relations::{ ns, r1cs::{ConstraintSystemRef, Result as R1CSResult}, @@ -22,7 +22,7 @@ pub fn limbs_to_bigint( let mut big_cur = BigUint::one(); let two = BigUint::from(2u32); for limb in limbs.iter().rev() { - let limb_repr = limb.into_repr().to_bits_le(); + let limb_repr = limb.into_bigint().to_bits_le(); let mut small_cur = big_cur.clone(); for limb_bit in limb_repr.iter() { if *limb_bit { @@ -41,7 +41,8 @@ pub fn bigint_to_basefield(bigint: &BigUint) -> BaseField let mut cur = BaseField::one(); let bytes = bigint.to_bytes_be(); - let basefield_256 = BaseField::from_repr(::BigInt::from(256)).unwrap(); + let basefield_256 = + BaseField::from_bigint(::BigInt::from(256u64)).unwrap(); for byte in bytes.iter().rev() { let bytes_basefield = BaseField::from(*byte as u128); @@ -60,7 +61,7 @@ pub struct Reducer { } impl Reducer { - /// convert limbs to bits (take at most `BaseField::size_in_bits() - 1` bits) + /// convert limbs to bits (take at most `BaseField::MODULUS_BIT_SIZE as usize - 1` bits) /// This implementation would be more efficient than the original `to_bits` /// or `to_non_unique_bits` since we enforce that some bits are always zero. #[tracing::instrument(target = "r1cs")] @@ -70,14 +71,16 @@ impl Reducer R1CSResult>> { let cs = limb.cs(); - let num_bits = min(BaseField::size_in_bits() - 1, num_bits); + let num_bits = min(BaseField::MODULUS_BIT_SIZE as usize - 1, num_bits); let mut bits_considered = Vec::with_capacity(num_bits); let limb_value = limb.value().unwrap_or_default(); - for b in BitIteratorBE::new(limb_value.into_repr()).skip( - <::Params as FpParameters>::REPR_SHAVE_BITS as usize - + (BaseField::size_in_bits() - num_bits), - ) { + let num_bits_to_shave = + BaseField::BigInt::NUM_LIMBS * 64 - (BaseField::MODULUS_BIT_SIZE as usize); + + for b in BitIteratorBE::new(limb_value.into_bigint()) + .skip(num_bits_to_shave + (BaseField::MODULUS_BIT_SIZE as usize - num_bits)) + { bits_considered.push(b); } @@ -131,13 +134,13 @@ impl Reducer, ) -> R1CSResult<()> { let params = get_params( - TargetField::size_in_bits(), - BaseField::size_in_bits(), + TargetField::MODULUS_BIT_SIZE as usize, + BaseField::MODULUS_BIT_SIZE as usize, elem.get_optimization_type(), ); let surfeit = overhead!(elem.num_of_additions_over_normal_form + BaseField::one()) + 1; - if BaseField::size_in_bits() > 2 * params.bits_per_limb + surfeit + 1 { + if BaseField::MODULUS_BIT_SIZE as usize > 2 * params.bits_per_limb + surfeit + 1 { Ok(()) } else { Self::reduce(elem) @@ -156,13 +159,13 @@ impl Reducer BaseField::size_in_bits() - 1 + > BaseField::MODULUS_BIT_SIZE as usize - 1 { panic!("The current limb parameters do not support multiplication."); } @@ -172,14 +175,14 @@ impl Reducer::BigInt::from( + &BaseField::from_bigint(::BigInt::from( (params.num_limbs) as u64 )) .unwrap() )); let bits_per_mulresult_limb = 2 * (params.bits_per_limb + 1) + overhead_limb; - if bits_per_mulresult_limb < BaseField::size_in_bits() { + if bits_per_mulresult_limb < BaseField::MODULUS_BIT_SIZE as usize { break; } @@ -220,7 +223,7 @@ impl Reducer::zero(); let mut limb_pairs = Vec::<(FpVar, FpVar)>::new(); - let num_limb_in_a_group = (BaseField::size_in_bits() + let num_limb_in_a_group = (BaseField::MODULUS_BIT_SIZE as usize - 1 - surfeit - 1 @@ -231,9 +234,9 @@ impl Reducer Reducer::BigInt = BaseField::one().into_repr(); + let mut pad_limb_repr: ::BigInt = + BaseField::one().into_bigint(); pad_limb_repr.muln( (surfeit @@ -282,7 +286,7 @@ impl Reducer Reducer::new_witness(cs.clone(), || Ok(carry_value))?; diff --git a/src/fields/quadratic_extension.rs b/src/fields/quadratic_extension.rs index 28b771d..5e665bb 100644 --- a/src/fields/quadratic_extension.rs +++ b/src/fields/quadratic_extension.rs @@ -1,5 +1,5 @@ use ark_ff::{ - fields::{Field, QuadExtField, QuadExtParameters}, + fields::{Field, QuadExtConfig, QuadExtField}, Zero, }; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; @@ -16,7 +16,7 @@ use crate::{ #[derive(Derivative)] #[derivative(Debug(bound = "BF: core::fmt::Debug"), Clone(bound = "BF: Clone"))] #[must_use] -pub struct QuadExtVar, P: QuadExtVarParams> +pub struct QuadExtVar, P: QuadExtVarConfig> where for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, { @@ -30,8 +30,8 @@ where /// This trait describes parameters that are used to implement arithmetic for /// `QuadExtVar`. -pub trait QuadExtVarParams>: - QuadExtParameters +pub trait QuadExtVarConfig>: + QuadExtConfig where for<'a> &'a BF: FieldOpsBounds<'a, Self::BaseField, BF>, { @@ -41,7 +41,7 @@ where fn mul_base_field_var_by_frob_coeff(fe: &mut BF, power: usize); } -impl, P: QuadExtVarParams> QuadExtVar +impl, P: QuadExtVarConfig> QuadExtVar where for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, { @@ -94,7 +94,7 @@ where let self_inverse = self.unitary_inverse()?; let mut found_nonzero = false; - let naf = ark_ff::biginteger::arithmetic::find_wnaf(exponent.as_ref()); + let naf = ark_ff::biginteger::arithmetic::find_naf(exponent.as_ref()); for &value in naf.iter().rev() { if found_nonzero { @@ -120,7 +120,7 @@ impl R1CSVar for QuadExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { type Value = QuadExtField

; @@ -141,7 +141,7 @@ impl From> for QuadExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { fn from(other: Boolean) -> Self { let c0 = BF::from(other); @@ -154,14 +154,14 @@ impl<'a, BF, P> FieldOpsBounds<'a, QuadExtField

, QuadExtVar> for QuadE where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { } impl<'a, BF, P> FieldOpsBounds<'a, QuadExtField

, QuadExtVar> for &'a QuadExtVar where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { } @@ -169,7 +169,7 @@ impl FieldVar, P::BasePrimeField> for QuadExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { fn constant(other: QuadExtField

) -> Self { let c0 = BF::constant(other.c0); @@ -308,7 +308,7 @@ impl_bounded_ops!( |this: &'a QuadExtVar, other: QuadExtField

| { this + QuadExtVar::constant(other) }, - (BF: FieldVar, P: QuadExtVarParams), + (BF: FieldVar, P: QuadExtVarConfig), for <'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF> ); impl_bounded_ops!( @@ -326,7 +326,7 @@ impl_bounded_ops!( |this: &'a QuadExtVar, other: QuadExtField

| { this - QuadExtVar::constant(other) }, - (BF: FieldVar, P: QuadExtVarParams), + (BF: FieldVar, P: QuadExtVarConfig), for <'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF> ); impl_bounded_ops!( @@ -363,7 +363,7 @@ impl_bounded_ops!( |this: &'a QuadExtVar, other: QuadExtField

| { this * QuadExtVar::constant(other) }, - (BF: FieldVar, P: QuadExtVarParams), + (BF: FieldVar, P: QuadExtVarConfig), for <'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF> ); @@ -371,7 +371,7 @@ impl EqGadget for QuadExtVar where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { #[tracing::instrument(target = "r1cs")] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { @@ -410,7 +410,7 @@ impl ToBitsGadget for QuadExtVar where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { #[tracing::instrument(target = "r1cs")] fn to_bits_le(&self) -> Result>, SynthesisError> { @@ -433,7 +433,7 @@ impl ToBytesGadget for QuadExtVar where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { #[tracing::instrument(target = "r1cs")] fn to_bytes(&self) -> Result>, SynthesisError> { @@ -456,7 +456,7 @@ impl ToConstraintFieldGadget for QuadExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, BF: ToConstraintFieldGadget, { #[tracing::instrument(target = "r1cs")] @@ -474,7 +474,7 @@ impl CondSelectGadget for QuadExtVar where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { #[inline] fn conditionally_select( @@ -493,7 +493,7 @@ where BF: FieldVar + TwoBitLookupGadget, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { type TableConstant = QuadExtField

; @@ -515,7 +515,7 @@ where BF: FieldVar + ThreeBitCondNegLookupGadget, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { type TableConstant = QuadExtField

; @@ -537,7 +537,7 @@ impl AllocVar, P::BasePrimeField> for QuadExtVar where BF: FieldVar, for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, - P: QuadExtVarParams, + P: QuadExtVarConfig, { fn new_variable>>( cs: impl Into>, diff --git a/src/groups/curves/short_weierstrass/bls12/mod.rs b/src/groups/curves/short_weierstrass/bls12/mod.rs index 9563c05..662f30a 100644 --- a/src/groups/curves/short_weierstrass/bls12/mod.rs +++ b/src/groups/curves/short_weierstrass/bls12/mod.rs @@ -98,14 +98,14 @@ impl ToBytesGadget for G1PreparedVar

{ } } -type Fp2G

= Fp2Var<

::Fp2Params>; +type Fp2G

= Fp2Var<

::Fp2Config>; type LCoeff

= (Fp2G

, Fp2G

); /// Represents the cached precomputation that can be performed on a G2 element /// which enables speeding up pairing computation. #[derive(Derivative)] #[derivative( - Clone(bound = "Fp2Var: Clone"), - Debug(bound = "Fp2Var: Debug") + Clone(bound = "Fp2Var: Clone"), + Debug(bound = "Fp2Var: Debug") )] pub struct G2PreparedVar { #[doc(hidden)] @@ -135,7 +135,7 @@ impl AllocVar, P::Fp> for G2PreparedVar

{ .zip(z_s) .map(|((x, y, _), z_inv)| (*x * &z_inv, *y * &z_inv)) .collect::>() - } + }, TwistType::D => { let mut z_s = projective_coeffs .iter() @@ -147,7 +147,7 @@ impl AllocVar, P::Fp> for G2PreparedVar

{ .zip(z_s) .map(|((_, x, y), z_inv)| (*x * &z_inv, *y * &z_inv)) .collect::>() - } + }, } }); diff --git a/src/groups/curves/short_weierstrass/mnt4/mod.rs b/src/groups/curves/short_weierstrass/mnt4/mod.rs index bd0bdc6..d55476a 100644 --- a/src/groups/curves/short_weierstrass/mnt4/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt4/mod.rs @@ -31,9 +31,9 @@ pub struct G1PreparedVar { #[doc(hidden)] pub y: FpVar, #[doc(hidden)] - pub x_twist: Fp2Var, + pub x_twist: Fp2Var, #[doc(hidden)] - pub y_twist: Fp2Var, + pub y_twist: Fp2Var, } impl AllocVar, P::Fp> for G1PreparedVar

{ @@ -131,7 +131,7 @@ impl ToBytesGadget for G1PreparedVar

{ } } -type Fp2G

= Fp2Var<

::Fp2Params>; +type Fp2G

= Fp2Var<

::Fp2Config>; /// Represents the cached precomputation that can be performed on a G2 element /// which enables speeding up pairing computation. @@ -139,13 +139,13 @@ type Fp2G

= Fp2Var<

::Fp2Params>; #[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))] pub struct G2PreparedVar { #[doc(hidden)] - pub x: Fp2Var, + pub x: Fp2Var, #[doc(hidden)] - pub y: Fp2Var, + pub y: Fp2Var, #[doc(hidden)] - pub x_over_twist: Fp2Var, + pub x_over_twist: Fp2Var, #[doc(hidden)] - pub y_over_twist: Fp2Var, + pub y_over_twist: Fp2Var, #[doc(hidden)] pub double_coefficients: Vec>, #[doc(hidden)] @@ -344,10 +344,10 @@ impl G2PreparedVar

{ #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))] pub struct AteDoubleCoefficientsVar { - pub c_h: Fp2Var, - pub c_4c: Fp2Var, - pub c_j: Fp2Var, - pub c_l: Fp2Var, + pub c_h: Fp2Var, + pub c_4c: Fp2Var, + pub c_j: Fp2Var, + pub c_l: Fp2Var, } impl AllocVar, P::Fp> for AteDoubleCoefficientsVar

{ @@ -429,8 +429,8 @@ impl AteDoubleCoefficientsVar

{ #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT4Parameters"), Debug(bound = "P: MNT4Parameters"))] pub struct AteAdditionCoefficientsVar { - pub c_l1: Fp2Var, - pub c_rz: Fp2Var, + pub c_l1: Fp2Var, + pub c_rz: Fp2Var, } impl AllocVar, P::Fp> @@ -488,8 +488,8 @@ impl AteAdditionCoefficientsVar

{ #[doc(hidden)] pub struct G2ProjectiveExtendedVar { - pub x: Fp2Var, - pub y: Fp2Var, - pub z: Fp2Var, - pub t: Fp2Var, + pub x: Fp2Var, + pub y: Fp2Var, + pub z: Fp2Var, + pub t: Fp2Var, } diff --git a/src/groups/curves/short_weierstrass/mnt6/mod.rs b/src/groups/curves/short_weierstrass/mnt6/mod.rs index 8234230..50a0c86 100644 --- a/src/groups/curves/short_weierstrass/mnt6/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt6/mod.rs @@ -31,9 +31,9 @@ pub struct G1PreparedVar { #[doc(hidden)] pub y: FpVar, #[doc(hidden)] - pub x_twist: Fp3Var, + pub x_twist: Fp3Var, #[doc(hidden)] - pub y_twist: Fp3Var, + pub y_twist: Fp3Var, } impl G1PreparedVar

{ @@ -131,7 +131,7 @@ impl ToBytesGadget for G1PreparedVar

{ } } -type Fp3G

= Fp3Var<

::Fp3Params>; +type Fp3G

= Fp3Var<

::Fp3Config>; /// Represents the cached precomputation that can be performed on a G2 element /// which enables speeding up pairing computation. @@ -139,13 +139,13 @@ type Fp3G

= Fp3Var<

::Fp3Params>; #[derivative(Clone(bound = "P: MNT6Parameters"), Debug(bound = "P: MNT6Parameters"))] pub struct G2PreparedVar { #[doc(hidden)] - pub x: Fp3Var, + pub x: Fp3Var, #[doc(hidden)] - pub y: Fp3Var, + pub y: Fp3Var, #[doc(hidden)] - pub x_over_twist: Fp3Var, + pub x_over_twist: Fp3Var, #[doc(hidden)] - pub y_over_twist: Fp3Var, + pub y_over_twist: Fp3Var, #[doc(hidden)] pub double_coefficients: Vec>, #[doc(hidden)] @@ -344,10 +344,10 @@ impl G2PreparedVar

{ #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT6Parameters"), Debug(bound = "P: MNT6Parameters"))] pub struct AteDoubleCoefficientsVar { - pub c_h: Fp3Var, - pub c_4c: Fp3Var, - pub c_j: Fp3Var, - pub c_l: Fp3Var, + pub c_h: Fp3Var, + pub c_4c: Fp3Var, + pub c_j: Fp3Var, + pub c_l: Fp3Var, } impl AllocVar, P::Fp> for AteDoubleCoefficientsVar

{ @@ -427,8 +427,8 @@ impl AteDoubleCoefficientsVar

{ #[derive(Derivative)] #[derivative(Clone(bound = "P: MNT6Parameters"), Debug(bound = "P: MNT6Parameters"))] pub struct AteAdditionCoefficientsVar { - pub c_l1: Fp3Var, - pub c_rz: Fp3Var, + pub c_l1: Fp3Var, + pub c_rz: Fp3Var, } impl AllocVar, P::Fp> @@ -487,8 +487,8 @@ impl AteAdditionCoefficientsVar

{ #[doc(hidden)] pub struct G2ProjectiveExtendedVar { - pub x: Fp3Var, - pub y: Fp3Var, - pub z: Fp3Var, - pub t: Fp3Var, + pub x: Fp3Var, + pub y: Fp3Var, + pub z: Fp3Var, + pub t: Fp3Var, } diff --git a/src/groups/curves/short_weierstrass/mod.rs b/src/groups/curves/short_weierstrass/mod.rs index cf023c4..9e57b62 100644 --- a/src/groups/curves/short_weierstrass/mod.rs +++ b/src/groups/curves/short_weierstrass/mod.rs @@ -209,7 +209,7 @@ where } else { (Ok(ge.x), Ok(ge.y), Ok(P::BaseField::one())) } - } + }, _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -276,7 +276,7 @@ where multiple_of_power_of_two: &mut NonZeroAffineVar, bits: &[&Boolean<::BasePrimeField>], ) -> Result<(), SynthesisError> { - let scalar_modulus_bits = ::size_in_bits(); + let scalar_modulus_bits = ::MODULUS_BIT_SIZE as usize; assert!(scalar_modulus_bits >= bits.len()); let split_len = ark_std::cmp::min(scalar_modulus_bits - 2, bits.len()); @@ -418,7 +418,7 @@ where #[tracing::instrument(target = "r1cs")] fn enforce_prime_order(&self) -> Result<(), SynthesisError> { unimplemented!("cannot enforce prime order"); - // let r_minus_1 = (-P::ScalarField::one()).into_repr(); + // let r_minus_1 = (-P::ScalarField::one()).into_bigint(); // let mut result = Self::zero(); // for b in BitIteratorBE::without_leading_zeros(r_minus_1) { @@ -513,11 +513,11 @@ where // little-endian. bits.reverse(); - let scalar_modulus_bits = ::size_in_bits(); + let scalar_modulus_bits = ::MODULUS_BIT_SIZE; let mut mul_result = Self::zero(); let mut power_of_two_times_self = non_zero_self; // We chunk up `bits` into `p`-sized chunks. - for bits in bits.chunks(scalar_modulus_bits) { + for bits in bits.chunks(scalar_modulus_bits as usize) { self.fixed_scalar_mul_le(&mut mul_result, &mut power_of_two_times_self, bits)?; } @@ -803,7 +803,7 @@ where let cofactor_weight = BitIteratorBE::new(cofactor.as_slice()) .filter(|b| *b) .count(); - let modulus_minus_1 = (-P::ScalarField::one()).into_repr(); // r - 1 + let modulus_minus_1 = (-P::ScalarField::one()).into_bigint(); // r - 1 let modulus_minus_1_weight = BitIteratorBE::new(modulus_minus_1).filter(|b| *b).count(); @@ -831,9 +831,9 @@ where || { f().map(|g| { let g = g.into_affine(); - let mut power_of_two = P::ScalarField::one().into_repr(); + let mut power_of_two = P::ScalarField::one().into_bigint(); power_of_two.muln(power_of_2); - let power_of_two_inv = P::ScalarField::from_repr(power_of_two) + let power_of_two_inv = P::ScalarField::from_bigint(power_of_two) .and_then(|n| n.inverse()) .unwrap(); g.mul(power_of_two_inv) @@ -866,7 +866,7 @@ where ge.enforce_equal(&ge)?; Ok(ge) } - } + }, } } } diff --git a/src/groups/curves/twisted_edwards/mod.rs b/src/groups/curves/twisted_edwards/mod.rs index aed8f82..ae6f402 100644 --- a/src/groups/curves/twisted_edwards/mod.rs +++ b/src/groups/curves/twisted_edwards/mod.rs @@ -276,7 +276,7 @@ where Ok(ge) => { let ge: TEAffine

= ge.into(); (Ok(ge.x), Ok(ge.y)) - } + }, _ => ( Err(SynthesisError::AssignmentMissing), Err(SynthesisError::AssignmentMissing), @@ -458,7 +458,7 @@ where /// is unchanged. #[tracing::instrument(target = "r1cs")] fn enforce_prime_order(&self) -> Result<(), SynthesisError> { - let r_minus_1 = (-P::ScalarField::one()).into_repr(); + let r_minus_1 = (-P::ScalarField::one()).into_bigint(); let mut result = Self::zero(); for b in BitIteratorBE::without_leading_zeros(r_minus_1) { @@ -592,7 +592,7 @@ where let cofactor_weight = BitIteratorBE::new(cofactor.as_slice()) .filter(|b| *b) .count(); - let modulus_minus_1 = (-P::ScalarField::one()).into_repr(); // r - 1 + let modulus_minus_1 = (-P::ScalarField::one()).into_bigint(); // r - 1 let modulus_minus_1_weight = BitIteratorBE::new(modulus_minus_1).filter(|b| *b).count(); @@ -620,9 +620,9 @@ where || { f().map(|g| { let g = g.into_affine(); - let mut power_of_two = P::ScalarField::one().into_repr(); + let mut power_of_two = P::ScalarField::one().into_bigint(); power_of_two.muln(power_of_2); - let power_of_two_inv = P::ScalarField::from_repr(power_of_two) + let power_of_two_inv = P::ScalarField::from_bigint(power_of_two) .and_then(|n| n.inverse()) .unwrap(); g.mul(power_of_two_inv) @@ -654,7 +654,7 @@ where ge.enforce_equal(&ge)?; Ok(ge) } - } + }, } } } diff --git a/src/pairing/bls12/mod.rs b/src/pairing/bls12/mod.rs index 33454c4..3b7ed9a 100644 --- a/src/pairing/bls12/mod.rs +++ b/src/pairing/bls12/mod.rs @@ -13,13 +13,13 @@ use core::marker::PhantomData; /// Specifies the constraints for computing a pairing in a BLS12 bilinear group. pub struct PairingVar(PhantomData

); -type Fp2V

= Fp2Var<

::Fp2Params>; +type Fp2V

= Fp2Var<

::Fp2Config>; impl PairingVar

{ // Evaluate the line function at point p. #[tracing::instrument(target = "r1cs")] fn ell( - f: &mut Fp12Var, + f: &mut Fp12Var, coeffs: &(Fp2V

, Fp2V

), p: &G1AffineVar

, ) -> Result<(), SynthesisError> { @@ -35,7 +35,7 @@ impl PairingVar

{ c1.c1 *= &p.x; *f = f.mul_by_014(&c0, &c1, &c2)?; Ok(()) - } + }, TwistType::D => { let c0 = Fp2V::

::new(p.y.clone(), zero); let mut c1 = coeffs.0.clone(); @@ -45,12 +45,12 @@ impl PairingVar

{ c1.c1 *= &p.x; *f = f.mul_by_034(&c0, &c1, &c2)?; Ok(()) - } + }, } } #[tracing::instrument(target = "r1cs")] - fn exp_by_x(f: &Fp12Var) -> Result, SynthesisError> { + fn exp_by_x(f: &Fp12Var) -> Result, SynthesisError> { let mut result = f.optimized_cyclotomic_exp(P::X)?; if P::X_IS_NEGATIVE { result = result.unitary_inverse()?; @@ -64,7 +64,7 @@ impl PG, P::Fp> for PairingVar

{ type G2Var = G2Var

; type G1PreparedVar = G1PreparedVar

; type G2PreparedVar = G2PreparedVar

; - type GTVar = Fp12Var; + type GTVar = Fp12Var; #[tracing::instrument(target = "r1cs")] fn miller_loop( diff --git a/src/pairing/mnt4/mod.rs b/src/pairing/mnt4/mod.rs index 0ddbec5..1a2f506 100644 --- a/src/pairing/mnt4/mod.rs +++ b/src/pairing/mnt4/mod.rs @@ -17,8 +17,8 @@ use core::marker::PhantomData; /// Specifies the constraints for computing a pairing in a MNT4 bilinear group. pub struct PairingVar(PhantomData

); -type Fp2G

= Fp2Var<

::Fp2Params>; -type Fp4G

= Fp4Var<

::Fp4Params>; +type Fp2G

= Fp2Var<

::Fp2Config>; +type Fp4G

= Fp4Var<

::Fp4Config>; /// A variable corresponding to `ark_ec::mnt4::GT`. pub type GTVar

= Fp4G

; diff --git a/src/pairing/mnt6/mod.rs b/src/pairing/mnt6/mod.rs index bb849b2..fa56a91 100644 --- a/src/pairing/mnt6/mod.rs +++ b/src/pairing/mnt6/mod.rs @@ -16,8 +16,8 @@ use core::marker::PhantomData; /// Specifies the constraints for computing a pairing in a MNT6 bilinear group. pub struct PairingVar(PhantomData

); -type Fp3G

= Fp3Var<

::Fp3Params>; -type Fp6G

= Fp6Var<

::Fp6Params>; +type Fp3G

= Fp3Var<

::Fp3Config>; +type Fp6G

= Fp6Var<

::Fp6Config>; /// A variable corresponding to `ark_ec::mnt6::GT`. pub type GTVar

= Fp6G

; diff --git a/src/poly/domain/mod.rs b/src/poly/domain/mod.rs index f5352d0..95071ea 100644 --- a/src/poly/domain/mod.rs +++ b/src/poly/domain/mod.rs @@ -129,7 +129,7 @@ mod tests { fn test_query_coset_template() { const COSET_DIM: u64 = 7; - const COSET_SIZE: usize = 1 << COSET_DIM; + const COSET_SIZE: u64 = 1 << COSET_DIM; const LOCALIZATION: u64 = 3; let cs = ConstraintSystem::new_ref(); let mut rng = test_rng(); diff --git a/src/poly/evaluations/univariate/lagrange_interpolator.rs b/src/poly/evaluations/univariate/lagrange_interpolator.rs index 7663ef3..40417f6 100644 --- a/src/poly/evaluations/univariate/lagrange_interpolator.rs +++ b/src/poly/evaluations/univariate/lagrange_interpolator.rs @@ -118,7 +118,7 @@ mod tests { let domain = Radix2DomainVar::new( gen, 4, // 2^4 = 16 - FpVar::constant(Fr::multiplicative_generator()), + FpVar::constant(Fr::GENERATOR), ) .unwrap(); // generate evaluations of `poly` on this domain diff --git a/src/poly/evaluations/univariate/mod.rs b/src/poly/evaluations/univariate/mod.rs index 003648c..83a2515 100644 --- a/src/poly/evaluations/univariate/mod.rs +++ b/src/poly/evaluations/univariate/mod.rs @@ -452,7 +452,7 @@ mod tests { let domain = Radix2DomainVar::new( gen, 4, // 2^4 = 16 - FpVar::constant(Fr::multiplicative_generator()), + FpVar::constant(Fr::GENERATOR), ) .unwrap(); let cs = ConstraintSystem::new_ref(); diff --git a/tests/arithmetic_tests.rs b/tests/arithmetic_tests.rs index 9fa75ad..1155503 100644 --- a/tests/arithmetic_tests.rs +++ b/tests/arithmetic_tests.rs @@ -47,8 +47,8 @@ fn allocation_test( .unwrap(); let a_bits_actual: Vec = a_bits.into_iter().map(|b| b.value().unwrap()).collect(); - let mut a_bits_expected = a_native.into_repr().to_bits_le(); - a_bits_expected.truncate(TargetField::size_in_bits()); + let mut a_bits_expected = a_native.into_bigint().to_bits_le(); + a_bits_expected.truncate(TargetField::MODULUS_BIT_SIZE as usize); assert_eq!( a_bits_actual, a_bits_expected, "allocated bits does not equal the expected bits" @@ -107,8 +107,8 @@ fn multiplication_test( assert!( a_plus_zero_native.eq(&a_native), "a_plus_zero = {:?}, a = {:?}", - a_plus_zero_native.into_repr().as_ref(), - a_native.into_repr().as_ref() + a_plus_zero_native.into_bigint().as_ref(), + a_native.into_bigint().as_ref() ); assert!( a_minus_zero_native.eq(&a_native), "a_minus_zero = {:?}, a = {:?}", - a_minus_zero_native.into_repr().as_ref(), - a_native.into_repr().as_ref() + a_minus_zero_native.into_bigint().as_ref(), + a_native.into_bigint().as_ref() ); assert!( zero_minus_a_native.eq(&minus_a_native), "zero_minus_a = {:?}, minus_a = {:?}", - zero_minus_a_native.into_repr().as_ref(), - minus_a_native.into_repr().as_ref() + zero_minus_a_native.into_bigint().as_ref(), + minus_a_native.into_bigint().as_ref() ); assert!( a_times_zero_native.eq(&zero_native), "a_times_zero = {:?}, zero = {:?}", - a_times_zero_native.into_repr().as_ref(), - zero_native.into_repr().as_ref() + a_times_zero_native.into_bigint().as_ref(), + zero_native.into_bigint().as_ref() ); assert!( zero_plus_a_native.eq(&a_native), "zero_plus_a = {:?}, a = {:?}", - zero_plus_a_native.into_repr().as_ref(), - a_native.into_repr().as_ref() + zero_plus_a_native.into_bigint().as_ref(), + a_native.into_bigint().as_ref() ); assert!( zero_times_a_native.eq(&zero_native), "zero_times_a = {:?}, zero = {:?}", - zero_times_a_native.into_repr().as_ref(), - zero_native.into_repr().as_ref() + zero_times_a_native.into_bigint().as_ref(), + zero_native.into_bigint().as_ref() ); assert!( a_times_one_native.eq(&a_native), "a_times_one = {:?}, a = {:?}", - a_times_one_native.into_repr().as_ref(), - a_native.into_repr().as_ref() + a_times_one_native.into_bigint().as_ref(), + a_native.into_bigint().as_ref() ); assert!( one_times_a_native.eq(&a_native), "one_times_a = {:?}, a = {:?}", - one_times_a_native.into_repr().as_ref(), - a_native.into_repr().as_ref() + one_times_a_native.into_bigint().as_ref(), + a_native.into_bigint().as_ref() ); } @@ -327,15 +327,15 @@ fn randomized_arithmetic_test { num_native += &next_native; num += &next; - } + }, 1 => { num_native *= &next_native; num *= &next; - } + }, 2 => { num_native -= &next_native; num -= &next; - } + }, _ => (), }; @@ -465,7 +465,7 @@ fn double_stress_test_1