From fff6d767e103f4fa5e4787883d41024adb143718 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 1 Nov 2023 11:42:09 -0700 Subject: [PATCH] minimum change to sanity check approach --- src/circuit/gadgets/constraints.rs | 36 ++---------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/circuit/gadgets/constraints.rs b/src/circuit/gadgets/constraints.rs index b2fb3c1ba1..765e3c0f96 100644 --- a/src/circuit/gadgets/constraints.rs +++ b/src/circuit/gadgets/constraints.rs @@ -74,45 +74,13 @@ pub(crate) fn enforce_equal_const> ); } -/// Adds a constraint to CS, enforcing a add relationship between the allocated numbers a, b, and sum. -/// -/// a + b = sum -pub(crate) fn enforce_sum>( - cs: &mut CS, - annotation: A, - a: &AllocatedNum, - b: &AllocatedNum, - sum: &AllocatedNum, -) where - A: FnOnce() -> AR, - AR: Into, -{ - // (a + b) * 1 = sum - cs.enforce( - annotation, - |lc| lc + a.get_variable() + b.get_variable(), - |lc| lc + CS::one(), - |lc| lc + sum.get_variable(), - ); -} - /// Compute sum and enforce it. pub(crate) fn add>( - mut cs: CS, + cs: CS, a: &AllocatedNum, b: &AllocatedNum, ) -> Result, SynthesisError> { - let res = AllocatedNum::alloc(cs.namespace(|| "add_num"), || { - let mut tmp = a.get_value().ok_or(SynthesisError::AssignmentMissing)?; - tmp.add_assign(&b.get_value().ok_or(SynthesisError::AssignmentMissing)?); - - Ok(tmp) - })?; - - // a + b = res - enforce_sum(&mut cs, || "sum constraint", a, b, &res); - - Ok(res) + a.add(cs, b) } /// Creates a linear combination representing the popcount (sum of one bits) of `v`.