Support commit and prove
winderica winderica@gmail.com
Thu, 30 May 2024 07:40:56 +0800
6 files changed,
36 insertions(+),
18 deletions(-)
M
Cargo.toml
→
Cargo.toml
@@ -87,3 +87,4 @@ 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-relations = { git = "https://github.com/winderica/snark/", branch = "cp" }
M
src/alloc.rs
→
src/alloc.rs
@@ -19,19 +19,22 @@
/// Indicate to the `ConstraintSystem` that the high-level variable should /// be allocated as a private witness to the `ConstraintSystem`. Witness = 2, + + Committed = 3, } impl AllocationMode { /// Outputs the maximum according to the relation `Constant < Input < /// Witness`. pub fn max(&self, other: Self) -> Self { - use AllocationMode::*; - match (self, other) { - (Constant, _) => other, - (Input, Constant) => *self, - (Input, _) => other, - (Witness, _) => *self, - } + // use AllocationMode::*; + // match (self, other) { + // (Constant, _) => other, + // (Input, Constant) => *self, + // (Input, _) => other, + // (Witness, _) => *self, + // } + unimplemented!() } }@@ -75,6 +78,16 @@ cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>, ) -> Result<Self, SynthesisError> { Self::new_variable(cs, f, AllocationMode::Witness) + } + + /// Allocates a new commitment of type `Self` in the `ConstraintSystem` + /// `cs`. + #[tracing::instrument(target = "r1cs", skip(cs, f))] + fn new_committed<T: Borrow<V>>( + cs: impl Into<Namespace<F>>, + f: impl FnOnce() -> Result<T, SynthesisError>, + ) -> Result<Self, SynthesisError> { + Self::new_variable(cs, f, AllocationMode::Committed) } /// Allocates a new constant or private witness of type `Self` in the
M
src/fields/fp/mod.rs
→
src/fields/fp/mod.rs
@@ -703,10 +703,11 @@ let value_generator = || {
value = Some(*f()?.borrow()); value.ok_or(SynthesisError::AssignmentMissing) }; - let variable = if mode == AllocationMode::Input { - cs.new_input_variable(value_generator)? - } else { - cs.new_witness_variable(value_generator)? + let variable = match mode { + AllocationMode::Input => cs.new_input_variable(value_generator)?, + AllocationMode::Witness => cs.new_witness_variable(value_generator)?, + AllocationMode::Committed => cs.new_committed_variable(value_generator)?, + _ => unreachable!(), }; Ok(Self::new(value, variable, cs)) }
M
src/groups/curves/short_weierstrass/mod.rs
→
src/groups/curves/short_weierstrass/mod.rs
@@ -514,12 +514,13 @@ // We first handle the non-zero case, and then later will conditionally select
// 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);@@ -904,6 +905,7 @@ ge.enforce_equal(&ge)?;
Ok(ge) } }, + _ => unimplemented!(), } } }
M
src/groups/curves/twisted_edwards/mod.rs
→
src/groups/curves/twisted_edwards/mod.rs
@@ -650,6 +650,7 @@ ge.enforce_equal(&ge)?;
Ok(ge) } }, + _ => unimplemented!(), } } }
M
src/lib.rs
→
src/lib.rs
@@ -2,8 +2,8 @@ #![cfg_attr(not(feature = "std"), no_std)]
//! This crate implements common "gadgets" that make //! programming rank-1 constraint systems easier. #![deny( - warnings, - unused, + // warnings, + // unused, future_incompatible, nonstandard_style, rust_2018_idioms