diff --git a/kimchi/src/linearization.rs b/kimchi/src/linearization.rs index ae5d43ff0e..c8703bfca5 100644 --- a/kimchi/src/linearization.rs +++ b/kimchi/src/linearization.rs @@ -42,6 +42,7 @@ use ark_ff::{FftField, PrimeField, SquareRootField, Zero}; pub fn constraints_expr( feature_flags: Option<&FeatureFlags>, generic: bool, + needs_more_exponents: bool, ) -> (Expr, Column>, Alphas) { // register powers of alpha so that we don't reuse them across mutually inclusive constraints let mut powers_of_alpha = Alphas::::default(); @@ -49,13 +50,17 @@ 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 more_exponents = max( + KeccakRound::::CONSTRAINTS, + KeccakSponge::::CONSTRAINTS, + ); + if let Some(feature_flags) = feature_flags { if feature_flags.keccak { - max_exponents = max( - KeccakRound::::CONSTRAINTS, - KeccakSponge::::CONSTRAINTS, - ); + max_exponents = more_exponents } + } else if needs_more_exponents { + max_exponents = more_exponents } powers_of_alpha.register(ArgumentType::Gate(GateType::Zero), max_exponents); @@ -170,7 +175,7 @@ pub fn constraints_expr( if feature_flags.keccak { expr += keccak_round_expr(); } - } else { + } else if needs_more_exponents { expr += Expr::IfFeature( FeatureFlag::Keccak, Box::new(keccak_round_expr()), @@ -186,7 +191,7 @@ pub fn constraints_expr( if feature_flags.keccak { expr += keccak_sponge_expr(); } - } else { + } else if needs_more_exponents { expr += Expr::IfFeature( FeatureFlag::Keccak, Box::new(keccak_sponge_expr()), @@ -266,7 +271,8 @@ pub fn constraints_expr( // flags. if cfg!(feature = "check_feature_flags") { if let Some(feature_flags) = feature_flags { - let (feature_flagged_expr, _) = constraints_expr::(None, generic); + let (feature_flagged_expr, _) = + constraints_expr::(None, generic, feature_flags.keccak); let feature_flagged_expr = feature_flagged_expr.apply_feature_flags(feature_flags); assert_eq!(expr, feature_flagged_expr); } @@ -397,7 +403,7 @@ pub fn expr_linearization ) { let evaluated_cols = linearization_columns::(feature_flags); - let (expr, powers_of_alpha) = constraints_expr::(feature_flags, generic); + let (expr, powers_of_alpha) = constraints_expr::(feature_flags, generic, false); let linearization = expr .linearize(evaluated_cols)