From 86ba793d18429f0b65f55c65c6fd14702abb5bb7 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Thu, 28 Nov 2024 17:02:37 -0500 Subject: [PATCH 01/11] Refacto: R1CS to GR1CS --- Cargo.toml | 45 +++---- benches/bench.rs | 20 ++- src/alloc.rs | 8 +- src/boolean/allocated.rs | 30 ++--- src/boolean/and.rs | 36 +++--- src/boolean/cmp.rs | 4 +- src/boolean/convert.rs | 4 +- src/boolean/eq.rs | 14 +- src/boolean/mod.rs | 14 +- src/boolean/not.rs | 14 +- src/boolean/or.rs | 26 ++-- src/boolean/select.rs | 12 +- src/boolean/test_utils.rs | 2 +- src/boolean/xor.rs | 20 +-- src/cmp.rs | 6 +- src/convert.rs | 4 +- src/eq.rs | 40 +++--- src/fields/cubic_extension.rs | 38 +++--- src/fields/emulated_fp/allocated_field_var.rs | 32 ++--- .../emulated_fp/allocated_mul_result.rs | 6 +- src/fields/emulated_fp/field_var.rs | 36 +++--- src/fields/emulated_fp/mod.rs | 2 +- src/fields/emulated_fp/mul_result.rs | 4 +- src/fields/emulated_fp/reduce.rs | 16 +-- src/fields/fp/cmp.rs | 16 +-- src/fields/fp/mod.rs | 122 +++++++++--------- src/fields/fp12.rs | 2 +- src/fields/fp6_3over2.rs | 2 +- src/fields/mod.rs | 4 +- src/fields/quadratic_extension.rs | 38 +++--- src/{r1cs_var.rs => gr1cs_var.rs} | 14 +- .../curves/short_weierstrass/bls12/mod.rs | 18 +-- .../curves/short_weierstrass/mnt4/mod.rs | 30 ++--- .../curves/short_weierstrass/mnt6/mod.rs | 30 ++--- src/groups/curves/short_weierstrass/mod.rs | 42 +++--- .../short_weierstrass/non_zero_affine.rs | 26 ++-- src/groups/curves/twisted_edwards/mod.rs | 48 +++---- src/groups/mod.rs | 14 +- src/lib.rs | 12 +- src/macros.rs | 30 ++--- src/pairing/bls12/mod.rs | 14 +- src/pairing/mnt4/mod.rs | 22 ++-- src/pairing/mnt6/mod.rs | 22 ++-- src/pairing/mod.rs | 6 +- src/poly/domain/mod.rs | 6 +- src/poly/domain/vanishing_poly.rs | 6 +- .../univariate/lagrange_interpolator.rs | 2 +- src/poly/evaluations/univariate/mod.rs | 8 +- src/poly/polynomial/univariate/dense.rs | 6 +- src/select.rs | 2 +- src/uint/add/mod.rs | 2 +- src/uint/add/saturating.rs | 8 +- src/uint/add/wrapping.rs | 8 +- src/uint/and.rs | 52 ++++---- src/uint/cmp.rs | 2 +- src/uint/convert.rs | 18 +-- src/uint/eq.rs | 10 +- src/uint/mod.rs | 12 +- src/uint/not.rs | 16 +-- src/uint/or.rs | 36 +++--- src/uint/rotate.rs | 24 ++-- src/uint/select.rs | 2 +- src/uint/shl.rs | 18 +-- src/uint/shr.rs | 18 +-- src/uint/test_utils.rs | 2 +- src/uint/xor.rs | 36 +++--- src/uint8.rs | 12 +- tests/arithmetic_tests.rs | 4 +- tests/from_test.rs | 4 +- tests/to_constraint_field_test.rs | 4 +- 70 files changed, 630 insertions(+), 633 deletions(-) rename src/{r1cs_var.rs => gr1cs_var.rs} (83%) diff --git a/Cargo.toml b/Cargo.toml index 7afc7d0e..3be3b013 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ark-r1cs-std" -version = "0.4.0" +version = "0.5.0" authors = [ "arkworks contributors" ] description = "A standard library for constraint system gadgets" homepage = "https://arkworks.rs" @@ -14,10 +14,10 @@ edition = "2021" resolver = "2" [dependencies] -ark-ff = { version = "0.4.0", default-features = false } -ark-ec = { version = "0.4.0", default-features = false } -ark-std = { version = "0.4.0", default-features = false } -ark-relations = { version = "0.4.0", default-features = false } +ark-ff = { version = "0.5.0", default-features = false } +ark-ec = { version = "0.5.0", default-features = false } +ark-std = { version = "0.5.0", default-features = false } +ark-relations = { path = "../snark/relations", default-features = true } educe = "0.6.0" tracing = { version = "0.1", default-features = false, features = [ "attributes" ] } @@ -26,17 +26,17 @@ num-traits = { version = "0.2", default-features = false } num-integer = { version = "0.1.44", default-features = false } [dev-dependencies] -ark-test-curves = { version = "0.4.0", default-features = false, features = ["bls12_381_scalar_field", "bls12_381_curve", "mnt4_753_scalar_field"] } -ark-poly = { version = "0.4.0", default-features = false } +ark-test-curves = { version = "0.5.0", default-features = false, features = ["bls12_381_scalar_field", "bls12_381_curve", "mnt4_753_scalar_field"] } +ark-poly = { version = "0.5.0", default-features = false } paste = "1.0" -ark-bls12-377 = { version = "0.4.0", features = ["curve"], default-features = false } -ark-bls12-381 = { version = "0.4.0", features = ["curve"], default-features = false } -ark-mnt4-298 = { version = "0.4.0", features = ["curve"], default-features = false } -ark-mnt4-753 = { version = "0.4.0", features = ["curve"], default-features = false } -ark-mnt6-298 = { version = "0.4.0", default-features = false } -ark-mnt6-753 = { version = "0.4.0", default-features = false } -ark-pallas = { version = "0.4.0", features = ["curve"], default-features = false } -ark-bn254 = { version = "0.4.0", features = ["curve"], default-features = false } +ark-bls12-377 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-bls12-381 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-mnt4-298 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-mnt4-753 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-mnt6-298 = { version = "0.5.0", default-features = false } +ark-mnt6-753 = { version = "0.5.0", default-features = false } +ark-pallas = { version = "0.5.0", features = ["curve"], default-features = false } +ark-bn254 = { version = "0.5.0", features = ["curve"], default-features = false } [features] default = ["std"] @@ -76,18 +76,3 @@ debug = true [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } -[patch.crates-io] -ark-ff = { git = "https://github.com/arkworks-rs/algebra/" } -ark-ec = { 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-bn254 = { git = "https://github.com/arkworks-rs/curves/" } -ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves/" } -ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves/" } -ark-mnt4-298 = { git = "https://github.com/arkworks-rs/curves/" } -ark-mnt4-753 = { git = "https://github.com/arkworks-rs/curves/" } -ark-mnt6-298 = { git = "https://github.com/arkworks-rs/curves/" } -ark-mnt6-753 = { git = "https://github.com/arkworks-rs/curves/" } -ark-pallas = { git = "https://github.com/arkworks-rs/curves/" } -ark-std = { git = "https://github.com/arkworks-rs/std/" } \ No newline at end of file diff --git a/benches/bench.rs b/benches/bench.rs index d9fff676..62d538e0 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -6,7 +6,8 @@ use ark_r1cs_std::{ }; use ark_relations::{ ns, - r1cs::{ConstraintSystem, ConstraintSystemRef, OptimizationGoal}, + gr1cs::{ConstraintSystem, ConstraintSystemRef, OptimizationGoal}, + }; use ark_std::rand::RngCore; @@ -19,9 +20,20 @@ fn get_density(cs: &ConstraintSystemRef) -> us let mut cs_bak = r.borrow().clone(); cs_bak.finalize(); - let matrices = cs_bak.to_matrices().unwrap(); - - matrices.a_num_non_zero + matrices.b_num_non_zero + matrices.c_num_non_zero + let matrices_map = cs_bak.to_matrices().unwrap(); + match matrices_map.get(ark_relations::gr1cs::R1CS_PREDICATE_LABEL) { + None => 0, + Some(matrices) => { + let a = &matrices[0]; + let b = &matrices[1]; + let c = &matrices[2]; + let a_num_non_zero: usize = a.iter().map(|lc| lc.len()).sum(); + let b_num_non_zero: usize = b.iter().map(|lc| lc.len()).sum(); + let c_num_non_zero: usize = c.iter().map(|lc| lc.len()).sum(); + + a_num_non_zero + b_num_non_zero + c_num_non_zero + }, + } }, } } diff --git a/src/alloc.rs b/src/alloc.rs index ccce47f5..a3b3ad45 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -1,6 +1,6 @@ use crate::Vec; use ark_ff::Field; -use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_relations::gr1cs::{Namespace, SynthesisError}; use core::borrow::Borrow; /// Describes the mode that a variable should be allocated in within @@ -49,7 +49,7 @@ pub trait AllocVar: Sized { /// Allocates a new constant of type `Self` in the `ConstraintSystem` `cs`. /// /// This should *not* allocate any new variables or constraints in `cs`. - #[tracing::instrument(target = "r1cs", skip(cs, t))] + #[tracing::instrument(target = "gr1cs", skip(cs, t))] fn new_constant( cs: impl Into>, t: impl Borrow, @@ -59,7 +59,7 @@ pub trait AllocVar: Sized { /// Allocates a new public input of type `Self` in the `ConstraintSystem` /// `cs`. - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_input>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -69,7 +69,7 @@ pub trait AllocVar: Sized { /// Allocates a new private witness of type `Self` in the `ConstraintSystem` /// `cs`. - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_witness>( cs: impl Into>, f: impl FnOnce() -> Result, diff --git a/src/boolean/allocated.rs b/src/boolean/allocated.rs index 9397f12d..a3447979 100644 --- a/src/boolean/allocated.rs +++ b/src/boolean/allocated.rs @@ -1,7 +1,7 @@ use core::borrow::Borrow; use ark_ff::{Field, PrimeField}; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError, Variable}; +use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError, Variable}; use crate::{ alloc::{AllocVar, AllocationMode}, @@ -58,7 +58,7 @@ impl AllocatedBool { /// Performs an XOR operation over the two operands, returning /// an `AllocatedBool`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn not(&self) -> Result { let variable = self.cs.new_lc(lc!() + Variable::One - self.variable)?; Ok(Self { @@ -69,7 +69,7 @@ impl AllocatedBool { /// Performs an XOR operation over the two operands, returning /// an `AllocatedBool`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn xor(&self, b: &Self) -> Result { let result = Self::new_witness_without_booleanity_check(self.cs.clone(), || { Ok(self.value()? ^ b.value()?) @@ -90,7 +90,7 @@ impl AllocatedBool { // -2a * b = c - a - b // 2a * b = a + b - c // (a + a) * b = a + b - c - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable + self.variable, lc!() + b.variable, lc!() + self.variable + b.variable - result.variable, @@ -101,7 +101,7 @@ impl AllocatedBool { /// Performs an AND operation over the two operands, returning /// an `AllocatedBool`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn and(&self, b: &Self) -> Result { let result = Self::new_witness_without_booleanity_check(self.cs.clone(), || { Ok(self.value()? & b.value()?) @@ -109,7 +109,7 @@ impl AllocatedBool { // Constrain (a) * (b) = (c), ensuring c is 1 iff // a AND b are both 1. - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable, lc!() + b.variable, lc!() + result.variable, @@ -120,7 +120,7 @@ impl AllocatedBool { /// Performs an OR operation over the two operands, returning /// an `AllocatedBool`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn or(&self, b: &Self) -> Result { let result = Self::new_witness_without_booleanity_check(self.cs.clone(), || { Ok(self.value()? | b.value()?) @@ -128,7 +128,7 @@ impl AllocatedBool { // Constrain (1 - a) * (1 - b) = (1 - c), ensuring c is 0 iff // a and b are both false, and otherwise c is 1. - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + Variable::One - self.variable, lc!() + Variable::One - b.variable, lc!() + Variable::One - result.variable, @@ -138,7 +138,7 @@ impl AllocatedBool { } /// Calculates `a AND (NOT b)`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn and_not(&self, b: &Self) -> Result { let result = Self::new_witness_without_booleanity_check(self.cs.clone(), || { Ok(self.value()? & !b.value()?) @@ -146,7 +146,7 @@ impl AllocatedBool { // Constrain (a) * (1 - b) = (c), ensuring c is 1 iff // a is true and b is false, and otherwise c is 0. - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable, lc!() + Variable::One - b.variable, lc!() + result.variable, @@ -156,7 +156,7 @@ impl AllocatedBool { } /// Calculates `(NOT a) AND (NOT b)`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn nor(&self, b: &Self) -> Result { let result = Self::new_witness_without_booleanity_check(self.cs.clone(), || { Ok(!(self.value()? | b.value()?)) @@ -164,7 +164,7 @@ impl AllocatedBool { // Constrain (1 - a) * (1 - b) = (c), ensuring c is 1 iff // a and b are both false, and otherwise c is 0. - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + Variable::One - self.variable, lc!() + Variable::One - b.variable, lc!() + result.variable, @@ -205,7 +205,7 @@ impl AllocVar for AllocatedBool { // Constrain: (1 - a) * a = 0 // This constrains a to be either 0 or 1. - cs.enforce_constraint(lc!() + Variable::One - variable, lc!() + variable, lc!())?; + cs.enforce_r1cs_constraint(lc!() + Variable::One - variable, lc!() + variable, lc!())?; Ok(Self { variable, cs }) } @@ -213,7 +213,7 @@ impl AllocVar for AllocatedBool { } impl CondSelectGadget for AllocatedBool { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean, true_val: &Self, @@ -235,7 +235,7 @@ impl CondSelectGadget for AllocatedBool { mod test { use super::*; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_test_curves::bls12_381::Fr; #[test] fn allocated_xor() -> Result<(), SynthesisError> { diff --git a/src/boolean/and.rs b/src/boolean/and.rs index 20251f3f..0547b585 100644 --- a/src/boolean/and.rs +++ b/src/boolean/and.rs @@ -1,5 +1,5 @@ use ark_ff::{Field, PrimeField}; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::BitAnd, ops::BitAndAssign}; use crate::{fields::fp::FpVar, prelude::EqGadget}; @@ -28,10 +28,10 @@ impl Boolean { /// Outputs `bits[0] & bits[1] & ... & bits.last().unwrap()`. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -47,7 +47,7 @@ impl Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn kary_and(bits: &[Self]) -> Result { assert!(!bits.is_empty()); if bits.len() <= 3 { @@ -72,10 +72,10 @@ impl Boolean { /// Outputs `!(bits[0] & bits[1] & ... & bits.last().unwrap())`. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -92,7 +92,7 @@ impl Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn kary_nand(bits: &[Self]) -> Result { Ok(!Self::kary_and(bits)?) } @@ -101,7 +101,7 @@ impl Boolean { /// /// Informally, this means that at least one element in `bits` must be /// `false`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn enforce_kary_nand(bits: &[Self]) -> Result<(), SynthesisError> { Self::kary_and(bits)?.enforce_equal(&Boolean::FALSE) } @@ -115,10 +115,10 @@ impl<'a, F: Field> BitAnd for &'a Boolean { /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -136,7 +136,7 @@ impl<'a, F: Field> BitAnd for &'a Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: Self) -> Self::Output { self._and(other).unwrap() } @@ -145,7 +145,7 @@ impl<'a, F: Field> BitAnd for &'a Boolean { impl<'a, F: Field> BitAnd<&'a Self> for Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: &Self) -> Self::Output { self._and(&other).unwrap() } @@ -154,7 +154,7 @@ impl<'a, F: Field> BitAnd<&'a Self> for Boolean { impl<'a, F: Field> BitAnd> for &'a Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: Boolean) -> Self::Output { self._and(&other).unwrap() } @@ -163,7 +163,7 @@ impl<'a, F: Field> BitAnd> for &'a Boolean { impl BitAnd for Boolean { type Output = Self; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: Self) -> Self::Output { self._and(&other).unwrap() } @@ -171,7 +171,7 @@ impl BitAnd for Boolean { impl BitAndAssign for Boolean { /// Sets `self = self & other`. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand_assign(&mut self, other: Self) { let result = self._and(&other).unwrap(); *self = result; @@ -180,7 +180,7 @@ impl BitAndAssign for Boolean { impl<'a, F: Field> BitAndAssign<&'a Self> for Boolean { /// Sets `self = self & other`. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand_assign(&mut self, other: &'a Self) { let result = self._and(other).unwrap(); *self = result; @@ -194,9 +194,9 @@ mod tests { alloc::{AllocVar, AllocationMode}, boolean::test_utils::run_binary_exhaustive, prelude::EqGadget, - R1CSVar, + GR1CSVar, }; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_test_curves::bls12_381::Fr; #[test] diff --git a/src/boolean/cmp.rs b/src/boolean/cmp.rs index 744279a0..1fe22072 100644 --- a/src/boolean/cmp.rs +++ b/src/boolean/cmp.rs @@ -20,7 +20,7 @@ impl Boolean { /// `F::characteristic()`, That is, interpret bits as a little-endian /// integer, and enforce that this integer is "in the field Z_p", where /// `p = F::characteristic()` . - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn enforce_in_field_le(bits: &[Self]) -> Result<(), SynthesisError> { // `bits` < F::characteristic() <==> `bits` <= F::characteristic() -1 let mut b = F::characteristic().to_vec(); @@ -38,7 +38,7 @@ impl Boolean { /// Enforces that `bits` is less than or equal to `element`, /// when both are interpreted as (little-endian) integers. - #[tracing::instrument(target = "r1cs", skip(element))] + #[tracing::instrument(target = "gr1cs", skip(element))] pub fn enforce_smaller_or_equal_than_le( bits: &[Self], element: impl AsRef<[u64]>, diff --git a/src/boolean/convert.rs b/src/boolean/convert.rs index d4ce1518..cd351f9b 100644 --- a/src/boolean/convert.rs +++ b/src/boolean/convert.rs @@ -3,7 +3,7 @@ use crate::convert::{ToBytesGadget, ToConstraintFieldGadget}; impl ToBytesGadget for Boolean { /// Outputs `1u8` if `self` is true, and `0u8` otherwise. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let value = self.value().map(u8::from).ok(); let mut bits = [Boolean::FALSE; 8]; @@ -13,7 +13,7 @@ impl ToBytesGadget for Boolean { } impl ToConstraintFieldGadget for Boolean { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { let var = From::from(self.clone()); Ok(vec![var]) diff --git a/src/boolean/eq.rs b/src/boolean/eq.rs index 43bc7da2..33609ff0 100644 --- a/src/boolean/eq.rs +++ b/src/boolean/eq.rs @@ -1,4 +1,4 @@ -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use crate::boolean::Boolean; use crate::eq::EqGadget; @@ -6,7 +6,7 @@ use crate::eq::EqGadget; use super::*; impl EqGadget for Boolean { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { // self | other | XNOR(self, other) | self == other // -----|-------|-------------------|-------------- @@ -17,7 +17,7 @@ impl EqGadget for Boolean { Ok(!(self ^ other)) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_equal( &self, other: &Self, @@ -43,12 +43,12 @@ impl EqGadget for Boolean { if condition != &Constant(false) { let cs = self.cs().or(other.cs()).or(condition.cs()); - cs.enforce_constraint(lc!() + difference, condition.lc(), lc!())?; + cs.enforce_r1cs_constraint(lc!() + difference, condition.lc(), lc!())?; } Ok(()) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_not_equal( &self, other: &Self, @@ -74,7 +74,7 @@ impl EqGadget for Boolean { if should_enforce != &Constant(false) { let cs = self.cs().or(other.cs()).or(should_enforce.cs()); - cs.enforce_constraint(sum, should_enforce.lc(), lc!() + one)?; + cs.enforce_r1cs_constraint(sum, should_enforce.lc(), lc!() + one)?; } Ok(()) } @@ -87,7 +87,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, boolean::test_utils::{run_binary_exhaustive, run_unary_exhaustive}, prelude::EqGadget, - R1CSVar, + GR1CSVar, }; use ark_test_curves::bls12_381::Fr; diff --git a/src/boolean/mod.rs b/src/boolean/mod.rs index e4fab85c..a8f9aa77 100644 --- a/src/boolean/mod.rs +++ b/src/boolean/mod.rs @@ -1,7 +1,7 @@ use ark_ff::{BitIteratorBE, Field, PrimeField}; use crate::{fields::fp::FpVar, prelude::*, Vec}; -use ark_relations::r1cs::{ +use ark_relations::gr1cs::{ ConstraintSystemRef, LinearCombination, Namespace, SynthesisError, Variable, }; use core::borrow::Borrow; @@ -30,7 +30,7 @@ pub enum Boolean { Constant(bool), } -impl R1CSVar for Boolean { +impl GR1CSVar for Boolean { type Value = bool; fn cs(&self) -> ConstraintSystemRef { @@ -61,10 +61,10 @@ impl Boolean { /// This *does not* create any new variables or constraints. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -92,7 +92,7 @@ impl Boolean { /// /// This *does not* create any new variables or constraints. /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; /// use ark_r1cs_std::prelude::*; @@ -127,7 +127,7 @@ impl Boolean { /// `FpVar` /// /// Wraps around if the bit representation is larger than the field modulus. - #[tracing::instrument(target = "r1cs", skip(bits))] + #[tracing::instrument(target = "gr1cs", skip(bits))] pub fn le_bits_to_fp(bits: &[Self]) -> Result, SynthesisError> where F: PrimeField, @@ -207,7 +207,7 @@ mod test { use ark_ff::{ AdditiveGroup, BitIteratorBE, BitIteratorLE, Field, One, PrimeField, UniformRand, }; - use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; + use ark_relations::gr1cs::{ConstraintSystem, SynthesisError}; use ark_test_curves::bls12_381::Fr; #[test] diff --git a/src/boolean/not.rs b/src/boolean/not.rs index 2745526d..b5bb6f91 100644 --- a/src/boolean/not.rs +++ b/src/boolean/not.rs @@ -1,5 +1,5 @@ use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::ops::Not; use super::Boolean; @@ -26,10 +26,10 @@ impl<'a, F: Field> Not for &'a Boolean { /// /// This *does not* create any new variables or constraints. /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -47,7 +47,7 @@ impl<'a, F: Field> Not for &'a Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] fn not(self) -> Self::Output { self._not().unwrap() } @@ -56,7 +56,7 @@ impl<'a, F: Field> Not for &'a Boolean { impl<'a, F: Field> Not for &'a mut Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] fn not(self) -> Self::Output { self._not().unwrap() } @@ -65,7 +65,7 @@ impl<'a, F: Field> Not for &'a mut Boolean { impl Not for Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] fn not(self) -> Self::Output { self._not().unwrap() } @@ -78,7 +78,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, boolean::test_utils::run_unary_exhaustive, prelude::EqGadget, - R1CSVar, + GR1CSVar, }; use ark_test_curves::bls12_381::Fr; diff --git a/src/boolean/or.rs b/src/boolean/or.rs index 8f8b41c1..1d8ca48e 100644 --- a/src/boolean/or.rs +++ b/src/boolean/or.rs @@ -1,5 +1,5 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::BitOr, ops::BitOrAssign}; use crate::{ @@ -22,10 +22,10 @@ impl Boolean { /// Outputs `bits[0] | bits[1] | ... | bits.last().unwrap()`. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -42,7 +42,7 @@ impl Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn kary_or(bits: &[Self]) -> Result { assert!(!bits.is_empty()); if bits.len() <= 3 { @@ -74,10 +74,10 @@ impl<'a, F: PrimeField> BitOr for &'a Boolean { /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -95,7 +95,7 @@ impl<'a, F: PrimeField> BitOr for &'a Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: Self) -> Self::Output { self._or(other).unwrap() } @@ -104,7 +104,7 @@ impl<'a, F: PrimeField> BitOr for &'a Boolean { impl<'a, F: PrimeField> BitOr<&'a Self> for Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: &Self) -> Self::Output { self._or(&other).unwrap() } @@ -113,7 +113,7 @@ impl<'a, F: PrimeField> BitOr<&'a Self> for Boolean { impl<'a, F: PrimeField> BitOr> for &'a Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: Boolean) -> Self::Output { self._or(&other).unwrap() } @@ -122,7 +122,7 @@ impl<'a, F: PrimeField> BitOr> for &'a Boolean { impl BitOr for Boolean { type Output = Self; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: Self) -> Self::Output { self._or(&other).unwrap() } @@ -130,7 +130,7 @@ impl BitOr for Boolean { impl BitOrAssign for Boolean { /// Sets `self = self | other`. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor_assign(&mut self, other: Self) { let result = self._or(&other).unwrap(); *self = result; @@ -139,7 +139,7 @@ impl BitOrAssign for Boolean { impl<'a, F: PrimeField> BitOrAssign<&'a Self> for Boolean { /// Sets `self = self | other`. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor_assign(&mut self, other: &'a Self) { let result = self._or(other).unwrap(); *self = result; @@ -153,7 +153,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, boolean::test_utils::run_binary_exhaustive, prelude::EqGadget, - R1CSVar, + GR1CSVar, }; use ark_test_curves::bls12_381::Fr; diff --git a/src/boolean/select.rs b/src/boolean/select.rs index 78eb0448..ab5df7f1 100644 --- a/src/boolean/select.rs +++ b/src/boolean/select.rs @@ -7,10 +7,10 @@ impl Boolean { /// If `self.is_eq(&Boolean::TRUE)`, this outputs `first`; else, it outputs /// `second`. /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -27,7 +27,7 @@ impl Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(first, second))] + #[tracing::instrument(target = "gr1cs", skip(first, second))] pub fn select>( &self, first: &T, @@ -37,7 +37,7 @@ impl Boolean { } } impl CondSelectGadget for Boolean { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean, true_val: &Self, @@ -78,7 +78,7 @@ impl CondSelectGadget for Boolean { // 0 | 1 | 0 | 1 // 1 | 0 | 0 | 0 // 1 | 1 | 0 | 1 - cs.enforce_constraint( + cs.enforce_r1cs_constraint( cond.lc(), lc!() + a.lc() - b.lc(), lc!() + result.lc() - b.lc(), @@ -98,7 +98,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, boolean::test_utils::run_binary_exhaustive, prelude::EqGadget, - R1CSVar, + GR1CSVar, }; use ark_test_curves::bls12_381::Fr; diff --git a/src/boolean/test_utils.rs b/src/boolean/test_utils.rs index 9577e82d..b613081c 100644 --- a/src/boolean/test_utils.rs +++ b/src/boolean/test_utils.rs @@ -1,7 +1,7 @@ use crate::test_utils; use super::*; -use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystem, SynthesisError}; pub(crate) fn test_unary_op( a: bool, diff --git a/src/boolean/xor.rs b/src/boolean/xor.rs index 67e45b36..7d907678 100644 --- a/src/boolean/xor.rs +++ b/src/boolean/xor.rs @@ -1,5 +1,5 @@ use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::BitXor, ops::BitXorAssign}; use super::Boolean; @@ -24,10 +24,10 @@ impl<'a, F: Field> BitXor for &'a Boolean { /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -45,7 +45,7 @@ impl<'a, F: Field> BitXor for &'a Boolean { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: Self) -> Self::Output { self._xor(other).unwrap() } @@ -54,7 +54,7 @@ impl<'a, F: Field> BitXor for &'a Boolean { impl<'a, F: Field> BitXor<&'a Self> for Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: &Self) -> Self::Output { self._xor(&other).unwrap() } @@ -63,7 +63,7 @@ impl<'a, F: Field> BitXor<&'a Self> for Boolean { impl<'a, F: Field> BitXor> for &'a Boolean { type Output = Boolean; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: Boolean) -> Self::Output { self._xor(&other).unwrap() } @@ -72,7 +72,7 @@ impl<'a, F: Field> BitXor> for &'a Boolean { impl BitXor for Boolean { type Output = Self; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: Self) -> Self::Output { self._xor(&other).unwrap() } @@ -80,7 +80,7 @@ impl BitXor for Boolean { impl BitXorAssign for Boolean { /// Sets `self = self ^ other`. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor_assign(&mut self, other: Self) { let result = self._xor(&other).unwrap(); *self = result; @@ -89,7 +89,7 @@ impl BitXorAssign for Boolean { impl<'a, F: Field> BitXorAssign<&'a Self> for Boolean { /// Sets `self = self ^ other`. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor_assign(&mut self, other: &'a Self) { let result = self._xor(other).unwrap(); *self = result; @@ -103,7 +103,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, boolean::test_utils::run_binary_exhaustive, prelude::EqGadget, - R1CSVar, + GR1CSVar, }; use ark_test_curves::bls12_381::Fr; diff --git a/src/cmp.rs b/src/cmp.rs index ad29a97e..f2b8f2fc 100644 --- a/src/cmp.rs +++ b/src/cmp.rs @@ -1,10 +1,10 @@ use ark_ff::{Field, PrimeField}; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; -use crate::{boolean::Boolean, eq::EqGadget, R1CSVar}; +use crate::{boolean::Boolean, eq::EqGadget, GR1CSVar}; /// Specifies how to generate constraints for comparing two variables. -pub trait CmpGadget: R1CSVar + EqGadget { +pub trait CmpGadget: GR1CSVar + EqGadget { fn is_gt(&self, other: &Self) -> Result, SynthesisError> { other.is_lt(self) } diff --git a/src/convert.rs b/src/convert.rs index 41f87a3f..ef5fae12 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -1,5 +1,5 @@ use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::vec::Vec; use crate::{boolean::Boolean, uint8::UInt8}; @@ -150,5 +150,5 @@ pub trait ToConstraintFieldGadget { /// Converts `self` to `FpVar` variables. fn to_constraint_field( &self, - ) -> Result>, ark_relations::r1cs::SynthesisError>; + ) -> Result>, ark_relations::gr1cs::SynthesisError>; } diff --git a/src/eq.rs b/src/eq.rs index 1692edc9..9c36f478 100644 --- a/src/eq.rs +++ b/src/eq.rs @@ -1,6 +1,6 @@ use crate::{prelude::*, Vec}; use ark_ff::{Field, PrimeField}; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; /// Specifies how to generate constraints that check for equality for two /// variables of type `Self`. @@ -26,7 +26,7 @@ pub trait EqGadget { /// /// More efficient specialized implementation may be possible; implementors /// are encouraged to carefully analyze the efficiency and safety of these. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_equal( &self, other: &Self, @@ -44,7 +44,7 @@ pub trait EqGadget { /// /// More efficient specialized implementation may be possible; implementors /// are encouraged to carefully analyze the efficiency and safety of these. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError> { self.conditional_enforce_equal(other, &Boolean::TRUE) } @@ -58,7 +58,7 @@ pub trait EqGadget { /// /// More efficient specialized implementation may be possible; implementors /// are encouraged to carefully analyze the efficiency and safety of these. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_not_equal( &self, other: &Self, @@ -76,14 +76,14 @@ pub trait EqGadget { /// /// More efficient specialized implementation may be possible; implementors /// are encouraged to carefully analyze the efficiency and safety of these. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn enforce_not_equal(&self, other: &Self) -> Result<(), SynthesisError> { self.conditional_enforce_not_equal(other, &Boolean::TRUE) } } -impl + R1CSVar, F: PrimeField> EqGadget for [T] { - #[tracing::instrument(target = "r1cs", skip(self, other))] +impl + GR1CSVar, F: PrimeField> EqGadget for [T] { + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { assert_eq!(self.len(), other.len()); if self.is_empty() & other.is_empty() { @@ -97,7 +97,7 @@ impl + R1CSVar, F: PrimeField> EqGadget for [T] { } } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_equal( &self, other: &Self, @@ -110,7 +110,7 @@ impl + R1CSVar, F: PrimeField> EqGadget for [T] { Ok(()) } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_not_equal( &self, other: &Self, @@ -123,7 +123,7 @@ impl + R1CSVar, F: PrimeField> EqGadget for [T] { Ok(()) } else { let cs = [&some_are_different, should_enforce].cs(); - cs.enforce_constraint( + cs.enforce_r1cs_constraint( some_are_different.lc(), should_enforce.lc(), should_enforce.lc(), @@ -133,13 +133,13 @@ impl + R1CSVar, F: PrimeField> EqGadget for [T] { } /// This blanket implementation just forwards to the impl on [`[T]`]. -impl + R1CSVar, F: PrimeField> EqGadget for Vec { - #[tracing::instrument(target = "r1cs", skip(self, other))] +impl + GR1CSVar, F: PrimeField> EqGadget for Vec { + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { self.as_slice().is_eq(other.as_slice()) } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_equal( &self, other: &Self, @@ -149,7 +149,7 @@ impl + R1CSVar, F: PrimeField> EqGadget for Vec { .conditional_enforce_equal(other.as_slice(), condition) } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_not_equal( &self, other: &Self, @@ -173,7 +173,7 @@ impl EqGadget for () { /// else, enforce a vacuously true statement. /// /// This is a no-op as `self.is_eq(other)?` is always `true`. - #[tracing::instrument(target = "r1cs", skip(self, _other))] + #[tracing::instrument(target = "gr1cs", skip(self, _other))] fn conditional_enforce_equal( &self, _other: &Self, @@ -186,20 +186,20 @@ impl EqGadget for () { /// /// This does not generate any constraints as `self.is_eq(other)?` is always /// `true`. - #[tracing::instrument(target = "r1cs", skip(self, _other))] + #[tracing::instrument(target = "gr1cs", skip(self, _other))] fn enforce_equal(&self, _other: &Self) -> Result<(), SynthesisError> { Ok(()) } } /// This blanket implementation just forwards to the impl on [`[T]`]. -impl + R1CSVar, F: PrimeField, const N: usize> EqGadget for [T; N] { - #[tracing::instrument(target = "r1cs", skip(self, other))] +impl + GR1CSVar, F: PrimeField, const N: usize> EqGadget for [T; N] { + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { self.as_slice().is_eq(other.as_slice()) } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_equal( &self, other: &Self, @@ -209,7 +209,7 @@ impl + R1CSVar, F: PrimeField, const N: usize> EqGadget for .conditional_enforce_equal(other.as_slice(), condition) } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_not_equal( &self, other: &Self, diff --git a/src/fields/cubic_extension.rs b/src/fields/cubic_extension.rs index 62105a2d..5bf92b13 100644 --- a/src/fields/cubic_extension.rs +++ b/src/fields/cubic_extension.rs @@ -8,7 +8,7 @@ use ark_ff::{ fields::{CubicExtField, Field}, CubicExtConfig, Zero, }; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use core::{borrow::Borrow, marker::PhantomData}; use educe::Educe; @@ -83,7 +83,7 @@ where } } -impl R1CSVar for CubicExtVar +impl GR1CSVar for CubicExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, @@ -161,7 +161,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn double(&self) -> Result { let c0 = self.c0.double()?; let c1 = self.c1.double()?; @@ -170,7 +170,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn negate(&self) -> Result { let mut result = self.clone(); result.c0.negate_in_place()?; @@ -185,7 +185,7 @@ where /// Abstract Pairing-Friendly /// Fields.pdf; Section 4 (CH-SQR2)) #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn square(&self) -> Result { let a = self.c0.clone(); let b = self.c1.clone(); @@ -205,7 +205,7 @@ where Ok(Self::new(c0, c1, c2)) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn mul_equals(&self, other: &Self, result: &Self) -> Result<(), SynthesisError> { // Karatsuba multiplication for cubic extensions: // v0 = A.c0 * B.c0 @@ -255,7 +255,7 @@ where Ok(()) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn frobenius_map(&self, power: usize) -> Result { let mut result = self.clone(); result.c0.frobenius_map_in_place(power)?; @@ -266,7 +266,7 @@ where Ok(result) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn inverse(&self) -> Result { let mode = if self.is_constant() { AllocationMode::Constant @@ -368,7 +368,7 @@ where for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, P: CubicExtVarConfig, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { let b0 = self.c0.is_eq(&other.c0)?; let b1 = self.c1.is_eq(&other.c1)?; @@ -377,7 +377,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_equal( &self, other: &Self, @@ -390,7 +390,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_not_equal( &self, other: &Self, @@ -407,7 +407,7 @@ where for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, P: CubicExtVarConfig, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_bits_le()?; let mut c1 = self.c1.to_bits_le()?; @@ -417,7 +417,7 @@ where Ok(c0) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bits_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_non_unique_bits_le()?; let mut c1 = self.c1.to_non_unique_bits_le()?; @@ -434,7 +434,7 @@ where for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, P: CubicExtVarConfig, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_bytes_le()?; let mut c1 = self.c1.to_bytes_le()?; @@ -445,7 +445,7 @@ where Ok(c0) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_non_unique_bytes_le()?; let mut c1 = self.c1.to_non_unique_bytes_le()?; @@ -465,7 +465,7 @@ where P: CubicExtVarConfig, BF: ToConstraintFieldGadget, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { let mut res = Vec::new(); @@ -484,7 +484,7 @@ where P: CubicExtVarConfig, { #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean, true_value: &Self, @@ -506,7 +506,7 @@ where { type TableConstant = CubicExtField

; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn two_bit_lookup( b: &[Boolean], c: &[Self::TableConstant], @@ -530,7 +530,7 @@ where { type TableConstant = CubicExtField

; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn three_bit_cond_neg_lookup( b: &[Boolean], b0b1: &Boolean, diff --git a/src/fields/emulated_fp/allocated_field_var.rs b/src/fields/emulated_fp/allocated_field_var.rs index 6905fe37..56f5ee55 100644 --- a/src/fields/emulated_fp/allocated_field_var.rs +++ b/src/fields/emulated_fp/allocated_field_var.rs @@ -11,7 +11,7 @@ use crate::{ use ark_ff::{BigInteger, PrimeField}; use ark_relations::{ ns, - r1cs::{ + gr1cs::{ ConstraintSystemRef, Namespace, OptimizationGoal, Result as R1CSResult, SynthesisError, }, }; @@ -131,7 +131,7 @@ impl AllocatedEmulatedFpVar R1CSResult { assert_eq!(self.get_optimization_type(), other.get_optimization_type()); @@ -156,7 +156,7 @@ impl AllocatedEmulatedFpVar R1CSResult { let other_limbs = Self::get_limbs_representations(other, self.get_optimization_type())?; @@ -181,7 +181,7 @@ impl AllocatedEmulatedFpVar R1CSResult { assert_eq!(self.get_optimization_type(), other.get_optimization_type()); @@ -256,7 +256,7 @@ impl AllocatedEmulatedFpVar R1CSResult { assert_eq!(self.get_optimization_type(), other.get_optimization_type()); @@ -266,13 +266,13 @@ impl AllocatedEmulatedFpVar R1CSResult { self.sub(&Self::constant(self.cs(), *other)?) } /// Multiply a emulated field element - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn mul(&self, other: &Self) -> R1CSResult { assert_eq!(self.get_optimization_type(), other.get_optimization_type()); @@ -285,13 +285,13 @@ impl AllocatedEmulatedFpVar R1CSResult { Self::zero(self.cs())?.sub(self) } /// Compute the inverse of a emulated field element - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn inverse(&self) -> R1CSResult { let inverse = Self::new_witness(self.cs(), || { Ok(self.value()?.inverse().unwrap_or_else(TargetF::zero)) @@ -345,7 +345,7 @@ impl AllocatedEmulatedFpVar AllocatedEmulatedFpVar AllocatedEmulatedFpVar ToBitsGadget for AllocatedEmulatedFpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> R1CSResult>> { let params = get_params( TargetF::MODULUS_BIT_SIZE as usize, @@ -680,7 +680,7 @@ impl ToBitsGadget impl ToBytesGadget for AllocatedEmulatedFpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> R1CSResult>> { let mut bits = self.to_bits_le()?; @@ -696,7 +696,7 @@ impl ToBytesGadget impl CondSelectGadget for AllocatedEmulatedFpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean, true_value: &Self, @@ -732,7 +732,7 @@ impl TwoBitLookupGadget { type TableConstant = TargetF; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn two_bit_lookup( bits: &[Boolean], constants: &[Self::TableConstant], @@ -790,7 +790,7 @@ impl ThreeBitCondNegLookupGadget { type TableConstant = TargetF; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn three_bit_cond_neg_lookup( bits: &[Boolean], b0b1: &Boolean, diff --git a/src/fields/emulated_fp/allocated_mul_result.rs b/src/fields/emulated_fp/allocated_mul_result.rs index 458f6223..71d298d7 100644 --- a/src/fields/emulated_fp/allocated_mul_result.rs +++ b/src/fields/emulated_fp/allocated_mul_result.rs @@ -7,7 +7,7 @@ use crate::{fields::fp::FpVar, prelude::*}; use ark_ff::PrimeField; use ark_relations::{ ns, - r1cs::{ConstraintSystemRef, OptimizationGoal, Result as R1CSResult}, + gr1cs::{ConstraintSystemRef, OptimizationGoal, Result as R1CSResult}, }; use ark_std::{marker::PhantomData, vec::Vec}; use num_bigint::BigUint; @@ -227,7 +227,7 @@ impl AllocatedMulResultVar R1CSResult { assert_eq!(self.get_optimization_type(), other.get_optimization_type()); @@ -248,7 +248,7 @@ impl AllocatedMulResultVar R1CSResult { let mut other_limbs = AllocatedEmulatedFpVar::::get_limbs_representations( other, diff --git a/src/fields/emulated_fp/field_var.rs b/src/fields/emulated_fp/field_var.rs index b8ad9052..ee2230cb 100644 --- a/src/fields/emulated_fp/field_var.rs +++ b/src/fields/emulated_fp/field_var.rs @@ -4,10 +4,10 @@ use crate::{ convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, fields::{fp::FpVar, FieldVar}, prelude::*, - R1CSVar, + GR1CSVar, }; use ark_ff::{BigInteger, PrimeField}; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, Result as R1CSResult, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, Result as R1CSResult, SynthesisError}; use ark_std::{ borrow::Borrow, hash::{Hash, Hasher}, @@ -41,7 +41,7 @@ impl Hash for EmulatedFpVar R1CSVar for EmulatedFpVar { +impl GR1CSVar for EmulatedFpVar { type Value = TargetF; fn cs(&self) -> ConstraintSystemRef { @@ -108,7 +108,7 @@ impl FieldVar Self::Constant(v) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn negate(&self) -> R1CSResult { match self { Self::Constant(c) => Ok(Self::Constant(-*c)), @@ -116,7 +116,7 @@ impl FieldVar } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn inverse(&self) -> R1CSResult { match self { Self::Constant(c) => Ok(Self::Constant(c.inverse().unwrap_or_default())), @@ -124,7 +124,7 @@ impl FieldVar } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn frobenius_map(&self, power: usize) -> R1CSResult { match self { Self::Constant(c) => Ok(Self::Constant({ @@ -207,7 +207,7 @@ impl_bounded_ops!( /// ************************************************************************* impl EqGadget for EmulatedFpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq(&self, other: &Self) -> R1CSResult> { let cs = self.cs().or(other.cs()); @@ -224,7 +224,7 @@ impl EqGadget for EmulatedFpVar EqGadget for EmulatedFpVar EqGadget for EmulatedFpVar ToBitsGadget for EmulatedFpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> R1CSResult>> { match self { Self::Constant(_) => self.to_non_unique_bits_le(), @@ -278,7 +278,7 @@ impl ToBitsGadget for EmulatedFpV } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bits_le(&self) -> R1CSResult>> { use ark_ff::BitIteratorLE; match self { @@ -296,7 +296,7 @@ impl ToBytesGadget { /// Outputs the unique byte decomposition of `self` in *little-endian* /// form. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> R1CSResult>> { match self { Self::Constant(c) => Ok(UInt8::constant_vec( @@ -307,7 +307,7 @@ impl ToBytesGadget } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> R1CSResult>> { match self { Self::Constant(c) => Ok(UInt8::constant_vec( @@ -321,7 +321,7 @@ impl ToBytesGadget impl CondSelectGadget for EmulatedFpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean, true_value: &Self, @@ -353,7 +353,7 @@ impl TwoBitLookupGadget { type TableConstant = TargetF; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn two_bit_lookup(b: &[Boolean], c: &[Self::TableConstant]) -> R1CSResult { debug_assert_eq!(b.len(), 2); debug_assert_eq!(c.len(), 4); @@ -375,7 +375,7 @@ impl ThreeBitCondNegLookupGadget { type TableConstant = TargetF; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn three_bit_cond_neg_lookup( b: &[Boolean], b0b1: &Boolean, @@ -427,7 +427,7 @@ impl AllocVar impl ToConstraintFieldGadget for EmulatedFpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> R1CSResult>> { // Use one group element to represent the optimization type. // @@ -448,7 +448,7 @@ impl ToConstraintFieldGadget impl EmulatedFpVar { /// The `mul_without_reduce` for `EmulatedFpVar` - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn mul_without_reduce(&self, other: &Self) -> R1CSResult> { match self { Self::Constant(c) => match other { diff --git a/src/fields/emulated_fp/mod.rs b/src/fields/emulated_fp/mod.rs index 17b394cb..6107e3ff 100644 --- a/src/fields/emulated_fp/mod.rs +++ b/src/fields/emulated_fp/mod.rs @@ -24,7 +24,7 @@ //! following example: //! //! ```rust -//! # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { +//! # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { //! # use ark_std::UniformRand; //! # use ark_relations::{ns, r1cs::ConstraintSystem}; //! # use ark_r1cs_std::prelude::*; diff --git a/src/fields/emulated_fp/mul_result.rs b/src/fields/emulated_fp/mul_result.rs index f3ada272..0ea67f4a 100644 --- a/src/fields/emulated_fp/mul_result.rs +++ b/src/fields/emulated_fp/mul_result.rs @@ -1,6 +1,6 @@ use super::{AllocatedMulResultVar, EmulatedFpVar}; use ark_ff::PrimeField; -use ark_relations::r1cs::Result as R1CSResult; +use ark_relations::gr1cs::Result as R1CSResult; /// An intermediate representation especially for the result of a /// multiplication, containing more limbs. It is intended for advanced usage to @@ -31,7 +31,7 @@ impl MulResultVar { } /// Reduce the `MulResultVar` back to EmulatedFpVar - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn reduce(&self) -> R1CSResult> { match self { Self::Constant(c) => Ok(EmulatedFpVar::Constant(*c)), diff --git a/src/fields/emulated_fp/reduce.rs b/src/fields/emulated_fp/reduce.rs index d3cd0c28..2846b96b 100644 --- a/src/fields/emulated_fp/reduce.rs +++ b/src/fields/emulated_fp/reduce.rs @@ -4,12 +4,12 @@ use crate::{ boolean::Boolean, eq::EqGadget, fields::{fp::FpVar, FieldVar}, - R1CSVar, + GR1CSVar, }; use ark_ff::{biginteger::BigInteger, BitIteratorBE, One, PrimeField, Zero}; use ark_relations::{ ns, - r1cs::{ConstraintSystemRef, Result as R1CSResult}, + gr1cs::{ConstraintSystemRef, Result as R1CSResult}, }; use ark_std::{cmp::min, marker::PhantomData, vec, vec::Vec}; use num_bigint::BigUint; @@ -62,7 +62,7 @@ impl Reducer { /// 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")] + #[tracing::instrument(target = "gr1cs")] pub fn limb_to_bits(limb: &FpVar, num_bits: usize) -> R1CSResult>> { let cs = limb.cs(); @@ -109,7 +109,7 @@ impl Reducer { } /// Reduction to the normal form - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn reduce(elem: &mut AllocatedEmulatedFpVar) -> R1CSResult<()> { let new_elem = AllocatedEmulatedFpVar::new_witness(ns!(elem.cs(), "normal_form"), || { Ok(elem.value().unwrap_or_default()) @@ -121,7 +121,7 @@ impl Reducer { } /// Reduction to be enforced after additions - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn post_add_reduce(elem: &mut AllocatedEmulatedFpVar) -> R1CSResult<()> { let params = get_params( TargetF::MODULUS_BIT_SIZE as usize, @@ -139,7 +139,7 @@ impl Reducer { /// Reduction used before multiplication to reduce the representations in a /// way that allows efficient multiplication - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn pre_mul_reduce( elem: &mut AllocatedEmulatedFpVar, elem_other: &mut AllocatedEmulatedFpVar, @@ -189,7 +189,7 @@ impl Reducer { } /// Reduction to the normal form - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn pre_eq_reduce(elem: &mut AllocatedEmulatedFpVar) -> R1CSResult<()> { if elem.is_in_the_normal_form { return Ok(()); @@ -199,7 +199,7 @@ impl Reducer { } /// Group and check equality - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn group_and_check_equality( surfeit: usize, bits_per_limb: usize, diff --git a/src/fields/fp/cmp.rs b/src/fields/fp/cmp.rs index f3304e4a..8e1193f9 100644 --- a/src/fields/fp/cmp.rs +++ b/src/fields/fp/cmp.rs @@ -5,7 +5,7 @@ use crate::{ prelude::*, }; use ark_ff::PrimeField; -use ark_relations::r1cs::{SynthesisError, Variable}; +use ark_relations::gr1cs::{SynthesisError, Variable}; use core::cmp::Ordering; impl FpVar { @@ -14,7 +14,7 @@ impl FpVar { /// also be checked for equality, e.g. `self <= other` instead of `self < /// other`, set `should_also_check_quality` to `true`. This variant /// verifies `self` and `other` are `<= (p-1)/2`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn enforce_cmp( &self, other: &FpVar, @@ -31,7 +31,7 @@ impl FpVar { /// other`, set `should_also_check_quality` to `true`. This variant /// assumes `self` and `other` are `<= (p-1)/2` and does not generate /// constraints to verify that. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn enforce_cmp_unchecked( &self, other: &FpVar, @@ -48,7 +48,7 @@ impl FpVar { /// `self` should also be checked for equality, e.g. `self <= other` /// instead of `self < other`, set `should_also_check_quality` to /// `true`. This variant verifies `self` and `other` are `<= (p-1)/2`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn is_cmp( &self, other: &FpVar, @@ -66,7 +66,7 @@ impl FpVar { /// `self < other`, set `should_also_check_quality` to `true`. This /// variant assumes `self` and `other` are `<= (p-1)/2` and does not /// generate constraints to verify that. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn is_cmp_unchecked( &self, other: &FpVar, @@ -98,7 +98,7 @@ impl FpVar { } /// Helper function to enforce that `self <= (p-1)/2`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn enforce_smaller_or_equal_than_mod_minus_one_div_two( &self, ) -> Result<(), SynthesisError> { @@ -147,7 +147,7 @@ impl FpVar { let lc_one = lc!() + Variable::One; [self, other] .cs() - .enforce_constraint(is_smaller_than.lc(), lc_one.clone(), lc_one) + .enforce_r1cs_constraint(is_smaller_than.lc(), lc_one.clone(), lc_one) } } @@ -157,7 +157,7 @@ mod test { use crate::{alloc::AllocVar, fields::fp::FpVar}; use ark_ff::{PrimeField, UniformRand}; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_test_curves::bls12_381::Fr; #[test] diff --git a/src/fields/fp/mod.rs b/src/fields/fp/mod.rs index bc35c81b..36bbc9ad 100644 --- a/src/fields/fp/mod.rs +++ b/src/fields/fp/mod.rs @@ -1,5 +1,5 @@ use ark_ff::{BigInteger, PrimeField}; -use ark_relations::r1cs::{ +use ark_relations::gr1cs::{ ConstraintSystemRef, LinearCombination, Namespace, SynthesisError, Variable, }; @@ -80,7 +80,7 @@ impl FpVar { } } -impl R1CSVar for FpVar { +impl GR1CSVar for FpVar { type Value = F; fn cs(&self) -> ConstraintSystemRef { @@ -142,7 +142,7 @@ impl AllocatedFp { /// Outputs `self + other`. /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn add(&self, other: &Self) -> Self { let value = match (self.value, other.value) { (Some(val1), Some(val2)) => Some(val1 + &val2), @@ -194,7 +194,7 @@ impl AllocatedFp { /// Outputs `self - other`. /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn sub(&self, other: &Self) -> Self { let value = match (self.value, other.value) { (Some(val1), Some(val2)) => Some(val1 - &val2), @@ -211,14 +211,14 @@ impl AllocatedFp { /// Outputs `self * other`. /// /// This requires *one* constraint. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn mul(&self, other: &Self) -> Self { let product = AllocatedFp::new_witness(self.cs.clone(), || { Ok(self.value.get()? * &other.value.get()?) }) .unwrap(); self.cs - .enforce_constraint( + .enforce_r1cs_constraint( lc!() + self.variable, lc!() + other.variable, lc!() + product.variable, @@ -230,7 +230,7 @@ impl AllocatedFp { /// Output `self + other` /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn add_constant(&self, other: F) -> Self { if other.is_zero() { self.clone() @@ -247,7 +247,7 @@ impl AllocatedFp { /// Output `self - other` /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn sub_constant(&self, other: F) -> Self { self.add_constant(-other) } @@ -255,7 +255,7 @@ impl AllocatedFp { /// Output `self * other` /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn mul_constant(&self, other: F) -> Self { if other.is_one() { self.clone() @@ -269,7 +269,7 @@ impl AllocatedFp { /// Output `self + self` /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn double(&self) -> Result { let value = self.value.map(|val| val.double()); let variable = self.cs.new_lc(lc!() + self.variable + self.variable)?; @@ -279,7 +279,7 @@ impl AllocatedFp { /// Output `-self` /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn negate(&self) -> Self { let mut result = self.clone(); result.negate_in_place(); @@ -289,7 +289,7 @@ impl AllocatedFp { /// Sets `self = -self` /// /// This does not create any constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn negate_in_place(&mut self) -> &mut Self { if let Some(val) = self.value.as_mut() { *val = -(*val); @@ -301,7 +301,7 @@ impl AllocatedFp { /// Outputs `self * self` /// /// This requires *one* constraint. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn square(&self) -> Result { Ok(self.mul(self)) } @@ -309,13 +309,13 @@ impl AllocatedFp { /// Outputs `result` such that `result * self = 1`. /// /// This requires *one* constraint. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn inverse(&self) -> Result { let inverse = Self::new_witness(self.cs.clone(), || { Ok(self.value.get()?.inverse().unwrap_or_else(F::zero)) })?; - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable, lc!() + inverse.variable, lc!() + Variable::One, @@ -324,7 +324,7 @@ impl AllocatedFp { } /// This is a no-op for prime fields. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn frobenius_map(&self, _: usize) -> Result { Ok(self.clone()) } @@ -332,9 +332,9 @@ impl AllocatedFp { /// Enforces that `self * other = result`. /// /// This requires *one* constraint. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn mul_equals(&self, other: &Self, result: &Self) -> Result<(), SynthesisError> { - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable, lc!() + other.variable, lc!() + result.variable, @@ -344,9 +344,9 @@ impl AllocatedFp { /// Enforces that `self * self = result`. /// /// This requires *one* constraint. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn square_equals(&self, result: &Self) -> Result<(), SynthesisError> { - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable, lc!() + self.variable, lc!() + result.variable, @@ -356,7 +356,7 @@ impl AllocatedFp { /// Outputs the bit `self == other`. /// /// This requires two constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn is_eq(&self, other: &Self) -> Result, SynthesisError> { Ok(!self.is_neq(other)?) } @@ -364,7 +364,7 @@ impl AllocatedFp { /// Outputs the bit `self != other`. /// /// This requires two constraints. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn is_neq(&self, other: &Self) -> Result, SynthesisError> { // We don't need to enforce `is_not_equal` to be boolean here; // see the comments above the constraints below for why. @@ -424,12 +424,12 @@ impl AllocatedFp { // and constraint 2 enforces that if self != other, then `is_not_equal = 1`. // Since these are the only possible two cases, `is_not_equal` is always // constrained to 0 or 1. - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable - other.variable, lc!() + multiplier, is_not_equal.lc(), )?; - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable - other.variable, (!&is_not_equal).lc(), lc!(), @@ -440,13 +440,13 @@ impl AllocatedFp { /// Enforces that self == other if `should_enforce.is_eq(&Boolean::TRUE)`. /// /// This requires one constraint. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn conditional_enforce_equal( &self, other: &Self, should_enforce: &Boolean, ) -> Result<(), SynthesisError> { - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable - other.variable, lc!() + should_enforce.lc(), lc!(), @@ -456,7 +456,7 @@ impl AllocatedFp { /// Enforces that self != other if `should_enforce.is_eq(&Boolean::TRUE)`. /// /// This requires one constraint. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn conditional_enforce_not_equal( &self, other: &Self, @@ -478,7 +478,7 @@ impl AllocatedFp { } })?; - self.cs.enforce_constraint( + self.cs.enforce_r1cs_constraint( lc!() + self.variable - other.variable, lc!() + multiplier.variable, should_enforce.lc(), @@ -496,14 +496,14 @@ impl ToBitsGadget for AllocatedFp { /// /// This method enforces that the output is in the field, i.e. /// it invokes `Boolean::enforce_in_field_le` on the bit decomposition. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> Result>, SynthesisError> { let bits = self.to_non_unique_bits_le()?; Boolean::enforce_in_field_le(&bits)?; Ok(bits) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bits_le(&self) -> Result>, SynthesisError> { let cs = self.cs.clone(); use ark_ff::BitIteratorBE; @@ -539,7 +539,7 @@ impl ToBitsGadget for AllocatedFp { lc = lc - &self.variable; - cs.enforce_constraint(lc!(), lc!(), lc)?; + cs.enforce_r1cs_constraint(lc!(), lc!(), lc)?; Ok(bits) } @@ -551,7 +551,7 @@ impl ToBytesGadget for AllocatedFp { /// /// This method enforces that the decomposition represents /// an integer that is less than `F::MODULUS`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let num_bits = F::BigInt::NUM_LIMBS * 64; let mut bits = self.to_bits_le()?; @@ -564,7 +564,7 @@ impl ToBytesGadget for AllocatedFp { Ok(bytes) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let num_bits = F::BigInt::NUM_LIMBS * 64; let mut bits = self.to_non_unique_bits_le()?; @@ -579,7 +579,7 @@ impl ToBytesGadget for AllocatedFp { } impl ToConstraintFieldGadget for AllocatedFp { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { Ok(vec![self.clone().into()]) } @@ -587,7 +587,7 @@ impl ToConstraintFieldGadget for AllocatedFp { impl CondSelectGadget for AllocatedFp { #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean, true_val: &Self, @@ -607,7 +607,7 @@ impl CondSelectGadget for AllocatedFp { // r = c * a + (1 - c) * b // r = b + c * (a - b) // c * (a - b) = r - b - cs.enforce_constraint( + cs.enforce_r1cs_constraint( cond.lc(), lc!() + true_val.variable - false_val.variable, lc!() + result.variable - false_val.variable, @@ -623,7 +623,7 @@ impl CondSelectGadget for AllocatedFp { /// `b` is little-endian: `b[0]` is LSB. impl TwoBitLookupGadget for AllocatedFp { type TableConstant = F; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn two_bit_lookup(b: &[Boolean], c: &[Self::TableConstant]) -> Result { debug_assert_eq!(b.len(), 2); debug_assert_eq!(c.len(), 4); @@ -634,7 +634,7 @@ impl TwoBitLookupGadget for AllocatedFp { Ok(c[index]) })?; let one = Variable::One; - b.cs().enforce_constraint( + b.cs().enforce_r1cs_constraint( lc!() + b[1].lc() * (c[3] - &c[2] - &c[1] + &c[0]) + (c[1] - &c[0], one), lc!() + b[0].lc(), lc!() + result.variable - (c[0], one) + b[1].lc() * (c[0] - &c[2]), @@ -647,7 +647,7 @@ impl TwoBitLookupGadget for AllocatedFp { impl ThreeBitCondNegLookupGadget for AllocatedFp { type TableConstant = F; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn three_bit_cond_neg_lookup( b: &[Boolean], b0b1: &Boolean, @@ -675,7 +675,7 @@ impl ThreeBitCondNegLookupGadget for AllocatedFp { + b[1].lc() * (c[2] - &c[0]) + (c[0], Variable::One); // enforce y * (1 - 2 * b_2) == res - b.cs().enforce_constraint( + b.cs().enforce_r1cs_constraint( y_lc.clone(), b[2].lc() * F::from(2u64).neg() + (F::one(), Variable::One), lc!() + result.variable, @@ -726,7 +726,7 @@ impl FieldVar for FpVar { Self::Constant(F::one()) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn double(&self) -> Result { match self { Self::Constant(c) => Ok(Self::Constant(c.double())), @@ -734,7 +734,7 @@ impl FieldVar for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn negate(&self) -> Result { match self { Self::Constant(c) => Ok(Self::Constant(-*c)), @@ -742,7 +742,7 @@ impl FieldVar for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn square(&self) -> Result { match self { Self::Constant(c) => Ok(Self::Constant(c.square())), @@ -751,7 +751,7 @@ impl FieldVar for FpVar { } /// Enforce that `self * other == result`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn mul_equals(&self, other: &Self, result: &Self) -> Result<(), SynthesisError> { use FpVar::*; match (self, other, result) { @@ -769,7 +769,7 @@ impl FieldVar for FpVar { } /// Enforce that `self * self == result`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn square_equals(&self, result: &Self) -> Result<(), SynthesisError> { use FpVar::*; match (self, result) { @@ -788,7 +788,7 @@ impl FieldVar for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn inverse(&self) -> Result { match self { FpVar::Var(v) => v.inverse().map(FpVar::Var), @@ -796,7 +796,7 @@ impl FieldVar for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn frobenius_map(&self, power: usize) -> Result { match self { FpVar::Var(v) => v.frobenius_map(power).map(FpVar::Var), @@ -808,7 +808,7 @@ impl FieldVar for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn frobenius_map_in_place(&mut self, power: usize) -> Result<&mut Self, SynthesisError> { *self = self.frobenius_map(power)?; Ok(self) @@ -883,7 +883,7 @@ impl_ops!( /// ************************************************************************* impl EqGadget for FpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { match (self, other) { (Self::Constant(c1), Self::Constant(c2)) => Ok(Boolean::Constant(c1 == c2)), @@ -896,7 +896,7 @@ impl EqGadget for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_equal( &self, other: &Self, @@ -913,7 +913,7 @@ impl EqGadget for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_not_equal( &self, other: &Self, @@ -932,7 +932,7 @@ impl EqGadget for FpVar { } impl ToBitsGadget for FpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> Result>, SynthesisError> { match self { Self::Constant(_) => self.to_non_unique_bits_le(), @@ -940,7 +940,7 @@ impl ToBitsGadget for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bits_le(&self) -> Result>, SynthesisError> { use ark_ff::BitIteratorLE; match self { @@ -956,7 +956,7 @@ impl ToBitsGadget for FpVar { impl ToBytesGadget for FpVar { /// Outputs the unique byte decomposition of `self` in *little-endian* /// form. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { match self { Self::Constant(c) => Ok(UInt8::constant_vec( @@ -966,7 +966,7 @@ impl ToBytesGadget for FpVar { } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { match self { Self::Constant(c) => Ok(UInt8::constant_vec( @@ -978,14 +978,14 @@ impl ToBytesGadget for FpVar { } impl ToConstraintFieldGadget for FpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { Ok(vec![self.clone()]) } } impl CondSelectGadget for FpVar { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean, true_value: &Self, @@ -1025,7 +1025,7 @@ impl CondSelectGadget for FpVar { impl TwoBitLookupGadget for FpVar { type TableConstant = F; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn two_bit_lookup(b: &[Boolean], c: &[Self::TableConstant]) -> Result { debug_assert_eq!(b.len(), 2); debug_assert_eq!(c.len(), 4); @@ -1043,7 +1043,7 @@ impl TwoBitLookupGadget for FpVar { impl ThreeBitCondNegLookupGadget for FpVar { type TableConstant = F; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn three_bit_cond_neg_lookup( b: &[Boolean], b0b1: &Boolean, @@ -1125,9 +1125,9 @@ mod test { alloc::{AllocVar, AllocationMode}, eq::EqGadget, fields::fp::FpVar, - R1CSVar, + GR1CSVar, }; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_std::{UniformRand, Zero}; use ark_test_curves::bls12_381::Fr; diff --git a/src/fields/fp12.rs b/src/fields/fp12.rs index 12bdc8c1..5a608d67 100644 --- a/src/fields/fp12.rs +++ b/src/fields/fp12.rs @@ -4,7 +4,7 @@ use ark_ff::{ fp6_3over2::Fp6Config, QuadExtConfig, }; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; /// A degree-12 extension field constructed as the tower of a /// quadratic extension over a cubic extension over a quadratic extension field. diff --git a/src/fields/fp6_3over2.rs b/src/fields/fp6_3over2.rs index 19c9648b..85aeb3dc 100644 --- a/src/fields/fp6_3over2.rs +++ b/src/fields/fp6_3over2.rs @@ -3,7 +3,7 @@ use ark_ff::{ fields::{fp6_3over2::*, Fp2}, CubicExtConfig, }; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::ops::MulAssign; /// A sextic extension field constructed as the tower of a diff --git a/src/fields/mod.rs b/src/fields/mod.rs index bced7ffd..a2196e99 100644 --- a/src/fields/mod.rs +++ b/src/fields/mod.rs @@ -1,5 +1,5 @@ use ark_ff::{prelude::*, BitIteratorBE}; -use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, SynthesisError}; use core::{ fmt::Debug, ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}, @@ -70,7 +70,7 @@ pub trait FieldVar: 'static + Clone + From> - + R1CSVar + + GR1CSVar + EqGadget + ToBitsGadget + AllocVar diff --git a/src/fields/quadratic_extension.rs b/src/fields/quadratic_extension.rs index d7419da3..f29b7fbb 100644 --- a/src/fields/quadratic_extension.rs +++ b/src/fields/quadratic_extension.rs @@ -8,7 +8,7 @@ use ark_ff::{ fields::{Field, QuadExtConfig, QuadExtField}, Zero, }; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use core::{borrow::Borrow, marker::PhantomData}; use educe::Educe; @@ -86,7 +86,7 @@ where /// This is only to be used when the element is *known* to be in the /// cyclotomic subgroup. #[inline] - #[tracing::instrument(target = "r1cs", skip(exponent))] + #[tracing::instrument(target = "gr1cs", skip(exponent))] pub fn cyclotomic_exp(&self, exponent: impl AsRef<[u64]>) -> Result where Self: FieldVar, P::BasePrimeField>, @@ -117,7 +117,7 @@ where } } -impl R1CSVar for QuadExtVar +impl GR1CSVar for QuadExtVar where BF: FieldVar, for<'a> &'a BF: FieldOpsBounds<'a, P::BaseField, BF>, @@ -191,7 +191,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn double(&self) -> Result { let c0 = self.c0.double()?; let c1 = self.c1.double()?; @@ -199,7 +199,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn negate(&self) -> Result { let mut result = self.clone(); result.c0.negate_in_place()?; @@ -208,7 +208,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn square(&self) -> Result { // From Libsnark/fp2_gadget.tcc // Complex multiplication for Fp2: @@ -232,7 +232,7 @@ where Ok(Self::new(c0, c1)) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn mul_equals(&self, other: &Self, result: &Self) -> Result<(), SynthesisError> { // Karatsuba multiplication for Fp2: // v0 = A.c0 * B.c0 @@ -265,7 +265,7 @@ where Ok(()) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn frobenius_map(&self, power: usize) -> Result { let mut result = self.clone(); result.c0.frobenius_map_in_place(power)?; @@ -274,7 +274,7 @@ where Ok(result) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn inverse(&self) -> Result { let mode = if self.is_constant() { AllocationMode::Constant @@ -374,7 +374,7 @@ where for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, P: QuadExtVarConfig, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { let b0 = self.c0.is_eq(&other.c0)?; let b1 = self.c1.is_eq(&other.c1)?; @@ -382,7 +382,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_equal( &self, other: &Self, @@ -394,7 +394,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_not_equal( &self, other: &Self, @@ -411,7 +411,7 @@ where for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, P: QuadExtVarConfig, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_bits_le()?; let mut c1 = self.c1.to_bits_le()?; @@ -419,7 +419,7 @@ where Ok(c0) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bits_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_non_unique_bits_le()?; let mut c1 = self.c1.to_non_unique_bits_le()?; @@ -434,7 +434,7 @@ where for<'b> &'b BF: FieldOpsBounds<'b, P::BaseField, BF>, P: QuadExtVarConfig, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_bytes_le()?; let mut c1 = self.c1.to_bytes_le()?; @@ -442,7 +442,7 @@ where Ok(c0) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut c0 = self.c0.to_non_unique_bytes_le()?; let mut c1 = self.c1.to_non_unique_bytes_le()?; @@ -458,7 +458,7 @@ where P: QuadExtVarConfig, BF: ToConstraintFieldGadget, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { let mut res = Vec::new(); @@ -496,7 +496,7 @@ where { type TableConstant = QuadExtField

; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn two_bit_lookup( b: &[Boolean], c: &[Self::TableConstant], @@ -518,7 +518,7 @@ where { type TableConstant = QuadExtField

; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn three_bit_cond_neg_lookup( b: &[Boolean], b0b1: &Boolean, diff --git a/src/r1cs_var.rs b/src/gr1cs_var.rs similarity index 83% rename from src/r1cs_var.rs rename to src/gr1cs_var.rs index f99e9b2d..f006d2ee 100644 --- a/src/r1cs_var.rs +++ b/src/gr1cs_var.rs @@ -1,10 +1,10 @@ use ark_ff::Field; -use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, SynthesisError}; use ark_std::vec::Vec; /// This trait describes some core functionality that is common to high-level /// variables, such as `Boolean`s, `FieldVar`s, `GroupVar`s, etc. -pub trait R1CSVar { +pub trait GR1CSVar { /// The type of the "native" value that `Self` represents in the constraint /// system. type Value: core::fmt::Debug + Eq + Clone; @@ -12,7 +12,7 @@ pub trait R1CSVar { /// Returns the underlying `ConstraintSystemRef`. /// /// If `self` is a constant value, then this *must* return - /// `ark_relations::r1cs::ConstraintSystemRef::None`. + /// `ark_relations::gr1cs::ConstraintSystemRef::None`. fn cs(&self) -> ConstraintSystemRef; /// Returns `true` if `self` is a circuit-generation-time constant. @@ -25,7 +25,7 @@ pub trait R1CSVar { fn value(&self) -> Result; } -impl> R1CSVar for [T] { +impl> GR1CSVar for [T] { type Value = Vec; fn cs(&self) -> ConstraintSystemRef { @@ -45,7 +45,7 @@ impl> R1CSVar for [T] { } } -impl<'a, F: Field, T: 'a + R1CSVar> R1CSVar for &'a T { +impl<'a, F: Field, T: 'a + GR1CSVar> GR1CSVar for &'a T { type Value = T::Value; fn cs(&self) -> ConstraintSystemRef { @@ -57,7 +57,7 @@ impl<'a, F: Field, T: 'a + R1CSVar> R1CSVar for &'a T { } } -impl, const N: usize> R1CSVar for [T; N] { +impl, const N: usize> GR1CSVar for [T; N] { type Value = [T::Value; N]; fn cs(&self) -> ConstraintSystemRef { @@ -73,7 +73,7 @@ impl, const N: usize> R1CSVar for [T; N] { } } -impl R1CSVar for () { +impl GR1CSVar for () { type Value = (); fn cs(&self) -> ConstraintSystemRef { diff --git a/src/groups/curves/short_weierstrass/bls12/mod.rs b/src/groups/curves/short_weierstrass/bls12/mod.rs index 1549f976..a6610380 100644 --- a/src/groups/curves/short_weierstrass/bls12/mod.rs +++ b/src/groups/curves/short_weierstrass/bls12/mod.rs @@ -3,7 +3,7 @@ use ark_ec::{ short_weierstrass::Affine as GroupAffine, }; use ark_ff::{BitIteratorBE, Field, One}; -use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_relations::gr1cs::{Namespace, SynthesisError}; use crate::{ fields::{fp::FpVar, fp2::Fp2Var, FieldVar}, @@ -77,7 +77,7 @@ impl AllocVar, P::Fp> for G1PreparedVar

{ impl ToBytesGadget for G1PreparedVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut bytes = self.0.x.to_bytes_le()?; let y_bytes = self.0.y.to_bytes_le()?; @@ -87,7 +87,7 @@ impl ToBytesGadget for G1PreparedVar

{ Ok(bytes) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut bytes = self.0.x.to_non_unique_bytes_le()?; let y_bytes = self.0.y.to_non_unique_bytes_le()?; @@ -110,7 +110,7 @@ pub struct G2PreparedVar { } impl AllocVar, P::Fp> for G2PreparedVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f, mode))] + #[tracing::instrument(target = "gr1cs", skip(cs, f, mode))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -169,7 +169,7 @@ impl AllocVar, P::Fp> for G2PreparedVar

{ impl ToBytesGadget for G2PreparedVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut bytes = Vec::new(); for coeffs in &self.ell_coeffs { @@ -179,7 +179,7 @@ impl ToBytesGadget for G2PreparedVar

{ Ok(bytes) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut bytes = Vec::new(); for coeffs in &self.ell_coeffs { @@ -192,7 +192,7 @@ impl ToBytesGadget for G2PreparedVar

{ impl G2PreparedVar

{ /// Constructs `Self` from a `G2Var`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn from_group_var(q: &G2Var

) -> Result { let q = q.to_affine()?; let two_inv = P::Fp::one().double().inverse().unwrap(); @@ -212,7 +212,7 @@ impl G2PreparedVar

{ Ok(Self { ell_coeffs }) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn double(r: &mut G2AffineVar

, two_inv: &P::Fp) -> Result, SynthesisError> { let a = r.y.inverse()?; let mut b = r.x.square()?; @@ -236,7 +236,7 @@ impl G2PreparedVar

{ } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn add(r: &mut G2AffineVar

, q: &G2AffineVar

) -> Result, SynthesisError> { let a = (&q.x - &r.x).inverse()?; let b = &q.y - &r.y; diff --git a/src/groups/curves/short_weierstrass/mnt4/mod.rs b/src/groups/curves/short_weierstrass/mnt4/mod.rs index a5c6875d..4e7842e9 100644 --- a/src/groups/curves/short_weierstrass/mnt4/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt4/mod.rs @@ -3,7 +3,7 @@ use ark_ec::mnt4::{ G1Prepared, G2Prepared, MNT4Config, }; use ark_ff::Field; -use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_relations::gr1cs::{Namespace, SynthesisError}; use crate::{ convert::ToBytesGadget, @@ -38,7 +38,7 @@ pub struct G1PreparedVar { } impl AllocVar, P::Fp> for G1PreparedVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -89,7 +89,7 @@ impl G1PreparedVar

{ } /// Constructs `Self` from a `G1Var`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn from_group_var(q: &G1Var

) -> Result { let q = q.to_affine()?; let x_twist = Fp2Var::new(&q.x * P::TWIST.c0, &q.x * P::TWIST.c1); @@ -105,7 +105,7 @@ impl G1PreparedVar

{ impl ToBytesGadget for G1PreparedVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_bytes_le()?; let mut y = self.y.to_bytes_le()?; @@ -118,7 +118,7 @@ impl ToBytesGadget for G1PreparedVar

{ Ok(x) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_non_unique_bytes_le()?; let mut y = self.y.to_non_unique_bytes_le()?; @@ -154,7 +154,7 @@ pub struct G2PreparedVar { } impl AllocVar, P::Fp> for G2PreparedVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -201,7 +201,7 @@ impl AllocVar, P::Fp> for G2PreparedVar

{ impl ToBytesGadget for G2PreparedVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_bytes_le()?; let mut y = self.y.to_bytes_le()?; @@ -221,7 +221,7 @@ impl ToBytesGadget for G2PreparedVar

{ Ok(x) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_non_unique_bytes_le()?; let mut y = self.y.to_non_unique_bytes_le()?; @@ -271,7 +271,7 @@ impl G2PreparedVar

{ } /// Constructs `Self` from a `G2Var`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn from_group_var(q: &G2Var

) -> Result { let twist_inv = P::TWIST.inverse().unwrap(); let q = q.to_affine()?; @@ -351,7 +351,7 @@ pub struct AteDoubleCoefficientsVar { } impl AllocVar, P::Fp> for AteDoubleCoefficientsVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -379,7 +379,7 @@ impl AllocVar, P::Fp> for AteDoubleCoeff impl ToBytesGadget for AteDoubleCoefficientsVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut c_h = self.c_h.to_bytes_le()?; let mut c_4c = self.c_4c.to_bytes_le()?; @@ -392,7 +392,7 @@ impl ToBytesGadget for AteDoubleCoefficientsVar

{ Ok(c_h) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut c_h = self.c_h.to_non_unique_bytes_le()?; let mut c_4c = self.c_4c.to_non_unique_bytes_le()?; @@ -434,7 +434,7 @@ pub struct AteAdditionCoefficientsVar { } impl AllocVar, P::Fp> for AteAdditionCoefficientsVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -456,7 +456,7 @@ impl AllocVar, P::Fp> for AteAdditionC impl ToBytesGadget for AteAdditionCoefficientsVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut c_l1 = self.c_l1.to_bytes_le()?; let mut c_rz = self.c_rz.to_bytes_le()?; @@ -465,7 +465,7 @@ impl ToBytesGadget for AteAdditionCoefficientsVar

{ Ok(c_l1) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut c_l1 = self.c_l1.to_non_unique_bytes_le()?; let mut c_rz = self.c_rz.to_non_unique_bytes_le()?; diff --git a/src/groups/curves/short_weierstrass/mnt6/mod.rs b/src/groups/curves/short_weierstrass/mnt6/mod.rs index 83f742f4..9959a999 100644 --- a/src/groups/curves/short_weierstrass/mnt6/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt6/mod.rs @@ -3,7 +3,7 @@ use ark_ec::mnt6::{ G1Prepared, G2Prepared, MNT6Config, }; use ark_ff::Field; -use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_relations::gr1cs::{Namespace, SynthesisError}; use crate::{ convert::ToBytesGadget, @@ -54,7 +54,7 @@ impl G1PreparedVar

{ } /// Constructs `Self` from a `G1Var`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn from_group_var(q: &G1Var

) -> Result { let q = q.to_affine()?; let zero = FpVar::::zero(); @@ -71,7 +71,7 @@ impl G1PreparedVar

{ } impl AllocVar, P::Fp> for G1PreparedVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -105,7 +105,7 @@ impl AllocVar, P::Fp> for G1PreparedVar

{ impl ToBytesGadget for G1PreparedVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_bytes_le()?; let mut y = self.y.to_bytes_le()?; @@ -118,7 +118,7 @@ impl ToBytesGadget for G1PreparedVar

{ Ok(x) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_non_unique_bytes_le()?; let mut y = self.y.to_non_unique_bytes_le()?; @@ -154,7 +154,7 @@ pub struct G2PreparedVar { } impl AllocVar, P::Fp> for G2PreparedVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -201,7 +201,7 @@ impl AllocVar, P::Fp> for G2PreparedVar

{ impl ToBytesGadget for G2PreparedVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_bytes_le()?; let mut y = self.y.to_bytes_le()?; @@ -221,7 +221,7 @@ impl ToBytesGadget for G2PreparedVar

{ Ok(x) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut x = self.x.to_non_unique_bytes_le()?; let mut y = self.y.to_non_unique_bytes_le()?; @@ -271,7 +271,7 @@ impl G2PreparedVar

{ } /// Constructs `Self` from a `G2Var`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn from_group_var(q: &G2Var

) -> Result { let q = q.to_affine()?; let twist_inv = P::TWIST.inverse().unwrap(); @@ -351,7 +351,7 @@ pub struct AteDoubleCoefficientsVar { } impl AllocVar, P::Fp> for AteDoubleCoefficientsVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -379,7 +379,7 @@ impl AllocVar, P::Fp> for AteDoubleCoeff impl ToBytesGadget for AteDoubleCoefficientsVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut c_h = self.c_h.to_bytes_le()?; let mut c_4c = self.c_4c.to_bytes_le()?; @@ -392,7 +392,7 @@ impl ToBytesGadget for AteDoubleCoefficientsVar

{ Ok(c_h) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut c_h = self.c_h.to_non_unique_bytes_le()?; let mut c_4c = self.c_4c.to_non_unique_bytes_le()?; @@ -432,7 +432,7 @@ pub struct AteAdditionCoefficientsVar { } impl AllocVar, P::Fp> for AteAdditionCoefficientsVar

{ - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>, f: impl FnOnce() -> Result, @@ -454,7 +454,7 @@ impl AllocVar, P::Fp> for AteAdditionC impl ToBytesGadget for AteAdditionCoefficientsVar

{ #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>, SynthesisError> { let mut c_l1 = self.c_l1.to_bytes_le()?; let mut c_rz = self.c_rz.to_bytes_le()?; @@ -463,7 +463,7 @@ impl ToBytesGadget for AteAdditionCoefficientsVar

{ Ok(c_l1) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>, SynthesisError> { let mut c_l1 = self.c_l1.to_non_unique_bytes_le()?; let mut c_rz = self.c_rz.to_non_unique_bytes_le()?; diff --git a/src/groups/curves/short_weierstrass/mod.rs b/src/groups/curves/short_weierstrass/mod.rs index 8604c052..a1f122b5 100644 --- a/src/groups/curves/short_weierstrass/mod.rs +++ b/src/groups/curves/short_weierstrass/mod.rs @@ -3,7 +3,7 @@ use ark_ec::{ AffineRepr, CurveConfig, CurveGroup, }; use ark_ff::{AdditiveGroup, BitIteratorBE, Field, One, PrimeField, Zero}; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use ark_std::{borrow::Borrow, marker::PhantomData, ops::Mul}; use educe::Educe; use non_zero_affine::NonZeroAffineVar; @@ -121,7 +121,7 @@ where } } -impl R1CSVar> for ProjectiveVar +impl GR1CSVar> for ProjectiveVar where P: SWCurveConfig, F: FieldVar>, @@ -159,7 +159,7 @@ where } /// Convert this point into affine form. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn to_affine(&self) -> Result, SynthesisError> { if self.is_constant() { let point = self.value()?.into_affine(); @@ -198,7 +198,7 @@ where /// Allocates a new variable without performing an on-curve check, which is /// useful if the variable is known to be on the curve (eg., if the point /// is a constant or is a public input). - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] pub fn new_variable_omit_on_curve_check( cs: impl Into>>, f: impl FnOnce() -> Result, SynthesisError>, @@ -238,7 +238,7 @@ where /// Mixed addition, which is useful when `other = (x2, y2)` is known to have /// z = 1. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] pub(crate) fn add_mixed(&self, other: &NonZeroAffineVar) -> Result { // Complete mixed addition formula from Renes-Costello-Batina 2015 // Algorithm 2 @@ -281,7 +281,7 @@ where /// Computes a scalar multiplication with a little-endian scalar of size /// `P::ScalarField::MODULUS_BITS`. #[tracing::instrument( - target = "r1cs", + target = "gr1cs", skip(self, mul_result, multiple_of_power_of_two, bits) )] fn fixed_scalar_mul_le( @@ -390,7 +390,7 @@ where self.z.is_zero() } - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable_omit_prime_order_check( cs: impl Into>>, f: impl FnOnce() -> Result, SynthesisError>, @@ -433,7 +433,7 @@ where /// is unchanged. // TODO: at the moment this doesn't work, because the addition and doubling // formulae are incomplete for even-order points. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn enforce_prime_order(&self) -> Result<(), SynthesisError> { unimplemented!("cannot enforce prime order"); // let r_minus_1 = (-P::ScalarField::one()).into_bigint(); @@ -451,7 +451,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn double_in_place(&mut self) -> Result<(), SynthesisError> { // Complete doubling formula from Renes-Costello-Batina 2015 // Algorithm 3 @@ -492,14 +492,14 @@ where Ok(()) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn negate(&self) -> Result { Ok(Self::new(self.x.clone(), self.y.negate()?, self.z.clone())) } /// Computes `bits * self`, where `bits` is a little-endian /// `Boolean` representation of a scalar. - #[tracing::instrument(target = "r1cs", skip(bits))] + #[tracing::instrument(target = "gr1cs", skip(bits))] fn scalar_mul_le<'a>( &self, bits: impl Iterator>>, @@ -557,7 +557,7 @@ where infinity.select(&Self::zero(), &mul_result) } - #[tracing::instrument(target = "r1cs", skip(scalar_bits_with_bases))] + #[tracing::instrument(target = "gr1cs", skip(scalar_bits_with_bases))] fn precomputed_base_scalar_mul_le<'a, I, B>( &mut self, scalar_bits_with_bases: I, @@ -736,7 +736,7 @@ where for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean>, true_value: &Self, @@ -756,7 +756,7 @@ where F: FieldVar>, for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq(&self, other: &Self) -> Result>, SynthesisError> { let x_equal = (&self.x * &other.z).is_eq(&(&other.x * &self.z))?; let y_equal = (&self.y * &other.z).is_eq(&(&other.y * &self.z))?; @@ -766,7 +766,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_equal( &self, other: &Self, @@ -780,7 +780,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_not_equal( &self, other: &Self, @@ -926,7 +926,7 @@ where F: FieldVar>, for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> Result>>, SynthesisError> { let g = self.to_affine()?; let mut bits = g.x.to_bits_le()?; @@ -936,7 +936,7 @@ where Ok(bits) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bits_le(&self) -> Result>>, SynthesisError> { let g = self.to_affine()?; let mut bits = g.x.to_non_unique_bits_le()?; @@ -953,7 +953,7 @@ where F: FieldVar>, for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>>, SynthesisError> { let g = self.to_affine()?; let mut bytes = g.x.to_bytes_le()?; @@ -964,7 +964,7 @@ where Ok(bytes) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>>, SynthesisError> { let g = self.to_affine()?; let mut bytes = g.x.to_non_unique_bytes_le()?; @@ -990,7 +990,7 @@ mod test_sw_curve { CurveGroup, }; use ark_ff::PrimeField; - use ark_relations::r1cs::{ConstraintSystem, Result}; + use ark_relations::gr1cs::{ConstraintSystem, Result}; use ark_std::UniformRand; use num_traits::Zero; diff --git a/src/groups/curves/short_weierstrass/non_zero_affine.rs b/src/groups/curves/short_weierstrass/non_zero_affine.rs index 50448518..46a95c74 100644 --- a/src/groups/curves/short_weierstrass/non_zero_affine.rs +++ b/src/groups/curves/short_weierstrass/non_zero_affine.rs @@ -36,13 +36,13 @@ where } /// Converts self into a non-zero projective point. - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] pub fn into_projective(&self) -> ProjectiveVar { ProjectiveVar::new(self.x.clone(), self.y.clone(), F::one()) } /// Performs an addition without checking that other != ±self. - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] pub fn add_unchecked(&self, other: &Self) -> Result { if [self, other].is_constant() { let result = self.value()?.add(other.value()?).into_affine(); @@ -68,7 +68,7 @@ where /// Doubles `self`. As this is a prime order curve point, /// the output is guaranteed to not be the point at infinity. - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] pub fn double(&self) -> Result { if [self].is_constant() { let result = SWProjective::

::from(self.value()?) @@ -100,7 +100,7 @@ where /// `self.double() + other`. /// /// This follows the formulae from [\[ELM03\]](https://arxiv.org/abs/math/0208038). - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] pub fn double_and_add_unchecked(&self, other: &Self) -> Result { if [self].is_constant() || other.is_constant() { self.double()?.add_unchecked(other) @@ -131,14 +131,14 @@ where } /// Doubles `self` in place. - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] pub fn double_in_place(&mut self) -> Result<(), SynthesisError> { *self = self.double()?; Ok(()) } } -impl R1CSVar<::BasePrimeField> for NonZeroAffineVar +impl GR1CSVar<::BasePrimeField> for NonZeroAffineVar where P: SWCurveConfig, F: FieldVar::BasePrimeField>, @@ -162,7 +162,7 @@ where for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean<::BasePrimeField>, true_value: &Self, @@ -181,7 +181,7 @@ where F: FieldVar::BasePrimeField>, for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq( &self, other: &Self, @@ -192,7 +192,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_equal( &self, other: &Self, @@ -206,7 +206,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError> { self.x.enforce_equal(&other.x)?; self.y.enforce_equal(&other.y)?; @@ -214,7 +214,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_not_equal( &self, other: &Self, @@ -235,10 +235,10 @@ mod test_non_zero_affine { curves::short_weierstrass::{non_zero_affine::NonZeroAffineVar, ProjectiveVar}, CurveVar, }, - R1CSVar, + GR1CSVar, }; use ark_ec::{models::short_weierstrass::SWCurveConfig, CurveGroup}; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_std::{vec::Vec, One}; use ark_test_curves::bls12_381::{g1::Config as G1Config, Fq}; diff --git a/src/groups/curves/twisted_edwards/mod.rs b/src/groups/curves/twisted_edwards/mod.rs index 4ffcc644..72fe1d1a 100644 --- a/src/groups/curves/twisted_edwards/mod.rs +++ b/src/groups/curves/twisted_edwards/mod.rs @@ -6,7 +6,7 @@ use ark_ec::{ AdditiveGroup, AffineRepr, CurveGroup, }; use ark_ff::{BitIteratorBE, Field, One, PrimeField, Zero}; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use crate::{ convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, @@ -48,7 +48,7 @@ mod montgomery_affine_impl { use ark_ff::Field; use core::ops::Add; - impl R1CSVar> for MontgomeryAffineVar + impl GR1CSVar> for MontgomeryAffineVar where P: TECurveConfig, F: FieldVar>, @@ -82,7 +82,7 @@ mod montgomery_affine_impl { /// Converts a Twisted Edwards curve point to coordinates for the /// corresponding affine Montgomery curve point. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn from_edwards_to_coords( p: &TEAffine

, ) -> Result<(P::BaseField, P::BaseField), SynthesisError> { @@ -102,7 +102,7 @@ mod montgomery_affine_impl { /// Converts a Twisted Edwards curve point to coordinates for the /// corresponding affine Montgomery curve point. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn new_witness_from_edwards( cs: ConstraintSystemRef>, p: &TEAffine

, @@ -114,7 +114,7 @@ mod montgomery_affine_impl { } /// Converts `self` into a Twisted Edwards curve point variable. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn into_edwards(&self) -> Result, SynthesisError> { let cs = self.cs(); @@ -169,7 +169,7 @@ mod montgomery_affine_impl { { type Output = MontgomeryAffineVar; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn add(self, other: &'a Self) -> Self::Output { let cs = [&self, other].cs(); let mode = if cs.is_none() { @@ -265,7 +265,7 @@ where /// Allocates a new variable without performing an on-curve check, which is /// useful if the variable is known to be on the curve (eg., if the point /// is a constant or is a public input). - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] pub fn new_variable_omit_on_curve_check>>( cs: impl Into>>, f: impl FnOnce() -> Result, @@ -305,7 +305,7 @@ where /// which such that the first two bits are use to select one of the /// bases, while the third bit is used to conditionally negate the /// selection. - #[tracing::instrument(target = "r1cs", skip(bases, scalars))] + #[tracing::instrument(target = "gr1cs", skip(bases, scalars))] pub fn precomputed_base_3_bit_signed_digit_scalar_mul( bases: &[impl Borrow<[TEProjective

]>], scalars: &[impl Borrow<[J]>], @@ -381,7 +381,7 @@ where } } -impl R1CSVar> for AffineVar +impl GR1CSVar> for AffineVar where P: TECurveConfig, F: FieldVar>, @@ -421,7 +421,7 @@ where Ok(self.x.is_zero()? & &self.y.is_one()?) } - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable_omit_prime_order_check( cs: impl Into>>, f: impl FnOnce() -> Result, SynthesisError>, @@ -453,7 +453,7 @@ where /// /// Does so by multiplying by the prime order, and checking that the result /// is unchanged. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn enforce_prime_order(&self) -> Result<(), SynthesisError> { let r_minus_1 = (-P::ScalarField::one()).into_bigint(); @@ -470,7 +470,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn double_in_place(&mut self) -> Result<(), SynthesisError> { if self.is_constant() { let value = self.value()?; @@ -515,12 +515,12 @@ where Ok(()) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn negate(&self) -> Result { Ok(Self::new(self.x.negate()?, self.y.clone())) } - #[tracing::instrument(target = "r1cs", skip(scalar_bits_with_base_multiples))] + #[tracing::instrument(target = "gr1cs", skip(scalar_bits_with_base_multiples))] fn precomputed_base_scalar_mul_le<'a, I, B>( &mut self, scalar_bits_with_base_multiples: I, @@ -562,7 +562,7 @@ where + TwoBitLookupGadget, TableConstant = P::BaseField>, for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>>, f: impl FnOnce() -> Result, @@ -662,7 +662,7 @@ where + TwoBitLookupGadget, TableConstant = P::BaseField>, for<'a> &'a F: FieldOpsBounds<'a, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs", skip(cs, f))] + #[tracing::instrument(target = "gr1cs", skip(cs, f))] fn new_variable>>( cs: impl Into>>, f: impl FnOnce() -> Result, @@ -841,7 +841,7 @@ where for<'b> &'b F: FieldOpsBounds<'b, P::BaseField, F>, { #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditionally_select( cond: &Boolean>, true_value: &Self, @@ -860,7 +860,7 @@ where F: FieldVar>, for<'b> &'b F: FieldOpsBounds<'b, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_eq(&self, other: &Self) -> Result>, SynthesisError> { let x_equal = self.x.is_eq(&other.x)?; let y_equal = self.y.is_eq(&other.y)?; @@ -868,7 +868,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_equal( &self, other: &Self, @@ -880,7 +880,7 @@ where } #[inline] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn conditional_enforce_not_equal( &self, other: &Self, @@ -896,7 +896,7 @@ where F: FieldVar>, for<'b> &'b F: FieldOpsBounds<'b, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bits_le(&self) -> Result>>, SynthesisError> { let mut x_bits = self.x.to_bits_le()?; let y_bits = self.y.to_bits_le()?; @@ -904,7 +904,7 @@ where Ok(x_bits) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bits_le(&self) -> Result>>, SynthesisError> { let mut x_bits = self.x.to_non_unique_bits_le()?; let y_bits = self.y.to_non_unique_bits_le()?; @@ -920,7 +920,7 @@ where F: FieldVar>, for<'b> &'b F: FieldOpsBounds<'b, P::BaseField, F>, { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_bytes_le(&self) -> Result>>, SynthesisError> { let mut x_bytes = self.x.to_bytes_le()?; let y_bytes = self.y.to_bytes_le()?; @@ -928,7 +928,7 @@ where Ok(x_bytes) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_non_unique_bytes_le(&self) -> Result>>, SynthesisError> { let mut x_bytes = self.x.to_non_unique_bytes_le()?; let y_bytes = self.y.to_non_unique_bytes_le()?; diff --git a/src/groups/mod.rs b/src/groups/mod.rs index 08edbd57..460009b7 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -4,7 +4,7 @@ use crate::{ prelude::*, }; use ark_ff::PrimeField; -use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_relations::gr1cs::{Namespace, SynthesisError}; use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; use ark_ec::CurveGroup; @@ -34,7 +34,7 @@ pub trait CurveVar: + Sized + Clone + Debug - + R1CSVar + + GR1CSVar + ToBitsGadget + ToBytesGadget + EqGadget @@ -57,7 +57,7 @@ pub trait CurveVar: fn zero() -> Self; /// Returns a `Boolean` representing whether `self == Self::zero()`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn is_zero(&self) -> Result, SynthesisError> { self.is_eq(&Self::zero()) } @@ -79,7 +79,7 @@ pub trait CurveVar: fn enforce_prime_order(&self) -> Result<(), SynthesisError>; /// Computes `self + self`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn double(&self) -> Result { let mut result = self.clone(); result.double_in_place()?; @@ -94,7 +94,7 @@ pub trait CurveVar: /// Computes `bits * self`, where `bits` is a little-endian /// `Boolean` representation of a scalar. - #[tracing::instrument(target = "r1cs", skip(bits))] + #[tracing::instrument(target = "gr1cs", skip(bits))] fn scalar_mul_le<'a>( &self, bits: impl Iterator>, @@ -119,7 +119,7 @@ pub trait CurveVar: /// /// The bases are precomputed power-of-two multiples of a single /// base. - #[tracing::instrument(target = "r1cs", skip(scalar_bits_with_bases))] + #[tracing::instrument(target = "gr1cs", skip(scalar_bits_with_bases))] fn precomputed_base_scalar_mul_le<'a, I, B>( &mut self, scalar_bits_with_bases: I, @@ -148,7 +148,7 @@ pub trait CurveVar: /// Computes `Σⱼ(scalarⱼ * baseⱼ)` for all j, /// where `scalarⱼ` is a `Boolean` *little-endian* /// representation of the j-th scalar. - #[tracing::instrument(target = "r1cs", skip(bases, scalars))] + #[tracing::instrument(target = "gr1cs", skip(bases, scalars))] fn precomputed_base_multiscalar_mul_le<'a, T, I, B>( bases: &[B], scalars: I, diff --git a/src/lib.rs b/src/lib.rs index ed0b1621..279a50b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,8 +26,8 @@ pub mod macros; pub(crate) use ark_std::vec::Vec; #[doc(hidden)] -pub mod r1cs_var; -pub use r1cs_var::*; +pub mod gr1cs_var; +pub use gr1cs_var::*; /// This module contains `Boolean`, an R1CS equivalent of the `bool` type. pub mod boolean; @@ -99,18 +99,18 @@ pub mod prelude { uint32::UInt32, uint64::UInt64, uint8::UInt8, - R1CSVar, + GR1CSVar, }; } /// A utility trait to convert `Self` to `Result pub trait Assignment { /// Converts `self` to `Result`. - fn get(self) -> Result; + fn get(self) -> Result; } impl Assignment for Option { - fn get(self) -> Result { - self.ok_or(ark_relations::r1cs::SynthesisError::AssignmentMissing) + fn get(self) -> Result { + self.ok_or(ark_relations::gr1cs::SynthesisError::AssignmentMissing) } } diff --git a/src/macros.rs b/src/macros.rs index 1564f491..228c1c62 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -49,7 +49,7 @@ macro_rules! impl_bounded_ops { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces, clippy::redundant_closure_call)] fn $fn(self, other: &'a $type) -> Self::Output { ($impl)(self, other) @@ -62,7 +62,7 @@ macro_rules! impl_bounded_ops { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $fn(self, other: $type) -> Self::Output { core::ops::$trait::$fn(self, &other) @@ -75,7 +75,7 @@ macro_rules! impl_bounded_ops { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $fn(self, other: &'a $type) -> Self::Output { core::ops::$trait::$fn(&self, other) @@ -89,7 +89,7 @@ macro_rules! impl_bounded_ops { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $fn(self, other: $type) -> Self::Output { core::ops::$trait::$fn(&self, &other) @@ -101,7 +101,7 @@ macro_rules! impl_bounded_ops { $($bounds)* { - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: $type) { let result = core::ops::$trait::$fn(&*self, &other); @@ -114,7 +114,7 @@ macro_rules! impl_bounded_ops { $($bounds)* { - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: &'a $type) { let result = core::ops::$trait::$fn(&*self, other); @@ -129,7 +129,7 @@ macro_rules! impl_bounded_ops { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces, clippy::redundant_closure_call)] fn $fn(self, other: $native) -> Self::Output { ($constant_impl)(self, other) @@ -143,7 +143,7 @@ macro_rules! impl_bounded_ops { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $fn(self, other: $native) -> Self::Output { core::ops::$trait::$fn(&self, other) @@ -156,7 +156,7 @@ macro_rules! impl_bounded_ops { $($bounds)* { - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: $native) { let result = core::ops::$trait::$fn(&*self, other); @@ -196,7 +196,7 @@ macro_rules! impl_bounded_ops_diff { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces, clippy::redundant_closure_call)] fn $fn(self, other: &'a $other_type) -> Self::Output { ($impl)(self, other) @@ -209,7 +209,7 @@ macro_rules! impl_bounded_ops_diff { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $fn(self, other: $other_type) -> Self::Output { core::ops::$trait::$fn(self, &other) @@ -222,7 +222,7 @@ macro_rules! impl_bounded_ops_diff { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $fn(self, other: &'a $other_type) -> Self::Output { core::ops::$trait::$fn(&self, other) @@ -236,7 +236,7 @@ macro_rules! impl_bounded_ops_diff { { type Output = $type; - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $fn(self, other: $other_type) -> Self::Output { core::ops::$trait::$fn(&self, &other) @@ -248,7 +248,7 @@ macro_rules! impl_bounded_ops_diff { $($bounds)* { - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: $other_type) { let result = core::ops::$trait::$fn(&*self, &other); @@ -261,7 +261,7 @@ macro_rules! impl_bounded_ops_diff { $($bounds)* { - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: &'a $other_type) { let result = core::ops::$trait::$fn(&*self, other); diff --git a/src/pairing/bls12/mod.rs b/src/pairing/bls12/mod.rs index 4e7c3958..8a9c4321 100644 --- a/src/pairing/bls12/mod.rs +++ b/src/pairing/bls12/mod.rs @@ -1,4 +1,4 @@ -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use super::PairingVar as PG; @@ -17,7 +17,7 @@ type Fp2V

= Fp2Var<

::Fp2Config>; impl PairingVar

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

, Fp2V

), @@ -49,7 +49,7 @@ impl PairingVar

{ } } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn exp_by_x(f: &Fp12Var) -> Result, SynthesisError> { let mut result = f.optimized_cyclotomic_exp(P::X)?; if P::X_IS_NEGATIVE { @@ -66,7 +66,7 @@ impl PG> for PairingVar

{ type G2PreparedVar = G2PreparedVar

; type GTVar = Fp12Var; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn miller_loop( ps: &[Self::G1PreparedVar], qs: &[Self::G2PreparedVar], @@ -98,7 +98,7 @@ impl PG> for PairingVar

{ Ok(f) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn final_exponentiation(f: &Self::GTVar) -> Result { // Computing the final exponentation following // https://eprint.iacr.org/2016/130.pdf. @@ -155,12 +155,12 @@ impl PG> for PairingVar

{ }) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn prepare_g1(p: &Self::G1Var) -> Result { Self::G1PreparedVar::from_group_var(p) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn prepare_g2(q: &Self::G2Var) -> Result { Self::G2PreparedVar::from_group_var(q) } diff --git a/src/pairing/mnt4/mod.rs b/src/pairing/mnt4/mod.rs index 07fcab0b..7eceefec 100644 --- a/src/pairing/mnt4/mod.rs +++ b/src/pairing/mnt4/mod.rs @@ -1,4 +1,4 @@ -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use super::PairingVar as PG; @@ -22,7 +22,7 @@ type Fp4G

= Fp4Var<

::Fp4Config>; pub type GTVar

= Fp4G

; impl PairingVar

{ - #[tracing::instrument(target = "r1cs", skip(r))] + #[tracing::instrument(target = "gr1cs", skip(r))] pub(crate) fn doubling_step_for_flipped_miller_loop( r: &G2ProjectiveExtendedVar

, ) -> Result<(G2ProjectiveExtendedVar

, AteDoubleCoefficientsVar

), SynthesisError> { @@ -58,7 +58,7 @@ impl PairingVar

{ Ok((r2, coeff)) } - #[tracing::instrument(target = "r1cs", skip(r))] + #[tracing::instrument(target = "gr1cs", skip(r))] pub(crate) fn mixed_addition_step_for_flipped_miller_loop( x: &Fp2G

, y: &Fp2G

, @@ -91,7 +91,7 @@ impl PairingVar

{ Ok((r2, coeff)) } - #[tracing::instrument(target = "r1cs", skip(p, q))] + #[tracing::instrument(target = "gr1cs", skip(p, q))] pub(crate) fn ate_miller_loop( p: &G1PreparedVar

, q: &G2PreparedVar

, @@ -153,7 +153,7 @@ impl PairingVar

{ Ok(f) } - #[tracing::instrument(target = "r1cs", skip(value))] + #[tracing::instrument(target = "gr1cs", skip(value))] pub(crate) fn final_exponentiation(value: &Fp4G

) -> Result, SynthesisError> { let value_inv = value.inverse()?; let value_to_first_chunk = Self::final_exponentiation_first_chunk(value, &value_inv)?; @@ -161,7 +161,7 @@ impl PairingVar

{ Self::final_exponentiation_last_chunk(&value_to_first_chunk, &value_inv_to_first_chunk) } - #[tracing::instrument(target = "r1cs", skip(elt, elt_inv))] + #[tracing::instrument(target = "gr1cs", skip(elt, elt_inv))] fn final_exponentiation_first_chunk( elt: &Fp4G

, elt_inv: &Fp4G

, @@ -174,7 +174,7 @@ impl PairingVar

{ Ok(elt_q2 * elt_inv) } - #[tracing::instrument(target = "r1cs", skip(elt, elt_inv))] + #[tracing::instrument(target = "gr1cs", skip(elt, elt_inv))] fn final_exponentiation_last_chunk( elt: &Fp4G

, elt_inv: &Fp4G

, @@ -203,7 +203,7 @@ impl PG> for PairingVar

{ type G2PreparedVar = G2PreparedVar

; type GTVar = GTVar

; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn miller_loop( ps: &[Self::G1PreparedVar], qs: &[Self::G2PreparedVar], @@ -216,17 +216,17 @@ impl PG> for PairingVar

{ Ok(result) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn final_exponentiation(r: &Self::GTVar) -> Result { Self::final_exponentiation(r) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn prepare_g1(p: &Self::G1Var) -> Result { Self::G1PreparedVar::from_group_var(p) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn prepare_g2(q: &Self::G2Var) -> Result { Self::G2PreparedVar::from_group_var(q) } diff --git a/src/pairing/mnt6/mod.rs b/src/pairing/mnt6/mod.rs index 27252f9b..3af12408 100644 --- a/src/pairing/mnt6/mod.rs +++ b/src/pairing/mnt6/mod.rs @@ -1,4 +1,4 @@ -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use super::PairingVar as PG; @@ -21,7 +21,7 @@ type Fp6G

= Fp6Var<

::Fp6Config>; pub type GTVar

= Fp6G

; impl PairingVar

{ - #[tracing::instrument(target = "r1cs", skip(r))] + #[tracing::instrument(target = "gr1cs", skip(r))] pub(crate) fn doubling_step_for_flipped_miller_loop( r: &G2ProjectiveExtendedVar

, ) -> Result<(G2ProjectiveExtendedVar

, AteDoubleCoefficientsVar

), SynthesisError> { @@ -52,7 +52,7 @@ impl PairingVar

{ Ok((r2, coeff)) } - #[tracing::instrument(target = "r1cs", skip(r))] + #[tracing::instrument(target = "gr1cs", skip(r))] pub(crate) fn mixed_addition_step_for_flipped_miller_loop( x: &Fp3G

, y: &Fp3G

, @@ -85,7 +85,7 @@ impl PairingVar

{ Ok((r2, coeff)) } - #[tracing::instrument(target = "r1cs", skip(p, q))] + #[tracing::instrument(target = "gr1cs", skip(p, q))] pub(crate) fn ate_miller_loop( p: &G1PreparedVar

, q: &G2PreparedVar

, @@ -148,7 +148,7 @@ impl PairingVar

{ Ok(f) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub(crate) fn final_exponentiation(value: &Fp6G

) -> Result, SynthesisError> { let value_inv = value.inverse()?; let value_to_first_chunk = Self::final_exponentiation_first_chunk(value, &value_inv)?; @@ -156,7 +156,7 @@ impl PairingVar

{ Self::final_exponentiation_last_chunk(&value_to_first_chunk, &value_inv_to_first_chunk) } - #[tracing::instrument(target = "r1cs", skip(elt, elt_inv))] + #[tracing::instrument(target = "gr1cs", skip(elt, elt_inv))] fn final_exponentiation_first_chunk( elt: &Fp6G

, elt_inv: &Fp6G

, @@ -173,7 +173,7 @@ impl PairingVar

{ Ok(alpha * &elt_q3_over_elt) } - #[tracing::instrument(target = "r1cs", skip(elt, elt_inv))] + #[tracing::instrument(target = "gr1cs", skip(elt, elt_inv))] fn final_exponentiation_last_chunk( elt: &Fp6G

, elt_inv: &Fp6G

, @@ -198,7 +198,7 @@ impl PG> for PairingVar

{ type G2PreparedVar = G2PreparedVar

; type GTVar = GTVar

; - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn miller_loop( ps: &[Self::G1PreparedVar], qs: &[Self::G2PreparedVar], @@ -211,17 +211,17 @@ impl PG> for PairingVar

{ Ok(result) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn final_exponentiation(r: &Self::GTVar) -> Result { Self::final_exponentiation(r) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn prepare_g1(p: &Self::G1Var) -> Result { Self::G1PreparedVar::from_group_var(p) } - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn prepare_g2(q: &Self::G2Var) -> Result { Self::G2PreparedVar::from_group_var(q) } diff --git a/src/pairing/mod.rs b/src/pairing/mod.rs index ab081fb8..07746199 100644 --- a/src/pairing/mod.rs +++ b/src/pairing/mod.rs @@ -1,6 +1,6 @@ use crate::{convert::ToBytesGadget, prelude::*}; use ark_ec::pairing::Pairing; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use core::fmt::Debug; /// This module implements pairings for BLS12 bilinear groups. @@ -53,7 +53,7 @@ pub trait PairingVar { fn final_exponentiation(p: &Self::GTVar) -> Result; /// Computes a pairing over `p` and `q`. - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn pairing( p: Self::G1PreparedVar, q: Self::G2PreparedVar, @@ -64,7 +64,7 @@ pub trait PairingVar { /// Computes a product of pairings over the elements in `p` and `q`. #[must_use] - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn product_of_pairings( p: &[Self::G1PreparedVar], q: &[Self::G2PreparedVar], diff --git a/src/poly/domain/mod.rs b/src/poly/domain/mod.rs index ebb72127..f33f4364 100644 --- a/src/poly/domain/mod.rs +++ b/src/poly/domain/mod.rs @@ -4,7 +4,7 @@ use crate::{ fields::{fp::FpVar, FieldVar}, }; use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::vec::Vec; pub mod vanishing_poly; @@ -126,12 +126,12 @@ fn truncate_to_coset_index( mod tests { use crate::prelude::*; use ark_ff::PrimeField; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_std::{rand::Rng, test_rng}; use crate::{ alloc::AllocVar, convert::ToBitsGadget, fields::fp::FpVar, poly::domain::Radix2DomainVar, - R1CSVar, + GR1CSVar, }; fn test_query_coset_template() { diff --git a/src/poly/domain/vanishing_poly.rs b/src/poly/domain/vanishing_poly.rs index 817f7bf5..b338c394 100644 --- a/src/poly/domain/vanishing_poly.rs +++ b/src/poly/domain/vanishing_poly.rs @@ -1,6 +1,6 @@ use crate::fields::{fp::FpVar, FieldVar}; use ark_ff::{Field, PrimeField}; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::ops::Sub; /// Struct describing vanishing polynomial for a multiplicative coset H where @@ -57,9 +57,9 @@ impl VanishingPolynomial { mod tests { use crate::{ alloc::AllocVar, fields::fp::FpVar, poly::domain::vanishing_poly::VanishingPolynomial, - R1CSVar, + GR1CSVar, }; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_std::{test_rng, UniformRand}; use ark_test_curves::bls12_381::Fr; diff --git a/src/poly/evaluations/univariate/lagrange_interpolator.rs b/src/poly/evaluations/univariate/lagrange_interpolator.rs index 252f3d55..bd9b36a3 100644 --- a/src/poly/evaluations/univariate/lagrange_interpolator.rs +++ b/src/poly/evaluations/univariate/lagrange_interpolator.rs @@ -100,7 +100,7 @@ mod tests { domain::Radix2DomainVar, evaluations::univariate::lagrange_interpolator::LagrangeInterpolator, }, - R1CSVar, + GR1CSVar, }; use ark_ff::{FftField, Field, One}; use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial, Polynomial}; diff --git a/src/poly/evaluations/univariate/mod.rs b/src/poly/evaluations/univariate/mod.rs index c05cc092..0df6ca39 100644 --- a/src/poly/evaluations/univariate/mod.rs +++ b/src/poly/evaluations/univariate/mod.rs @@ -8,10 +8,10 @@ use crate::{ domain::Radix2DomainVar, evaluations::univariate::lagrange_interpolator::LagrangeInterpolator, }, - R1CSVar, + GR1CSVar, }; use ark_ff::{batch_inversion, PrimeField}; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}, vec::Vec, @@ -368,11 +368,11 @@ mod tests { alloc::AllocVar, fields::{fp::FpVar, FieldVar}, poly::{domain::Radix2DomainVar, evaluations::univariate::EvaluationsVar}, - R1CSVar, + GR1CSVar, }; use ark_ff::{FftField, Field, One, UniformRand}; use ark_poly::{polynomial::univariate::DensePolynomial, DenseUVPolynomial, Polynomial}; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_std::test_rng; use ark_test_curves::bls12_381::Fr; diff --git a/src/poly/polynomial/univariate/dense.rs b/src/poly/polynomial/univariate/dense.rs index 53488963..e87b5151 100644 --- a/src/poly/polynomial/univariate/dense.rs +++ b/src/poly/polynomial/univariate/dense.rs @@ -1,5 +1,5 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use crate::fields::{fp::FpVar, FieldVar}; use ark_std::vec::Vec; @@ -43,10 +43,10 @@ impl DensePolynomialVar { mod tests { use crate::{ alloc::AllocVar, fields::fp::FpVar, - poly::polynomial::univariate::dense::DensePolynomialVar, R1CSVar, + poly::polynomial::univariate::dense::DensePolynomialVar, GR1CSVar, }; use ark_poly::{polynomial::univariate::DensePolynomial, DenseUVPolynomial, Polynomial}; - use ark_relations::r1cs::ConstraintSystem; + use ark_relations::gr1cs::ConstraintSystem; use ark_std::{test_rng, vec::Vec, UniformRand}; use ark_test_curves::bls12_381::Fr; diff --git a/src/select.rs b/src/select.rs index 528fc90d..da3ceb3d 100644 --- a/src/select.rs +++ b/src/select.rs @@ -1,6 +1,6 @@ use crate::prelude::*; use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::vec::Vec; /// Generates constraints for selecting between one of two values. pub trait CondSelectGadget: Sized + Clone { diff --git a/src/uint/add/mod.rs b/src/uint/add/mod.rs index d5eb7563..dfe48307 100644 --- a/src/uint/add/mod.rs +++ b/src/uint/add/mod.rs @@ -13,7 +13,7 @@ impl UInt { /// # Panics /// /// This method panics if the result of addition could possibly exceed the field size. - #[tracing::instrument(target = "r1cs", skip(operands, adder))] + #[tracing::instrument(target = "gr1cs", skip(operands, adder))] fn add_many_helper( operands: &[Self], adder: impl Fn(T, T) -> T, diff --git a/src/uint/add/saturating.rs b/src/uint/add/saturating.rs index 62c393eb..a38b3736 100644 --- a/src/uint/add/saturating.rs +++ b/src/uint/add/saturating.rs @@ -1,8 +1,8 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use crate::uint::*; -use crate::{boolean::Boolean, R1CSVar}; +use crate::{boolean::Boolean, GR1CSVar}; impl UInt { /// Compute `*self = self.wrapping_add(other)`. @@ -22,7 +22,7 @@ impl UInt { /// Computes `operands[0].wrapping_add(operands[1]).wrapping_add(operands[2])...`. /// /// The user must ensure that overflow does not occur. - #[tracing::instrument(target = "r1cs", skip(operands))] + #[tracing::instrument(target = "gr1cs", skip(operands))] pub fn saturating_add_many(operands: &[Self]) -> Result where F: PrimeField, @@ -60,7 +60,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/add/wrapping.rs b/src/uint/add/wrapping.rs index 5dfe4496..e9ac9c46 100644 --- a/src/uint/add/wrapping.rs +++ b/src/uint/add/wrapping.rs @@ -1,8 +1,8 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use crate::uint::*; -use crate::R1CSVar; +use crate::GR1CSVar; impl UInt { /// Compute `*self = self.wrapping_add(other)`. @@ -22,7 +22,7 @@ impl UInt { /// Computes `operands[0].wrapping_add(operands[1]).wrapping_add(operands[2])...`. /// /// The user must ensure that overflow does not occur. - #[tracing::instrument(target = "r1cs", skip(operands))] + #[tracing::instrument(target = "gr1cs", skip(operands))] pub fn wrapping_add_many(operands: &[Self]) -> Result where F: PrimeField, @@ -49,7 +49,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/and.rs b/src/uint/and.rs index cfe711a2..9b0e31d2 100644 --- a/src/uint/and.rs +++ b/src/uint/and.rs @@ -1,5 +1,5 @@ use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::BitAnd, ops::BitAndAssign}; use super::*; @@ -28,10 +28,10 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd for &'a UInt Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -44,7 +44,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd for &'a UInt Self::Output { self._and(other).unwrap() } @@ -58,10 +58,10 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a Self> for UInt Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -74,7 +74,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a Self> for UInt Self::Output { self._and_in_place(other).unwrap(); self @@ -90,10 +90,10 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd> for &'a UI /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -106,7 +106,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd> for &'a UI /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: UInt) -> Self::Output { other & self } @@ -121,10 +121,10 @@ impl BitAnd for UInt { /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -137,7 +137,7 @@ impl BitAnd for UInt { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: Self) -> Self::Output { self & &other } @@ -146,7 +146,7 @@ impl BitAnd for UInt { impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: T) -> Self::Output { self & UInt::constant(other) } @@ -155,7 +155,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd for UInt { impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a T> for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: &'a T) -> Self::Output { self & UInt::constant(*other) } @@ -164,7 +164,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a T> for UInt impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a T> for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: &'a T) -> Self::Output { self & UInt::constant(*other) } @@ -173,7 +173,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a T> for &'a UInt BitAnd for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand(self, other: T) -> Self::Output { self & UInt::constant(other) } @@ -186,10 +186,10 @@ impl BitAndAssign for UInt /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -203,7 +203,7 @@ impl BitAndAssign for UInt /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand_assign(&mut self, other: Self) { self._and_in_place(&other).unwrap(); } @@ -216,10 +216,10 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a Self> for UInt< /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -233,21 +233,21 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a Self> for UInt< /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand_assign(&mut self, other: &'a Self) { self._and_in_place(&other).unwrap(); } } impl BitAndAssign for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand_assign(&mut self, other: T) { *self &= &Self::constant(other); } } impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a T> for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitand_assign(&mut self, other: &'a T) { *self &= &Self::constant(*other); } @@ -260,7 +260,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive_both, run_binary_random_both}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/cmp.rs b/src/uint/cmp.rs index 5a01b169..4c037e44 100644 --- a/src/uint/cmp.rs +++ b/src/uint/cmp.rs @@ -23,7 +23,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/convert.rs b/src/uint/convert.rs index 242c3ad8..8a7e4e65 100644 --- a/src/uint/convert.rs +++ b/src/uint/convert.rs @@ -36,10 +36,10 @@ impl UInt { /// `UInt`. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -58,7 +58,7 @@ impl UInt { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] pub fn from_bits_le(bits: &[Boolean]) -> Self { assert_eq!(bits.len(), N); let bits = <&[Boolean; N]>::try_from(bits).unwrap().clone(); @@ -76,10 +76,10 @@ impl UInt { /// Converts a big-endian list of bytes into a `UInt`. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -106,10 +106,10 @@ impl UInt { /// Converts a little-endian byte order list of bytes into a `UInt`. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -161,7 +161,7 @@ impl ToBitsGadget for [UInt] impl ToBytesGadget for UInt { - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] fn to_bytes_le(&self) -> Result>, SynthesisError> { Ok(self .to_bits_le()? @@ -177,7 +177,7 @@ mod tests { use crate::{ prelude::EqGadget, uint::test_utils::{run_unary_exhaustive, run_unary_random}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/eq.rs b/src/uint/eq.rs index 1b7c386f..dbe074be 100644 --- a/src/uint/eq.rs +++ b/src/uint/eq.rs @@ -1,5 +1,5 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::vec::Vec; use crate::boolean::Boolean; @@ -10,7 +10,7 @@ use super::*; impl EqGadget for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn is_eq(&self, other: &Self) -> Result, SynthesisError> { let chunk_size = usize::try_from(ConstraintF::MODULUS_BIT_SIZE - 1).unwrap(); let chunks_are_eq = self @@ -26,7 +26,7 @@ impl EqGadget Boolean::kary_and(&chunks_are_eq) } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_equal( &self, other: &Self, @@ -45,7 +45,7 @@ impl EqGadget Ok(()) } - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn conditional_enforce_not_equal( &self, other: &Self, @@ -72,7 +72,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/mod.rs b/src/uint/mod.rs index 1544f24a..91fc8b33 100644 --- a/src/uint/mod.rs +++ b/src/uint/mod.rs @@ -1,7 +1,7 @@ use ark_ff::{Field, PrimeField}; use core::{borrow::Borrow, convert::TryFrom, fmt::Debug}; -use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use crate::{boolean::Boolean, prelude::*, Assignment, Vec}; @@ -34,7 +34,7 @@ pub struct UInt { pub value: Option, } -impl R1CSVar for UInt { +impl GR1CSVar for UInt { type Value = T; fn cs(&self) -> ConstraintSystemRef { @@ -62,10 +62,10 @@ impl UInt { /// This *does not* create new variables or constraints. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -96,10 +96,10 @@ impl UInt { /// /// This *does not* create any new variables or constraints. /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); diff --git a/src/uint/not.rs b/src/uint/not.rs index 8457f2ec..d20186f0 100644 --- a/src/uint/not.rs +++ b/src/uint/not.rs @@ -1,5 +1,5 @@ use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::ops::Not; use super::*; @@ -27,10 +27,10 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> Not for &'a UInt { /// If `self` is a constant, then this method *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -42,7 +42,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> Not for &'a UInt { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] fn not(self) -> Self::Output { self._not().unwrap() } @@ -56,10 +56,10 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> Not for UInt { /// If `self` is a constant, then this method *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -71,7 +71,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> Not for UInt { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] fn not(mut self) -> Self::Output { self._not_in_place().unwrap(); self @@ -85,7 +85,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_unary_exhaustive, run_unary_random}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/or.rs b/src/uint/or.rs index 0ca124ec..0a608343 100644 --- a/src/uint/or.rs +++ b/src/uint/or.rs @@ -1,5 +1,5 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::BitOr, ops::BitOrAssign}; use super::{PrimUInt, UInt}; @@ -29,10 +29,10 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for &'a UInt Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -45,7 +45,7 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for &'a UInt Self::Output { self._or(other).unwrap() } @@ -54,7 +54,7 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for &'a UInt BitOr<&'a Self> for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(mut self, other: &Self) -> Self::Output { self._or_in_place(&other).unwrap(); self @@ -64,7 +64,7 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a Self> for UInt BitOr> for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: UInt) -> Self::Output { other | self } @@ -73,7 +73,7 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr> for &' impl BitOr for UInt { type Output = Self; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: Self) -> Self::Output { self | &other } @@ -82,7 +82,7 @@ impl BitOr for UInt { impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: T) -> Self::Output { self | &UInt::constant(other) } @@ -91,7 +91,7 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for UInt impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a T> for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: &'a T) -> Self::Output { self | &UInt::constant(*other) } @@ -100,7 +100,7 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a T> for UInt BitOr<&'a T> for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: &'a T) -> Self::Output { self | &UInt::constant(*other) } @@ -109,7 +109,7 @@ impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a T> for &'a UInt BitOr for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor(self, other: T) -> Self::Output { self | &UInt::constant(other) } @@ -122,10 +122,10 @@ impl BitOrAssign for UInt Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -139,28 +139,28 @@ impl BitOrAssign for UInt BitOrAssign<&'a Self> for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor_assign(&mut self, other: &'a Self) { self._or_in_place(other).unwrap(); } } impl BitOrAssign for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor_assign(&mut self, other: T) { *self |= &UInt::constant(other); } } impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<&'a T> for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitor_assign(&mut self, other: &'a T) { *self |= &UInt::constant(*other); } @@ -173,7 +173,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive_both, run_binary_random_both}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/rotate.rs b/src/uint/rotate.rs index 62cd39f3..1e806b40 100644 --- a/src/uint/rotate.rs +++ b/src/uint/rotate.rs @@ -5,10 +5,10 @@ impl UInt { /// /// # Examples /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -20,7 +20,7 @@ impl UInt { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] pub fn rotate_right(&self, by: usize) -> Self { let mut result = self.clone(); result.rotate_right_in_place(by); @@ -30,10 +30,10 @@ impl UInt { /// /// # Examples /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -46,7 +46,7 @@ impl UInt { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] pub fn rotate_right_in_place(&mut self, by: usize) { let by = by % N; // `[T]::rotate_left` corresponds to a `rotate_right` of the bits. @@ -58,10 +58,10 @@ impl UInt { /// /// # Examples /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -73,7 +73,7 @@ impl UInt { /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self))] + #[tracing::instrument(target = "gr1cs", skip(self))] pub fn rotate_left(&self, by: usize) -> Self { let mut result = self.clone(); result.rotate_left_in_place(by); @@ -84,10 +84,10 @@ impl UInt { /// /// # Examples /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -115,7 +115,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_unary_exhaustive, run_unary_random}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/select.rs b/src/uint/select.rs index 6c061fe2..8d86fbd8 100644 --- a/src/uint/select.rs +++ b/src/uint/select.rs @@ -4,7 +4,7 @@ use crate::select::CondSelectGadget; impl CondSelectGadget for UInt { - #[tracing::instrument(target = "r1cs", skip(cond, true_value, false_value))] + #[tracing::instrument(target = "gr1cs", skip(cond, true_value, false_value))] fn conditionally_select( cond: &Boolean, true_value: &Self, diff --git a/src/uint/shl.rs b/src/uint/shl.rs index 4382ce64..c70742b7 100644 --- a/src/uint/shl.rs +++ b/src/uint/shl.rs @@ -1,5 +1,5 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::Shl, ops::ShlAssign}; use crate::boolean::Boolean; @@ -31,10 +31,10 @@ impl Shl for UInt< /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -47,7 +47,7 @@ impl Shl for UInt< /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn shl(self, other: T2) -> Self::Output { self._shl_u128(other.into()).unwrap() } @@ -56,7 +56,7 @@ impl Shl for UInt< impl<'a, const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shl for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn shl(self, other: T2) -> Self::Output { self._shl_u128(other.into()).unwrap() } @@ -69,10 +69,10 @@ impl ShlAssign for /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -86,7 +86,7 @@ impl ShlAssign for /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn shl_assign(&mut self, other: T2) { let result = self._shl_u128(other.into()).unwrap(); *self = result; @@ -100,7 +100,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive_native_only, run_binary_random_native_only}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/shr.rs b/src/uint/shr.rs index 7368a3fb..bfb367ee 100644 --- a/src/uint/shr.rs +++ b/src/uint/shr.rs @@ -1,5 +1,5 @@ use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::Shr, ops::ShrAssign}; use crate::boolean::Boolean; @@ -31,10 +31,10 @@ impl Shr for UInt< /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -47,7 +47,7 @@ impl Shr for UInt< /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn shr(self, other: T2) -> Self::Output { self._shr_u128(other.into()).unwrap() } @@ -56,7 +56,7 @@ impl Shr for UInt< impl<'a, const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shr for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn shr(self, other: T2) -> Self::Output { self._shr_u128(other.into()).unwrap() } @@ -69,10 +69,10 @@ impl ShrAssign for /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -86,7 +86,7 @@ impl ShrAssign for /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn shr_assign(&mut self, other: T2) { let result = self._shr_u128(other.into()).unwrap(); *self = result; @@ -100,7 +100,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive_native_only, run_binary_random_native_only}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint/test_utils.rs b/src/uint/test_utils.rs index 4987a2a7..f77b3d1a 100644 --- a/src/uint/test_utils.rs +++ b/src/uint/test_utils.rs @@ -1,4 +1,4 @@ -use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; +use ark_relations::gr1cs::{ConstraintSystem, SynthesisError}; use std::ops::RangeInclusive; use crate::test_utils::{self, modes}; diff --git a/src/uint/xor.rs b/src/uint/xor.rs index 56546ba7..8b2479fc 100644 --- a/src/uint/xor.rs +++ b/src/uint/xor.rs @@ -1,5 +1,5 @@ use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; +use ark_relations::gr1cs::SynthesisError; use ark_std::{ops::BitXor, ops::BitXorAssign}; use super::*; @@ -28,10 +28,10 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for &'a UInt Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -44,7 +44,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for &'a UInt Self::Output { self._xor(other).unwrap() } @@ -53,7 +53,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for &'a UInt BitXor<&'a Self> for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(mut self, other: &Self) -> Self::Output { self._xor_in_place(&other).unwrap(); self @@ -63,7 +63,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a Self> for UInt BitXor> for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: UInt) -> Self::Output { other ^ self } @@ -72,7 +72,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor> for &'a UI impl BitXor for UInt { type Output = Self; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: Self) -> Self::Output { self ^ &other } @@ -81,7 +81,7 @@ impl BitXor for UInt { impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: T) -> Self::Output { self ^ &UInt::constant(other) } @@ -90,7 +90,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for UInt { impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a T> for UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: &'a T) -> Self::Output { self ^ &UInt::constant(*other) } @@ -99,7 +99,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a T> for UInt impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a T> for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: &'a T) -> Self::Output { self ^ UInt::constant(*other) } @@ -108,7 +108,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a T> for &'a UInt BitXor for &'a UInt { type Output = UInt; - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor(self, other: T) -> Self::Output { self ^ UInt::constant(other) } @@ -121,10 +121,10 @@ impl BitXorAssign for UInt /// *does not* create any constraints or variables. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -138,28 +138,28 @@ impl BitXorAssign for UInt /// # Ok(()) /// # } /// ``` - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor_assign(&mut self, other: Self) { self._xor_in_place(&other).unwrap(); } } impl<'a, const N: usize, T: PrimUInt, F: Field> BitXorAssign<&'a Self> for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor_assign(&mut self, other: &'a Self) { self._xor_in_place(other).unwrap(); } } impl BitXorAssign for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor_assign(&mut self, other: T) { *self ^= Self::constant(other); } } impl<'a, const N: usize, T: PrimUInt, F: Field> BitXorAssign<&'a T> for UInt { - #[tracing::instrument(target = "r1cs", skip(self, other))] + #[tracing::instrument(target = "gr1cs", skip(self, other))] fn bitxor_assign(&mut self, other: &'a T) { *self ^= Self::constant(*other); } @@ -172,7 +172,7 @@ mod tests { alloc::{AllocVar, AllocationMode}, prelude::EqGadget, uint::test_utils::{run_binary_exhaustive_both, run_binary_random_both}, - R1CSVar, + GR1CSVar, }; use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; diff --git a/src/uint8.rs b/src/uint8.rs index 1f952de4..09d2fd5b 100644 --- a/src/uint8.rs +++ b/src/uint8.rs @@ -1,6 +1,6 @@ use ark_ff::{Field, PrimeField, ToConstraintField}; -use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_relations::gr1cs::{Namespace, SynthesisError}; use crate::{ convert::{ToBitsGadget, ToConstraintFieldGadget}, @@ -21,10 +21,10 @@ impl UInt8 { /// verifier time and verification key size. /// /// ``` - /// # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> { + /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { /// // We'll use the BLS12-381 scalar field for our constraints. /// use ark_test_curves::bls12_381::Fr; - /// use ark_relations::r1cs::*; + /// use ark_relations::gr1cs::*; /// use ark_r1cs_std::prelude::*; /// /// let cs = ConstraintSystem::::new_ref(); @@ -77,7 +77,7 @@ impl UInt8 { /// This is the gadget counterpart to the `[u8]` implementation of /// [`ToConstraintField``]. impl ToConstraintFieldGadget for [UInt8] { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { let max_size = ((ConstraintF::MODULUS_BIT_SIZE - 1) / 8) as usize; self.chunks(max_size) @@ -87,7 +87,7 @@ impl ToConstraintFieldGadget for [UInt8 ToConstraintFieldGadget for Vec> { - #[tracing::instrument(target = "r1cs")] + #[tracing::instrument(target = "gr1cs")] fn to_constraint_field(&self) -> Result>, SynthesisError> { self.as_slice().to_constraint_field() } @@ -106,7 +106,7 @@ mod test { Vec, }; use ark_ff::{PrimeField, ToConstraintField}; - use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; + use ark_relations::gr1cs::{ConstraintSystem, SynthesisError}; use ark_std::rand::{distributions::Uniform, Rng}; use ark_test_curves::bls12_381::Fr; diff --git a/tests/arithmetic_tests.rs b/tests/arithmetic_tests.rs index 83d72828..ac0d8c51 100644 --- a/tests/arithmetic_tests.rs +++ b/tests/arithmetic_tests.rs @@ -13,9 +13,9 @@ use ark_r1cs_std::{ emulated_fp::{AllocatedEmulatedFpVar, EmulatedFpVar}, FieldVar, }, - R1CSVar, + GR1CSVar, }; -use ark_relations::r1cs::{ConstraintSystem, ConstraintSystemRef}; +use ark_relations::gr1cs::{ConstraintSystem, ConstraintSystemRef}; use ark_std::rand::RngCore; #[cfg(not(ci))] diff --git a/tests/from_test.rs b/tests/from_test.rs index ddfd08cb..836d48aa 100644 --- a/tests/from_test.rs +++ b/tests/from_test.rs @@ -1,9 +1,9 @@ use ark_r1cs_std::{ alloc::AllocVar, fields::emulated_fp::{EmulatedFpVar, MulResultVar}, - R1CSVar, + GR1CSVar, }; -use ark_relations::r1cs::ConstraintSystem; +use ark_relations::gr1cs::ConstraintSystem; use ark_std::UniformRand; #[test] diff --git a/tests/to_constraint_field_test.rs b/tests/to_constraint_field_test.rs index 75c79c34..53bd7835 100644 --- a/tests/to_constraint_field_test.rs +++ b/tests/to_constraint_field_test.rs @@ -1,7 +1,7 @@ use ark_r1cs_std::{ - alloc::AllocVar, convert::ToConstraintFieldGadget, fields::emulated_fp::EmulatedFpVar, R1CSVar, + alloc::AllocVar, convert::ToConstraintFieldGadget, fields::emulated_fp::EmulatedFpVar, GR1CSVar, }; -use ark_relations::r1cs::ConstraintSystem; +use ark_relations::gr1cs::ConstraintSystem; #[test] fn to_constraint_field_test() { From 7c85546f84c8b74d0dc20f587a70dddf373dc5a1 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Thu, 16 Jan 2025 16:57:15 -0500 Subject: [PATCH 02/11] tweak --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 3be3b013..686b87e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ ark-mnt6-298 = { version = "0.5.0", default-features = false } ark-mnt6-753 = { version = "0.5.0", default-features = false } ark-pallas = { version = "0.5.0", features = ["curve"], default-features = false } ark-bn254 = { version = "0.5.0", features = ["curve"], default-features = false } +tracing-subscriber = { version = "0.3", default-features = true } [features] default = ["std"] @@ -76,3 +77,5 @@ debug = true [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } +[patch.crates-io] +ark-relations = { git = "https://github.com/alireza-shirzad/snark.git" } \ No newline at end of file From 9f3ee2cb04ef99062f9df43329fbc65dcec842c9 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Thu, 16 Jan 2025 17:00:51 -0500 Subject: [PATCH 03/11] tweak --- Cargo.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 686b87e6..305a5b1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ resolver = "2" ark-ff = { version = "0.5.0", default-features = false } ark-ec = { version = "0.5.0", default-features = false } ark-std = { version = "0.5.0", default-features = false } -ark-relations = { path = "../snark/relations", default-features = true } +ark-relations = { git = "https://github.com/alireza-shirzad/snark.git", default-features = true } educe = "0.6.0" tracing = { version = "0.1", default-features = false, features = [ "attributes" ] } @@ -76,6 +76,3 @@ debug = true [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } - -[patch.crates-io] -ark-relations = { git = "https://github.com/alireza-shirzad/snark.git" } \ No newline at end of file From 0084eb326f957422b55c5b4a47acb148afd613fd Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Fri, 31 Jan 2025 22:05:29 -0500 Subject: [PATCH 04/11] relations crate fixed --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 305a5b1e..2e84bdfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ resolver = "2" ark-ff = { version = "0.5.0", default-features = false } ark-ec = { version = "0.5.0", default-features = false } ark-std = { version = "0.5.0", default-features = false } -ark-relations = { git = "https://github.com/alireza-shirzad/snark.git", default-features = true } +ark-relations = { version = "0.5.0", default-features = true } educe = "0.6.0" tracing = { version = "0.1", default-features = false, features = [ "attributes" ] } @@ -76,3 +76,6 @@ debug = true [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } + +[patch.crates-io] +ark-relations = { git = "https://github.com/arkworks-rs/snark.git"} \ No newline at end of file From 35de2dfa6994133d9701cc87987232a0d142e313 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Thu, 20 Feb 2025 10:13:40 -0500 Subject: [PATCH 05/11] added the migration script --- scripts/migrate.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 scripts/migrate.sh diff --git a/scripts/migrate.sh b/scripts/migrate.sh new file mode 100755 index 00000000..92de3cf5 --- /dev/null +++ b/scripts/migrate.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# ----------------------------------------------------------------------------- +# rename_r1cs.sh +# +# Recursively: +# 1. Renames .rs filenames: R1CS->GR1CS, r1cs->gr1cs (except those with r1cs_std). +# 2. In .rs file contents, replaces R1CS->GR1CS, r1cs->gr1cs (except lines with r1cs_std). +# 3. Finally replaces enforce_constraint->enforce_r1cs_constraint (except lines with r1cs_std). +# ----------------------------------------------------------------------------- + +# --- Detect which 'sed' in-place flag to use (GNU vs BSD/macOS) --- +# On macOS, 'sed -i' requires a backup extension parameter (can be empty ''). +# On GNU sed, 'sed -i' is fine without extra args. +if sed --version 2>/dev/null | grep -q "GNU"; then + # GNU sed + SED_INPLACE=(-i) +else + # BSD/macOS sed + SED_INPLACE=(-i '') +fi + +echo "###############################################" +echo "# ⚠️ Cautious: RUN THIS SCRIPT ONLY ONCE! DO NOT RUN IT TWICE! #" +echo "# Make sure you have a backup before running. #" +echo "###############################################" +echo +read -p "Are you sure you want to continue? (yes/no) " choice + +if [[ "$choice" != "yes" ]]; then + echo "Aborting script execution." + exit 1 +fi + +# 1) Rename files that contain 'r1cs' or 'R1CS' in their name, skipping any with 'r1cs_std'. +echo "Renaming files that contain 'r1cs' or 'R1CS' (but not 'r1cs_std')..." +export LC_ALL=C # Ensure consistent behavior for case conversions + +# Use 'find' + 'while IFS= read -r -d ""' to handle spaces & special chars in filenames. +while IFS= read -r -d '' file; do + # If filename includes r1cs_std, skip + if [[ "$file" =~ r1cs_std ]]; then + continue + fi + + # Compute new filename by substituting: + newfile="$(echo "$file" | sed 's/R1CS/GR1CS/g; s/r1cs/gr1cs/g')" + + if [[ "$newfile" != "$file" ]]; then + echo " -> Renaming: $file -> $newfile" + mv "$file" "$newfile" + fi +done < <(find . -type f -name "*.rs" -print0) + +# 2) Replace R1CS->GR1CS and r1cs->gr1cs in file contents, +# skipping lines that have 'r1cs_std'. +echo "Replacing (R1CS->GR1CS, r1cs->gr1cs) in .rs file contents..." +while IFS= read -r -d '' file; do + # Replace R1CS -> GR1CS on lines NOT containing 'r1cs_std' + sed "${SED_INPLACE[@]}" '/r1cs_std/! s/R1CS/GR1CS/g' "$file" + # Replace r1cs -> gr1cs on lines NOT containing 'r1cs_std' + sed "${SED_INPLACE[@]}" '/r1cs_std/! s/r1cs/gr1cs/g' "$file" +done < <(find . -type f -name "*.rs" ! -name "*r1cs_std*" -print0) + +# 3) Finally, replace 'enforce_constraint' -> 'enforce_r1cs_constraint', +# skipping lines that have 'r1cs_std'. +echo "Replacing enforce_constraint->enforce_r1cs_constraint..." +while IFS= read -r -d '' file; do + sed "${SED_INPLACE[@]}" '/r1cs_std/! s/enforce_constraint/enforce_r1cs_constraint/g' "$file" +done < <(find . -type f -name "*.rs" ! -name "*r1cs_std*" -print0) + +echo "Done!" From 2827eaffed0f300c2d8501452333f57e8f8566a9 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Thu, 20 Feb 2025 10:31:07 -0500 Subject: [PATCH 06/11] fmt --- benches/bench.rs | 3 +-- src/boolean/and.rs | 2 +- src/boolean/eq.rs | 11 ++++----- src/boolean/mod.rs | 3 +-- src/boolean/or.rs | 2 +- src/boolean/xor.rs | 2 +- src/cmp.rs | 3 ++- src/fields/emulated_fp/allocated_field_var.rs | 10 ++++---- .../emulated_fp/allocated_mul_result.rs | 2 +- src/fields/emulated_fp/reduce.rs | 2 +- src/fields/fp/mod.rs | 8 ++++--- src/fields/mod.rs | 9 ++++--- src/groups/curves/short_weierstrass/mod.rs | 11 +++++---- src/uint/add/mod.rs | 10 ++++---- src/uint/add/saturating.rs | 6 ++--- src/uint/add/wrapping.rs | 6 ++--- src/uint/and.rs | 2 +- src/uint/convert.rs | 24 ++++++++++++------- src/uint/eq.rs | 3 +-- src/uint/mod.rs | 3 ++- src/uint/not.rs | 6 +++-- src/uint/or.rs | 2 +- src/uint/prim_uint.rs | 12 ++++++---- src/uint/shl.rs | 2 +- src/uint/shr.rs | 2 +- src/uint/xor.rs | 2 +- 26 files changed, 83 insertions(+), 65 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 62d538e0..34c0cb9b 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -5,9 +5,8 @@ use ark_r1cs_std::{ fields::{emulated_fp::EmulatedFpVar, FieldVar}, }; use ark_relations::{ - ns, gr1cs::{ConstraintSystem, ConstraintSystemRef, OptimizationGoal}, - + ns, }; use ark_std::rand::RngCore; diff --git a/src/boolean/and.rs b/src/boolean/and.rs index 0547b585..94de68e9 100644 --- a/src/boolean/and.rs +++ b/src/boolean/and.rs @@ -1,6 +1,6 @@ use ark_ff::{Field, PrimeField}; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::BitAnd, ops::BitAndAssign}; +use ark_std::ops::{BitAnd, BitAndAssign}; use crate::{fields::fp::FpVar, prelude::EqGadget}; diff --git a/src/boolean/eq.rs b/src/boolean/eq.rs index 33609ff0..91166ac5 100644 --- a/src/boolean/eq.rs +++ b/src/boolean/eq.rs @@ -1,7 +1,6 @@ use ark_relations::gr1cs::SynthesisError; -use crate::boolean::Boolean; -use crate::eq::EqGadget; +use crate::{boolean::Boolean, eq::EqGadget}; use super::*; @@ -26,8 +25,8 @@ impl EqGadget for Boolean { use Boolean::*; let one = Variable::One; // We will use the following trick: a == b <=> a - b == 0 - // This works because a - b == 0 if and only if a = 0 and b = 0, or a = 1 and b = 1, - // which is exactly the definition of a == b. + // This works because a - b == 0 if and only if a = 0 and b = 0, or a = 1 and b + // = 1, which is exactly the definition of a == b. let difference = match (self, other) { // 1 == 1; 0 == 0 (Constant(true), Constant(true)) | (Constant(false), Constant(false)) => return Ok(()), @@ -57,8 +56,8 @@ impl EqGadget for Boolean { use Boolean::*; let one = Variable::One; // We will use the following trick: a != b <=> a + b == 1 - // This works because a + b == 1 if and only if a = 0 and b = 1, or a = 1 and b = 0, - // which is exactly the definition of a != b. + // This works because a + b == 1 if and only if a = 0 and b = 1, or a = 1 and b + // = 0, which is exactly the definition of a != b. let sum = match (self, other) { // 1 != 0; 0 != 1 (Constant(true), Constant(false)) | (Constant(false), Constant(true)) => return Ok(()), diff --git a/src/boolean/mod.rs b/src/boolean/mod.rs index a8f9aa77..e1e5e30b 100644 --- a/src/boolean/mod.rs +++ b/src/boolean/mod.rs @@ -202,8 +202,7 @@ impl AllocVar for Boolean { #[cfg(test)] mod test { use super::Boolean; - use crate::convert::ToBytesGadget; - use crate::prelude::*; + use crate::{convert::ToBytesGadget, prelude::*}; use ark_ff::{ AdditiveGroup, BitIteratorBE, BitIteratorLE, Field, One, PrimeField, UniformRand, }; diff --git a/src/boolean/or.rs b/src/boolean/or.rs index 1d8ca48e..af962a44 100644 --- a/src/boolean/or.rs +++ b/src/boolean/or.rs @@ -1,6 +1,6 @@ use ark_ff::PrimeField; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::BitOr, ops::BitOrAssign}; +use ark_std::ops::{BitOr, BitOrAssign}; use crate::{ eq::EqGadget, diff --git a/src/boolean/xor.rs b/src/boolean/xor.rs index 7d907678..cbfd884f 100644 --- a/src/boolean/xor.rs +++ b/src/boolean/xor.rs @@ -1,6 +1,6 @@ use ark_ff::Field; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::BitXor, ops::BitXorAssign}; +use ark_std::ops::{BitXor, BitXorAssign}; use super::Boolean; diff --git a/src/cmp.rs b/src/cmp.rs index f2b8f2fc..714437a2 100644 --- a/src/cmp.rs +++ b/src/cmp.rs @@ -39,7 +39,8 @@ impl CmpGadget for () { } } -/// Mimics the lexicographic comparison behavior of `std::cmp::PartialOrd` for `[T]`. +/// Mimics the lexicographic comparison behavior of `std::cmp::PartialOrd` for +/// `[T]`. impl, F: PrimeField> CmpGadget for [T] { fn is_ge(&self, other: &Self) -> Result, SynthesisError> { let mut result = Boolean::TRUE; diff --git a/src/fields/emulated_fp/allocated_field_var.rs b/src/fields/emulated_fp/allocated_field_var.rs index 56f5ee55..e2078010 100644 --- a/src/fields/emulated_fp/allocated_field_var.rs +++ b/src/fields/emulated_fp/allocated_field_var.rs @@ -10,10 +10,10 @@ use crate::{ }; use ark_ff::{BigInteger, PrimeField}; use ark_relations::{ - ns, gr1cs::{ ConstraintSystemRef, Namespace, OptimizationGoal, Result as R1CSResult, SynthesisError, }, + ns, }; use ark_std::{ borrow::Borrow, @@ -621,10 +621,10 @@ impl AllocatedEmulatedFpVar>( cs: impl Into>, f: impl FnOnce() -> Result, diff --git a/src/fields/emulated_fp/allocated_mul_result.rs b/src/fields/emulated_fp/allocated_mul_result.rs index 71d298d7..6b42236d 100644 --- a/src/fields/emulated_fp/allocated_mul_result.rs +++ b/src/fields/emulated_fp/allocated_mul_result.rs @@ -6,8 +6,8 @@ use super::{ use crate::{fields::fp::FpVar, prelude::*}; use ark_ff::PrimeField; use ark_relations::{ - ns, gr1cs::{ConstraintSystemRef, OptimizationGoal, Result as R1CSResult}, + ns, }; use ark_std::{marker::PhantomData, vec::Vec}; use num_bigint::BigUint; diff --git a/src/fields/emulated_fp/reduce.rs b/src/fields/emulated_fp/reduce.rs index 2846b96b..45265513 100644 --- a/src/fields/emulated_fp/reduce.rs +++ b/src/fields/emulated_fp/reduce.rs @@ -8,8 +8,8 @@ use crate::{ }; use ark_ff::{biginteger::BigInteger, BitIteratorBE, One, PrimeField, Zero}; use ark_relations::{ - ns, gr1cs::{ConstraintSystemRef, Result as R1CSResult}, + ns, }; use ark_std::{cmp::min, marker::PhantomData, vec, vec::Vec}; use num_bigint::BigUint; diff --git a/src/fields/fp/mod.rs b/src/fields/fp/mod.rs index 36bbc9ad..fda9a4c9 100644 --- a/src/fields/fp/mod.rs +++ b/src/fields/fp/mod.rs @@ -52,7 +52,8 @@ pub enum FpVar { } impl FpVar { - /// Decomposes `self` into a vector of `bits` and a remainder `rest` such that + /// Decomposes `self` into a vector of `bits` and a remainder `rest` such + /// that /// * `bits.len() == size`, and /// * `rest == 0`. pub fn to_bits_le_with_top_bits_zero( @@ -465,8 +466,9 @@ impl AllocatedFp { // The high level logic is as follows: // We want to check that self - other != 0. We do this by checking that // (self - other).inverse() exists. In more detail, we check the following: - // If `should_enforce == true`, then we set `multiplier = (self - other).inverse()`, - // and check that (self - other) * multiplier == 1. (i.e., that the inverse exists) + // If `should_enforce == true`, then we set `multiplier = (self - + // other).inverse()`, and check that (self - other) * multiplier == 1. + // (i.e., that the inverse exists) // // If `should_enforce == false`, then we set `multiplier == 0`, and check that // (self - other) * 0 == 0, which is always satisfied. diff --git a/src/fields/mod.rs b/src/fields/mod.rs index 57161f12..3be5112c 100644 --- a/src/fields/mod.rs +++ b/src/fields/mod.rs @@ -5,8 +5,10 @@ use core::{ ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}, }; -use crate::convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}; -use crate::prelude::*; +use crate::{ + convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, + prelude::*, +}; /// This module contains a generic implementation of cubic extension field /// variables. That is, it implements the R1CS equivalent of @@ -22,7 +24,8 @@ pub mod quadratic_extension; pub mod fp; /// This module contains a generic implementation of "emulated" prime field -/// variables. It emulates `Fp` arithmetic using `Fq` operations, where `p != q`. +/// variables. It emulates `Fp` arithmetic using `Fq` operations, where `p != +/// q`. pub mod emulated_fp; /// This module contains a generic implementation of the degree-12 tower diff --git a/src/groups/curves/short_weierstrass/mod.rs b/src/groups/curves/short_weierstrass/mod.rs index a1f122b5..eb4eedf5 100644 --- a/src/groups/curves/short_weierstrass/mod.rs +++ b/src/groups/curves/short_weierstrass/mod.rs @@ -515,12 +515,13 @@ where // zero if `self` was zero. However, we also want to make sure that generated // constraints are satisfiable in both cases. // - // In particular, using non-sensible values for `x` and `y` in zero-case may cause - // `unchecked` operations to generate constraints that can never be satisfied, depending - // on the curve equation coefficients. + // In particular, using non-sensible values for `x` and `y` in zero-case may + // cause `unchecked` operations to generate constraints that can never + // be satisfied, depending on the curve equation coefficients. // - // The safest approach is to use coordinates of some point from the curve, thus not - // violating assumptions of `NonZeroAffine`. For instance, generator point. + // The safest approach is to use coordinates of some point from the curve, thus + // not violating assumptions of `NonZeroAffine`. For instance, generator + // point. let x = infinity.select(&F::constant(P::GENERATOR.x), &x)?; let y = infinity.select(&F::constant(P::GENERATOR.y), &y)?; let non_zero_self = NonZeroAffineVar::new(x, y); diff --git a/src/uint/add/mod.rs b/src/uint/add/mod.rs index dfe48307..fceb1043 100644 --- a/src/uint/add/mod.rs +++ b/src/uint/add/mod.rs @@ -6,13 +6,15 @@ mod saturating; mod wrapping; impl UInt { - /// Adds up `operands`, returning the bit decomposition of the result, along with - /// the value of the result. If all the operands are constant, then the bit decomposition - /// is empty, and the value is the constant value of the result. + /// Adds up `operands`, returning the bit decomposition of the result, along + /// with the value of the result. If all the operands are constant, then + /// the bit decomposition is empty, and the value is the constant value + /// of the result. /// /// # Panics /// - /// This method panics if the result of addition could possibly exceed the field size. + /// This method panics if the result of addition could possibly exceed the + /// field size. #[tracing::instrument(target = "gr1cs", skip(operands, adder))] fn add_many_helper( operands: &[Self], diff --git a/src/uint/add/saturating.rs b/src/uint/add/saturating.rs index a38b3736..ddd78f00 100644 --- a/src/uint/add/saturating.rs +++ b/src/uint/add/saturating.rs @@ -1,8 +1,7 @@ use ark_ff::PrimeField; use ark_relations::gr1cs::SynthesisError; -use crate::uint::*; -use crate::{boolean::Boolean, GR1CSVar}; +use crate::{boolean::Boolean, uint::*, GR1CSVar}; impl UInt { /// Compute `*self = self.wrapping_add(other)`. @@ -19,7 +18,8 @@ impl UInt { } /// Perform wrapping addition of `operands`. - /// Computes `operands[0].wrapping_add(operands[1]).wrapping_add(operands[2])...`. + /// Computes `operands[0].wrapping_add(operands[1]). + /// wrapping_add(operands[2])...`. /// /// The user must ensure that overflow does not occur. #[tracing::instrument(target = "gr1cs", skip(operands))] diff --git a/src/uint/add/wrapping.rs b/src/uint/add/wrapping.rs index e9ac9c46..2875c9db 100644 --- a/src/uint/add/wrapping.rs +++ b/src/uint/add/wrapping.rs @@ -1,8 +1,7 @@ use ark_ff::PrimeField; use ark_relations::gr1cs::SynthesisError; -use crate::uint::*; -use crate::GR1CSVar; +use crate::{uint::*, GR1CSVar}; impl UInt { /// Compute `*self = self.wrapping_add(other)`. @@ -19,7 +18,8 @@ impl UInt { } /// Perform wrapping addition of `operands`. - /// Computes `operands[0].wrapping_add(operands[1]).wrapping_add(operands[2])...`. + /// Computes `operands[0].wrapping_add(operands[1]). + /// wrapping_add(operands[2])...`. /// /// The user must ensure that overflow does not occur. #[tracing::instrument(target = "gr1cs", skip(operands))] diff --git a/src/uint/and.rs b/src/uint/and.rs index 9b0e31d2..c68d4f2f 100644 --- a/src/uint/and.rs +++ b/src/uint/and.rs @@ -1,6 +1,6 @@ use ark_ff::Field; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::BitAnd, ops::BitAndAssign}; +use ark_std::ops::{BitAnd, BitAndAssign}; use super::*; diff --git a/src/uint/convert.rs b/src/uint/convert.rs index 8a7e4e65..4c6301e1 100644 --- a/src/uint/convert.rs +++ b/src/uint/convert.rs @@ -1,14 +1,15 @@ -use crate::convert::*; -use crate::fields::fp::FpVar; +use crate::{convert::*, fields::fp::FpVar}; use super::*; impl UInt { /// Converts `self` into a field element. The elements comprising `self` are - /// interpreted as a little-endian bit order representation of a field element. + /// interpreted as a little-endian bit order representation of a field + /// element. /// /// # Panics - /// Assumes that `N` is equal to at most the number of bits in `F::MODULUS_BIT_SIZE - 1`, and panics otherwise. + /// Assumes that `N` is equal to at most the number of bits in + /// `F::MODULUS_BIT_SIZE - 1`, and panics otherwise. pub fn to_fp(&self) -> Result, SynthesisError> where F: PrimeField, @@ -18,11 +19,13 @@ impl UInt { Boolean::le_bits_to_fp(&self.bits) } - /// Converts a field element into its little-endian bit order representation. + /// Converts a field element into its little-endian bit order + /// representation. /// /// # Panics /// - /// Assumes that `N` is at most the number of bits in `F::MODULUS_BIT_SIZE - 1`, and panics otherwise. + /// Assumes that `N` is at most the number of bits in `F::MODULUS_BIT_SIZE - + /// 1`, and panics otherwise. pub fn from_fp(other: &FpVar) -> Result<(Self, FpVar), SynthesisError> where F: PrimeField, @@ -154,9 +157,12 @@ impl ToBitsGadget for [UInt] } } -/*****************************************************************************************/ -/********************************* Conversions to bytes. *********************************/ -/*****************************************************************************************/ +/// **************************************************************************** +/// ********** +/// ******************************* Conversions to bytes. +/// ******************************** +/// **************************************************************************** +/// ********** impl ToBytesGadget for UInt diff --git a/src/uint/eq.rs b/src/uint/eq.rs index dbe074be..1b6921b2 100644 --- a/src/uint/eq.rs +++ b/src/uint/eq.rs @@ -2,8 +2,7 @@ use ark_ff::PrimeField; use ark_relations::gr1cs::SynthesisError; use ark_std::vec::Vec; -use crate::boolean::Boolean; -use crate::eq::EqGadget; +use crate::{boolean::Boolean, eq::EqGadget}; use super::*; diff --git a/src/uint/mod.rs b/src/uint/mod.rs index 91fc8b33..263c3cbc 100644 --- a/src/uint/mod.rs +++ b/src/uint/mod.rs @@ -25,7 +25,8 @@ pub use prim_uint::*; #[cfg(test)] pub(crate) mod test_utils; -/// This struct represent an unsigned `N` bit integer as a sequence of `N` [`Boolean`]s. +/// This struct represent an unsigned `N` bit integer as a sequence of `N` +/// [`Boolean`]s. #[derive(Clone, Debug)] pub struct UInt { #[doc(hidden)] diff --git a/src/uint/not.rs b/src/uint/not.rs index d20186f0..3dadef8b 100644 --- a/src/uint/not.rs +++ b/src/uint/not.rs @@ -24,7 +24,8 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> Not for &'a UInt { type Output = UInt; /// Outputs `!self`. /// - /// If `self` is a constant, then this method *does not* create any constraints or variables. + /// If `self` is a constant, then this method *does not* create any + /// constraints or variables. /// /// ``` /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { @@ -53,7 +54,8 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> Not for UInt { /// Outputs `!self`. /// - /// If `self` is a constant, then this method *does not* create any constraints or variables. + /// If `self` is a constant, then this method *does not* create any + /// constraints or variables. /// /// ``` /// # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { diff --git a/src/uint/or.rs b/src/uint/or.rs index 0a608343..6dbff70f 100644 --- a/src/uint/or.rs +++ b/src/uint/or.rs @@ -1,6 +1,6 @@ use ark_ff::PrimeField; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::BitOr, ops::BitOrAssign}; +use ark_std::ops::{BitOr, BitOrAssign}; use super::{PrimUInt, UInt}; diff --git a/src/uint/prim_uint.rs b/src/uint/prim_uint.rs index 3b3fff81..60855f5e 100644 --- a/src/uint/prim_uint.rs +++ b/src/uint/prim_uint.rs @@ -1,5 +1,7 @@ -use core::ops::{Shl, ShlAssign, Shr, ShrAssign}; -use core::usize; +use core::{ + ops::{Shl, ShlAssign, Shr, ShrAssign}, + usize, +}; #[doc(hidden)] // Adapted from @@ -41,7 +43,8 @@ pub trait PrimUInt: #[doc(hidden)] const MAX_VALUE_BIT_DECOMP: &'static [bool]; - /// Return the memory representation of this number as a byte array in little-endian byte order. + /// Return the memory representation of this number as a byte array in + /// little-endian byte order. /// /// # Examples /// @@ -53,7 +56,8 @@ pub trait PrimUInt: /// ``` fn to_le_bytes(&self) -> Self::Bytes; - /// Return the memory representation of this number as a byte array in big-endian byte order. + /// Return the memory representation of this number as a byte array in + /// big-endian byte order. /// /// # Examples /// diff --git a/src/uint/shl.rs b/src/uint/shl.rs index c70742b7..b4bf29b1 100644 --- a/src/uint/shl.rs +++ b/src/uint/shl.rs @@ -1,6 +1,6 @@ use ark_ff::PrimeField; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::Shl, ops::ShlAssign}; +use ark_std::ops::{Shl, ShlAssign}; use crate::boolean::Boolean; diff --git a/src/uint/shr.rs b/src/uint/shr.rs index bfb367ee..3b3371a7 100644 --- a/src/uint/shr.rs +++ b/src/uint/shr.rs @@ -1,6 +1,6 @@ use ark_ff::PrimeField; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::Shr, ops::ShrAssign}; +use ark_std::ops::{Shr, ShrAssign}; use crate::boolean::Boolean; diff --git a/src/uint/xor.rs b/src/uint/xor.rs index 8b2479fc..2a316ab2 100644 --- a/src/uint/xor.rs +++ b/src/uint/xor.rs @@ -1,6 +1,6 @@ use ark_ff::Field; use ark_relations::gr1cs::SynthesisError; -use ark_std::{ops::BitXor, ops::BitXorAssign}; +use ark_std::ops::{BitXor, BitXorAssign}; use super::*; From 23a1a89616ec1536092677af5b9eb4fca69821fc Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Thu, 20 Feb 2025 14:01:41 -0500 Subject: [PATCH 07/11] doc test fix --- src/alloc.rs | 4 ++-- src/fields/emulated_fp/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/alloc.rs b/src/alloc.rs index 75d60512..fb1706bf 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -90,8 +90,8 @@ pub trait AllocVar: Sized { /// variable, one can write: /// ``` /// use ark_ff::PrimeField; - /// use ark_r1cs_std::{alloc::AllocVar, fields::{fp::FpVar, FieldVar}, R1CSVar}; - /// use ark_relations::r1cs::SynthesisError; + /// use ark_r1cs_std::{alloc::AllocVar, fields::{fp::FpVar, FieldVar}, GR1CSVar}; + /// use ark_relations::gr1cs::SynthesisError; /// /// fn div(x_var: &FpVar, y_var: &FpVar) -> Result, SynthesisError> { /// let cs = x_var.cs().or(y_var.cs()); diff --git a/src/fields/emulated_fp/mod.rs b/src/fields/emulated_fp/mod.rs index 6107e3ff..27294e3c 100644 --- a/src/fields/emulated_fp/mod.rs +++ b/src/fields/emulated_fp/mod.rs @@ -26,7 +26,7 @@ //! ```rust //! # fn main() -> Result<(), ark_relations::gr1cs::SynthesisError> { //! # use ark_std::UniformRand; -//! # use ark_relations::{ns, r1cs::ConstraintSystem}; +//! # use ark_relations::{ns, gr1cs::ConstraintSystem}; //! # use ark_r1cs_std::prelude::*; //! use ark_r1cs_std::fields::emulated_fp::EmulatedFpVar; //! use ark_bls12_377::{Fr, Fq}; From 09776fc5d42102c0993592108b5d78d9854055c8 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Wed, 12 Mar 2025 19:21:53 -0400 Subject: [PATCH 08/11] mwork --- Cargo.toml | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 53fe8a7f..4c339ea9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ark-r1cs-std" version = "0.5.0" -authors = [ "arkworks contributors" ] +authors = ["arkworks contributors"] description = "A standard library for constraint system gadgets" homepage = "https://arkworks.rs" repository = "https://github.com/arkworks-rs/r1cs-std" @@ -17,32 +17,50 @@ resolver = "2" ark-ff = { version = "0.5.0", default-features = false } ark-ec = { version = "0.5.0", default-features = false } ark-std = { version = "0.5.0", default-features = false } -ark-relations = { version = "0.5.0", default-features = false } +ark-relations = { git = "https://github.com/alireza-shirzad/snark.git", default-features = true } educe = "0.6.0" -tracing = { version = "0.1", default-features = false, features = [ "attributes" ] } +tracing = { version = "0.1", default-features = false, features = [ + "attributes", +] } num-bigint = { version = "0.4", default-features = false } num-traits = { version = "0.2", default-features = false } num-integer = { version = "0.1.44", default-features = false } [dev-dependencies] -ark-test-curves = { version = "0.5.0", default-features = false, features = ["bls12_381_scalar_field", "bls12_381_curve", "mnt4_753_scalar_field"] } +ark-test-curves = { version = "0.5.0", default-features = false, features = [ + "bls12_381_scalar_field", + "bls12_381_curve", + "mnt4_753_scalar_field", +] } ark-poly = { version = "0.5.0", default-features = false } paste = "1.0" -ark-bls12-377 = { version = "0.5.0", features = ["curve"], default-features = false } -ark-bls12-381 = { version = "0.5.0", features = ["curve"], default-features = false } -ark-mnt4-298 = { version = "0.5.0", features = ["curve"], default-features = false } -ark-mnt4-753 = { version = "0.5.0", features = ["curve"], default-features = false } -ark-mnt6-298 = { version = "0.5.0", default-features = false } -ark-mnt6-753 = { version = "0.5.0", default-features = false } -ark-pallas = { version = "0.5.0", features = ["curve"], default-features = false } -ark-bn254 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-bls12-377 = { version = "0.5.0", features = [ + "curve", +], default-features = false } +ark-bls12-381 = { version = "0.5.0", features = [ + "curve", +], default-features = false } +ark-mnt4-298 = { version = "0.5.0", features = [ + "curve", +], default-features = false } +ark-mnt4-753 = { version = "0.5.0", features = [ + "curve", +], default-features = false } +ark-mnt6-298 = { version = "0.5.0", default-features = false } +ark-mnt6-753 = { version = "0.5.0", default-features = false } +ark-pallas = { version = "0.5.0", features = [ + "curve", +], default-features = false } +ark-bn254 = { version = "0.5.0", features = [ + "curve", +], default-features = false } tracing-subscriber = { version = "0.3", default-features = true } [features] default = ["std"] -std = [ "ark-ff/std", "ark-relations/std", "ark-std/std", "num-bigint/std" ] -parallel = [ "std", "ark-ff/parallel", "ark-std/parallel"] +std = ["ark-ff/std", "ark-relations/std", "ark-std/std", "num-bigint/std"] +parallel = ["std", "ark-ff/parallel", "ark-std/parallel"] [[bench]] name = "emulated-bench" @@ -78,4 +96,4 @@ debug = true unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } [patch.crates-io] -ark-relations = { git = "https://github.com/arkworks-rs/snark.git"} +# ark-relations = { git = "https://github.com/arkworks-rs/snark.git"} From ca5708dbefc0679177bac9dc955a1b5e83276822 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Wed, 12 Mar 2025 20:00:26 -0400 Subject: [PATCH 09/11] work --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4c339ea9..f5064811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,6 +94,3 @@ debug = true [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } - -[patch.crates-io] -# ark-relations = { git = "https://github.com/arkworks-rs/snark.git"} From 5f2e90dfa9b5051fbc5c0fc134d3ea0fbb7feb83 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Mon, 17 Mar 2025 14:36:01 -0400 Subject: [PATCH 10/11] work --- Cargo.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f5064811..cca40329 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ resolver = "2" ark-ff = { version = "0.5.0", default-features = false } ark-ec = { version = "0.5.0", default-features = false } ark-std = { version = "0.5.0", default-features = false } -ark-relations = { git = "https://github.com/alireza-shirzad/snark.git", default-features = true } +ark-relations = { version = "0.5.0", default-features = true } educe = "0.6.0" tracing = { version = "0.1", default-features = false, features = [ @@ -94,3 +94,8 @@ debug = true [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } + + +# patch +[patch.crates-io] +ark-relations = { git = "https://github.com/arkworks-rs/snark.git", default-features = true } From ce625d63c33481ba9d67103f5ad5e68ad772e455 Mon Sep 17 00:00:00 2001 From: Alireza Shirzad Date: Mon, 17 Mar 2025 17:46:37 -0400 Subject: [PATCH 11/11] addressed comments --- Cargo.toml | 30 ++++++++---------------------- scripts/migrate.sh | 42 ++++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cca40329..582ecff5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,12 +17,10 @@ resolver = "2" ark-ff = { version = "0.5.0", default-features = false } ark-ec = { version = "0.5.0", default-features = false } ark-std = { version = "0.5.0", default-features = false } -ark-relations = { version = "0.5.0", default-features = true } +ark-relations = { version = "0.5.0", default-features = false } educe = "0.6.0" -tracing = { version = "0.1", default-features = false, features = [ - "attributes", -] } +tracing = { version = "^0.1.0", default-features = false, features = ["attributes"] } num-bigint = { version = "0.4", default-features = false } num-traits = { version = "0.2", default-features = false } num-integer = { version = "0.1.44", default-features = false } @@ -35,26 +33,14 @@ ark-test-curves = { version = "0.5.0", default-features = false, features = [ ] } ark-poly = { version = "0.5.0", default-features = false } paste = "1.0" -ark-bls12-377 = { version = "0.5.0", features = [ - "curve", -], default-features = false } -ark-bls12-381 = { version = "0.5.0", features = [ - "curve", -], default-features = false } -ark-mnt4-298 = { version = "0.5.0", features = [ - "curve", -], default-features = false } -ark-mnt4-753 = { version = "0.5.0", features = [ - "curve", -], default-features = false } +ark-bls12-377 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-bls12-381 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-mnt4-298 = { version = "0.5.0", features = ["curve"], default-features = false } +ark-mnt4-753 = { version = "0.5.0", features = ["curve"], default-features = false } ark-mnt6-298 = { version = "0.5.0", default-features = false } ark-mnt6-753 = { version = "0.5.0", default-features = false } -ark-pallas = { version = "0.5.0", features = [ - "curve", -], default-features = false } -ark-bn254 = { version = "0.5.0", features = [ - "curve", -], default-features = false } +ark-pallas = { version = "0.5.0", features = ["curve"], default-features = false } +ark-bn254 = { version = "0.5.0", features = ["curve"], default-features = false } tracing-subscriber = { version = "0.3", default-features = true } [features] diff --git a/scripts/migrate.sh b/scripts/migrate.sh index 92de3cf5..e2ca2eee 100755 --- a/scripts/migrate.sh +++ b/scripts/migrate.sh @@ -1,27 +1,24 @@ #!/usr/bin/env bash # ----------------------------------------------------------------------------- -# rename_r1cs.sh -# +# rename_r1cs.sh (Regex Version) +# # Recursively: # 1. Renames .rs filenames: R1CS->GR1CS, r1cs->gr1cs (except those with r1cs_std). -# 2. In .rs file contents, replaces R1CS->GR1CS, r1cs->gr1cs (except lines with r1cs_std). -# 3. Finally replaces enforce_constraint->enforce_r1cs_constraint (except lines with r1cs_std). +# 2. In .rs file contents, replaces R1CS->GR1CS, r1cs->gr1cs (except lines with r1cs_std), +# ensuring words already in GR1CS/gr1cs are not changed again. +# 3. Finally replaces enforce_constraint->enforce_r1cs_constraint (except lines with r1cs_std), +# ensuring enforce_r1cs_constraint is not changed again. # ----------------------------------------------------------------------------- # --- Detect which 'sed' in-place flag to use (GNU vs BSD/macOS) --- -# On macOS, 'sed -i' requires a backup extension parameter (can be empty ''). -# On GNU sed, 'sed -i' is fine without extra args. if sed --version 2>/dev/null | grep -q "GNU"; then - # GNU sed SED_INPLACE=(-i) else - # BSD/macOS sed SED_INPLACE=(-i '') fi echo "###############################################" -echo "# ⚠️ Cautious: RUN THIS SCRIPT ONLY ONCE! DO NOT RUN IT TWICE! #" echo "# Make sure you have a backup before running. #" echo "###############################################" echo @@ -32,20 +29,15 @@ if [[ "$choice" != "yes" ]]; then exit 1 fi -# 1) Rename files that contain 'r1cs' or 'R1CS' in their name, skipping any with 'r1cs_std'. -echo "Renaming files that contain 'r1cs' or 'R1CS' (but not 'r1cs_std')..." +# 1) Rename files that contain 'r1cs' or 'R1CS' in their name, skipping 'r1cs_std' and existing 'gr1cs'. +echo "Renaming files that contain 'r1cs' or 'R1CS' (but not 'r1cs_std' and already converted ones)..." export LC_ALL=C # Ensure consistent behavior for case conversions -# Use 'find' + 'while IFS= read -r -d ""' to handle spaces & special chars in filenames. while IFS= read -r -d '' file; do - # If filename includes r1cs_std, skip - if [[ "$file" =~ r1cs_std ]]; then + if [[ "$file" =~ r1cs_std || "$file" =~ gr1cs ]]; then continue fi - - # Compute new filename by substituting: - newfile="$(echo "$file" | sed 's/R1CS/GR1CS/g; s/r1cs/gr1cs/g')" - + newfile="$(echo "$file" | sed -E 's/(^|[^g])r1cs/\1gr1cs/g; s/(^|[^G])R1CS/\1GR1CS/g')" if [[ "$newfile" != "$file" ]]; then echo " -> Renaming: $file -> $newfile" mv "$file" "$newfile" @@ -53,20 +45,18 @@ while IFS= read -r -d '' file; do done < <(find . -type f -name "*.rs" -print0) # 2) Replace R1CS->GR1CS and r1cs->gr1cs in file contents, -# skipping lines that have 'r1cs_std'. +# skipping lines that have 'r1cs_std' and ensuring already transformed words are not changed again. echo "Replacing (R1CS->GR1CS, r1cs->gr1cs) in .rs file contents..." while IFS= read -r -d '' file; do - # Replace R1CS -> GR1CS on lines NOT containing 'r1cs_std' - sed "${SED_INPLACE[@]}" '/r1cs_std/! s/R1CS/GR1CS/g' "$file" - # Replace r1cs -> gr1cs on lines NOT containing 'r1cs_std' - sed "${SED_INPLACE[@]}" '/r1cs_std/! s/r1cs/gr1cs/g' "$file" + sed "${SED_INPLACE[@]}" -E '/r1cs_std|enforce_r1cs_constraint/! s/(^|[^g])r1cs/\1gr1cs/g' "$file" + sed "${SED_INPLACE[@]}" -E '/r1cs_std|enforce_r1cs_constraint/! s/(^|[^G])R1CS/\1GR1CS/g' "$file" done < <(find . -type f -name "*.rs" ! -name "*r1cs_std*" -print0) -# 3) Finally, replace 'enforce_constraint' -> 'enforce_r1cs_constraint', -# skipping lines that have 'r1cs_std'. +# 3) Replace 'enforce_constraint' -> 'enforce_r1cs_constraint', +# skipping lines that have 'r1cs_std' and ensuring enforce_r1cs_constraint is not changed again. echo "Replacing enforce_constraint->enforce_r1cs_constraint..." while IFS= read -r -d '' file; do - sed "${SED_INPLACE[@]}" '/r1cs_std/! s/enforce_constraint/enforce_r1cs_constraint/g' "$file" + sed "${SED_INPLACE[@]}" '/r1cs_std|enforce_r1cs_constraint/! s/enforce_constraint/enforce_r1cs_constraint/g' "$file" done < <(find . -type f -name "*.rs" ! -name "*r1cs_std*" -print0) echo "Done!"