From a7aacedfd3e4c3465a0e716ebd52dea1e0053c8f Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 26 Oct 2023 14:39:13 +0200 Subject: [PATCH 1/4] update generic columns for linearization width --- kimchi/src/linearization.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/kimchi/src/linearization.rs b/kimchi/src/linearization.rs index 74f1587292..2bf33114c7 100644 --- a/kimchi/src/linearization.rs +++ b/kimchi/src/linearization.rs @@ -26,7 +26,6 @@ use crate::circuits::{ constraints::FeatureFlags, expr::{Column, ConstantExpr, Expr, FeatureFlag, Linearization, PolishToken}, gate::GateType, - wires::COLUMNS, }; use ark_ff::{FftField, PrimeField, SquareRootField, Zero}; @@ -44,10 +43,8 @@ pub fn constraints_expr( // Set up powers of alpha. Only the max number of constraints matters. // The gate type argument can just be the zero gate. - powers_of_alpha.register( - ArgumentType::Gate(GateType::Zero), - VarbaseMul::::CONSTRAINTS, - ); + let mut max_exponents = VarbaseMul::::CONSTRAINTS; + powers_of_alpha.register(ArgumentType::Gate(GateType::Zero), max_exponents); let mut cache = expr::Cache::default(); @@ -234,7 +231,7 @@ pub fn constraints_expr( /// Adds the polynomials that are evaluated as part of the proof /// for the linearization to work. -pub fn linearization_columns( +pub fn linearization_columns( feature_flags: Option<&FeatureFlags>, ) -> std::collections::HashSet { let mut h = std::collections::HashSet::new(); @@ -267,12 +264,12 @@ pub fn linearization_columns( }; // the witness polynomials - for i in 0..COLUMNS { + for i in 0..W { h.insert(Witness(i)); } // the coefficient polynomials - for i in 0..COLUMNS { + for i in 0..W { h.insert(Coefficient(i)); } @@ -320,7 +317,7 @@ pub fn expr_linearization( feature_flags: Option<&FeatureFlags>, generic: bool, ) -> (Linearization>>, Alphas) { - let evaluated_cols = linearization_columns::(feature_flags); + let evaluated_cols = linearization_columns::(feature_flags); let (expr, powers_of_alpha) = constraints_expr::(feature_flags, generic); From 7d3b563f81f329061e6794653a8dc759087ba1bb Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 26 Oct 2023 14:40:54 +0200 Subject: [PATCH 2/4] update length of vector with constant instead of hard coded --- kimchi/src/circuits/polynomials/keccak/gadget.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kimchi/src/circuits/polynomials/keccak/gadget.rs b/kimchi/src/circuits/polynomials/keccak/gadget.rs index 83b75e3294..a620645d81 100644 --- a/kimchi/src/circuits/polynomials/keccak/gadget.rs +++ b/kimchi/src/circuits/polynomials/keccak/gadget.rs @@ -56,7 +56,7 @@ impl CircuitGate { } fn create_keccak_absorb(new_row: usize, root: bool, pad: bool, pad_bytes: usize) -> Self { - let mut coeffs = vec![F::zero(); 336]; + let mut coeffs = vec![F::zero(); SPONGE_COEFFS]; coeffs[0] = F::one(); // absorb if root { coeffs[2] = F::one(); // root @@ -66,10 +66,10 @@ impl CircuitGate { for i in 0..pad_bytes { coeffs[140 - i] = F::one(); // flag for padding if i == 0 { - coeffs[335 - i] += F::from(0x80u8); // pad + coeffs[SPONGE_COEFFS - 1 - i] += F::from(0x80u8); // pad } if i == pad_bytes - 1 { - coeffs[335 - i] += F::one(); // pad + coeffs[SPONGE_COEFFS - 1 - i] += F::one(); // pad } } } From 0447d8217bd9e36890fd3f41054368618476c740 Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 26 Oct 2023 14:49:02 +0200 Subject: [PATCH 3/4] remove unneeded mut --- kimchi/src/linearization.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kimchi/src/linearization.rs b/kimchi/src/linearization.rs index 2bf33114c7..054afee920 100644 --- a/kimchi/src/linearization.rs +++ b/kimchi/src/linearization.rs @@ -43,7 +43,7 @@ pub fn constraints_expr( // Set up powers of alpha. Only the max number of constraints matters. // The gate type argument can just be the zero gate. - let mut max_exponents = VarbaseMul::::CONSTRAINTS; + let max_exponents = VarbaseMul::::CONSTRAINTS; powers_of_alpha.register(ArgumentType::Gate(GateType::Zero), max_exponents); let mut cache = expr::Cache::default(); From b8bdbf2ccbdcb9b3169aff52893a2bb6876bca61 Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 26 Oct 2023 14:51:17 +0200 Subject: [PATCH 4/4] use larger exponent if keccak in use --- kimchi/src/linearization.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kimchi/src/linearization.rs b/kimchi/src/linearization.rs index eb79cbc39c..9ae1c4f5e5 100644 --- a/kimchi/src/linearization.rs +++ b/kimchi/src/linearization.rs @@ -9,6 +9,7 @@ use crate::circuits::lookup::{ lookups::{LookupFeatures, LookupInfo, LookupPatterns}, }; use crate::circuits::polynomials::keccak; +use crate::circuits::polynomials::keccak::circuitgates::KeccakRound; use crate::circuits::polynomials::{ complete_add::CompleteAdd, endomul_scalar::EndomulScalar, @@ -44,7 +45,12 @@ pub fn constraints_expr( // Set up powers of alpha. Only the max number of constraints matters. // The gate type argument can just be the zero gate. - let max_exponents = VarbaseMul::::CONSTRAINTS; + let mut max_exponents = VarbaseMul::::CONSTRAINTS; + if let Some(feature_flags) = feature_flags { + if feature_flags.keccak_round { + max_exponents = KeccakRound::::CONSTRAINTS; + } + } powers_of_alpha.register(ArgumentType::Gate(GateType::Zero), max_exponents); let mut cache = expr::Cache::default();