From e74150dca26320b5c8a93bb808db19f92f8f014a Mon Sep 17 00:00:00 2001 From: Arthur Paulino Date: Sat, 21 Oct 2023 08:13:01 -0300 Subject: [PATCH] fix LEM's Func::num_constraints and syntax test unit_parse_num --- src/lem/circuit.rs | 11 +++++++++-- src/parser/syntax.rs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lem/circuit.rs b/src/lem/circuit.rs index d0114eb1fe..062ed28590 100644 --- a/src/lem/circuit.rs +++ b/src/lem/circuit.rs @@ -43,7 +43,7 @@ use crate::{ }, coprocessor::Coprocessor, eval::lang::Lang, - field::{FWrap, LurkField}, + field::{FWrap, LanguageField, LurkField}, tag::ExprTag::{Comm, Num, Sym}, }; @@ -1485,12 +1485,19 @@ impl Func { } } let globals = &mut HashSet::default(); + let bit_decomp_cost = match F::FIELD { + LanguageField::Pallas => 298, + LanguageField::Vesta => 301, + LanguageField::BLS12_381 => 388, + _ => todo!(), + }; + // fixed cost for each slot let slot_constraints = 289 * self.slot.hash4 + 337 * self.slot.hash6 + 388 * self.slot.hash8 + 265 * self.slot.commitment - + 388 * self.slot.bit_decomp; + + bit_decomp_cost * self.slot.bit_decomp; let num_constraints = recurse(&self.body, globals, store, false); slot_constraints + num_constraints + globals.len() } diff --git a/src/parser/syntax.rs b/src/parser/syntax.rs index e0ec71ff6b..b15b413efa 100644 --- a/src/parser/syntax.rs +++ b/src/parser/syntax.rs @@ -867,7 +867,7 @@ pub mod tests { )); assert!(test( parse_num(), - "0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000", + "0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000000", Some(Syntax::Num( Pos::No, Num::Scalar(::ZERO - Scalar::from(1u64)) @@ -875,7 +875,7 @@ pub mod tests { )); assert!(test( parse_num(), - "0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", + "0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001", None, )); assert!(test(parse_num(), "-0", Some(num!(0))));