From 6e505a9fdf89ed0237300b6cc46d90333da51b01 Mon Sep 17 00:00:00 2001 From: David Nevado Date: Thu, 25 Jan 2024 17:11:50 +0100 Subject: [PATCH] fix nand --- maingate/src/instructions.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/maingate/src/instructions.rs b/maingate/src/instructions.rs index 230e24d2..47f9c465 100644 --- a/maingate/src/instructions.rs +++ b/maingate/src/instructions.rs @@ -885,14 +885,22 @@ pub trait MainGateInstructions: Chip { ctx: &mut RegionCtx<'_, F>, a: &AssignedCondition, b: &AssignedCondition, - ) -> Result<(), Error> { - self.apply( - ctx, - [Term::assigned_to_mul(a), Term::assigned_to_mul(b)], - F::ZERO, - CombinationOptionCommon::OneLinerMul.into(), - )?; - Ok(()) + ) -> Result, Error> { + // result + ab - 1 =0 + let result = a.value().zip(b.value()).map(|(a, b)| F::ONE - *a * b); + let result = self + .apply( + ctx, + [ + Term::assigned_to_mul(a), + Term::assigned_to_mul(b), + Term::unassigned_to_add(result), + ], + -F::ONE, + CombinationOptionCommon::OneLinerMul.into(), + )? + .swap_remove(2); + Ok(result) } /// Assigns a new witness `r` as: