From 24aeba651591aeca21a3583fc86785c1ba05df3b Mon Sep 17 00:00:00 2001 From: Arthur Paulino Date: Sat, 21 Oct 2023 08:47:28 -0300 Subject: [PATCH] fix LEM's Func::num_constraints and syntax parsing tests --- src/lem/circuit.rs | 11 +++++++++-- src/parser/syntax.rs | 8 ++++---- 2 files changed, 13 insertions(+), 6 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..baf4986eb7 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)))); @@ -891,7 +891,7 @@ pub mod tests { #[test] fn unit_parse_syntax_misc() { let vec: Vec = vec![ - 0x6e, 0x2e, 0x50, 0x55, 0xdc, 0xf6, 0x14, 0x86, 0xb0, 0x3b, 0xb8, 0x0e, 0xd2, 0xb3, + 0x3e, 0x2e, 0x50, 0x55, 0xdc, 0xf6, 0x14, 0x86, 0xb0, 0x3b, 0xb8, 0x0e, 0xd2, 0xb3, 0xf1, 0xa3, 0x5c, 0x30, 0xe1, 0x22, 0xde, 0xfe, 0xba, 0xe8, 0x24, 0xfa, 0xe4, 0xed, 0x32, 0x40, 0x8e, 0x87, ] @@ -908,7 +908,7 @@ pub mod tests { )); assert!(test( parse_syntax(state(), false, true), - "(0x6e2e5055dcf61486b03bb80ed2b3f1a35c30e122defebae824fae4ed32408e87)", + "(0x3e2e5055dcf61486b03bb80ed2b3f1a35c30e122defebae824fae4ed32408e87)", Some(list!([num!(Num::Scalar(f_from_le_bytes(&vec)))])), )); assert!(test(