From 994c27ac1a53331133189b4838d93a4ab8d4c983 Mon Sep 17 00:00:00 2001 From: Thomas Chataigner Date: Wed, 20 Mar 2024 10:52:20 +0100 Subject: [PATCH] feat: using ShapeCS from bellpepper --- Cargo.toml | 10 ++-- src/bellpepper/mod.rs | 3 +- src/bellpepper/r1cs.rs | 4 +- src/bellpepper/shape_cs.rs | 102 ------------------------------------- src/lib.rs | 2 +- src/supernova/mod.rs | 2 +- 6 files changed, 8 insertions(+), 115 deletions(-) delete mode 100644 src/bellpepper/shape_cs.rs diff --git a/Cargo.toml b/Cargo.toml index 94efcbc22..752353843 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,8 @@ keywords = ["zkSNARKs", "cryptography", "proofs"] rust-version = "1.71.0" [dependencies] -bellpepper = { path = "../bellpepper/crates/bellpepper" } -bellpepper-core = { path = "../bellpepper/crates/bellpepper-core" } +bellpepper-core = { version = "0.4.0", default-features = false } +bellpepper = { git = "https://github.com/lurk-lab/bellpepper", branch = "dev", default-features = false } ff = { version = "0.13.0", features = ["derive"] } digest = "0.10" halo2curves = { version = "0.6.0", features = ["bits", "derive_serde"] } @@ -125,8 +125,4 @@ inherits = "dev" opt-level = 3 lto = "thin" incremental = false -codegen-units = 16 - -[patch.crates-io] -bellpepper = { path = "../bellpepper/crates/bellpepper" } -bellpepper-core = { path = "../bellpepper/crates/bellpepper-core" } \ No newline at end of file +codegen-units = 16 \ No newline at end of file diff --git a/src/bellpepper/mod.rs b/src/bellpepper/mod.rs index f67b78611..7a846dd04 100644 --- a/src/bellpepper/mod.rs +++ b/src/bellpepper/mod.rs @@ -3,7 +3,6 @@ //! [Bellpepper]: https://github.com/lurk-lab/bellpepper pub mod r1cs; -pub mod shape_cs; pub mod solver; #[cfg(test)] @@ -11,12 +10,12 @@ mod tests { use crate::{ bellpepper::{ r1cs::{NovaShape, NovaWitness}, - shape_cs::ShapeCS, solver::SatisfyingAssignment, }, provider::{Bn256EngineKZG, PallasEngine, Secp256k1Engine}, traits::{snark::default_ck_hint, Engine}, }; + use bellpepper::util_cs::shape_cs::ShapeCS; use bellpepper_core::{num::AllocatedNum, ConstraintSystem}; use ff::PrimeField; diff --git a/src/bellpepper/r1cs.rs b/src/bellpepper/r1cs.rs index dfe050fb7..06db0d1f1 100644 --- a/src/bellpepper/r1cs.rs +++ b/src/bellpepper/r1cs.rs @@ -2,14 +2,14 @@ #![allow(non_snake_case)] -use super::{shape_cs::ShapeCS, solver::SatisfyingAssignment}; +use super::solver::SatisfyingAssignment; use crate::{ errors::NovaError, r1cs::{commitment_key, CommitmentKeyHint, R1CSInstance, R1CSShape, R1CSWitness, SparseMatrix}, traits::Engine, CommitmentKey, }; -use bellpepper::util_cs::test_shape_cs::TestShapeCS; +use bellpepper::util_cs::{shape_cs::ShapeCS, test_shape_cs::TestShapeCS}; use bellpepper_core::{Index, LinearCombination}; use ff::PrimeField; diff --git a/src/bellpepper/shape_cs.rs b/src/bellpepper/shape_cs.rs deleted file mode 100644 index 8a75419db..000000000 --- a/src/bellpepper/shape_cs.rs +++ /dev/null @@ -1,102 +0,0 @@ -//! Support for generating R1CS shape using bellpepper. - -use bellpepper_core::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable}; -use ff::PrimeField; - -/// `ShapeCS` is a `ConstraintSystem` for creating `R1CSShape`s for a circuit. -pub struct ShapeCS { - /// All constraints added to the `ShapeCS`. - pub constraints: Vec<( - LinearCombination, - LinearCombination, - LinearCombination, - )>, - inputs: usize, - aux: usize, -} - -impl ShapeCS { - /// Create a new, default `ShapeCS`, - pub fn new() -> Self { - Self::default() - } - - /// Returns the number of constraints defined for this `ShapeCS`. - pub fn num_constraints(&self) -> usize { - self.constraints.len() - } - - /// Returns the number of inputs defined for this `ShapeCS`. - pub fn num_inputs(&self) -> usize { - self.inputs - } - - /// Returns the number of aux inputs defined for this `ShapeCS`. - pub fn num_aux(&self) -> usize { - self.aux - } -} - -impl Default for ShapeCS { - fn default() -> Self { - Self { - constraints: vec![], - inputs: 1, - aux: 0, - } - } -} - -impl ConstraintSystem for ShapeCS { - type Root = Self; - - fn alloc(&mut self, _annotation: A, _f: F) -> Result - where - F: FnOnce() -> Result, - A: FnOnce() -> AR, - AR: Into, - { - self.aux += 1; - - Ok(Variable::new_unchecked(Index::Aux(self.aux - 1))) - } - - fn alloc_input(&mut self, _annotation: A, _f: F) -> Result - where - F: FnOnce() -> Result, - A: FnOnce() -> AR, - AR: Into, - { - self.inputs += 1; - - Ok(Variable::new_unchecked(Index::Input(self.inputs - 1))) - } - - fn enforce(&mut self, _annotation: A, a: LA, b: LB, c: LC) - where - A: FnOnce() -> AR, - AR: Into, - LA: FnOnce(LinearCombination) -> LinearCombination, - LB: FnOnce(LinearCombination) -> LinearCombination, - LC: FnOnce(LinearCombination) -> LinearCombination, - { - let a = a(LinearCombination::zero()); - let b = b(LinearCombination::zero()); - let c = c(LinearCombination::zero()); - - self.constraints.push((a, b, c)); - } - - fn push_namespace(&mut self, _name_fn: N) - where - NR: Into, - N: FnOnce() -> NR, - { - } - - fn pop_namespace(&mut self) {} - - fn get_root(&mut self) -> &mut Self::Root { - self - } -} diff --git a/src/lib.rs b/src/lib.rs index 702d301e4..3c2d8fa9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,11 +34,11 @@ use crate::digest::{DigestComputer, SimpleDigestible}; use crate::{ bellpepper::{ r1cs::{NovaShape, NovaWitness}, - shape_cs::ShapeCS, solver::SatisfyingAssignment, }, r1cs::R1CSResult, }; +use ::bellpepper::util_cs::shape_cs::ShapeCS; use abomonation::Abomonation; use abomonation_derive::Abomonation; use bellpepper_core::{ConstraintSystem, SynthesisError}; diff --git a/src/supernova/mod.rs b/src/supernova/mod.rs index e5d526a0d..db18c3b30 100644 --- a/src/supernova/mod.rs +++ b/src/supernova/mod.rs @@ -3,7 +3,6 @@ use std::ops::Index; use crate::{ - bellpepper::shape_cs::ShapeCS, constants::{BN_LIMB_WIDTH, BN_N_LIMBS, NUM_HASH_BITS}, digest::{DigestComputer, SimpleDigestible}, errors::NovaError, @@ -18,6 +17,7 @@ use crate::{ }, Commitment, CommitmentKey, R1CSWithArity, }; +use bellpepper::util_cs::shape_cs::ShapeCS; #[cfg(feature = "abomonate")] use abomonation::Abomonation;