From 212f29cfb9ba968757ea6bafd6039820b84f5a16 Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Mon, 5 Feb 2024 17:56:49 -0500 Subject: [PATCH] Add missing constraints mentioned by auditors (#1499) --- evm/src/arithmetic/arithmetic_stark.rs | 9 +++++++++ evm/src/logic.rs | 22 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/evm/src/arithmetic/arithmetic_stark.rs b/evm/src/arithmetic/arithmetic_stark.rs index dcf966ee59..5e3f039cdf 100644 --- a/evm/src/arithmetic/arithmetic_stark.rs +++ b/evm/src/arithmetic/arithmetic_stark.rs @@ -214,6 +214,10 @@ impl, const D: usize> Stark for ArithmeticSta yield_constr.constraint(flag * (flag - P::ONES)); } + // Only a single flag must be activated at once. + let all_flags = op_flags().map(|i| lv[i]).sum::

(); + yield_constr.constraint(all_flags * (all_flags - P::ONES)); + // Check that `OPCODE_COL` holds 0 if the operation is not a range_check. let opcode_constraint = (P::ONES - lv[columns::IS_RANGE_CHECK]) * lv[columns::OPCODE_COL]; yield_constr.constraint(opcode_constraint); @@ -261,6 +265,11 @@ impl, const D: usize> Stark for ArithmeticSta yield_constr.constraint(builder, constraint); } + // Only a single flag must be activated at once. + let all_flags = builder.add_many_extension(op_flags().map(|i| lv[i])); + let constraint = builder.mul_sub_extension(all_flags, all_flags, all_flags); + yield_constr.constraint(builder, constraint); + // Check that `OPCODE_COL` holds 0 if the operation is not a range_check. let opcode_constraint = builder.arithmetic_extension( F::NEG_ONE, diff --git a/evm/src/logic.rs b/evm/src/logic.rs index fa83fa94c1..7300c6af65 100644 --- a/evm/src/logic.rs +++ b/evm/src/logic.rs @@ -227,11 +227,19 @@ impl, const D: usize> Stark for LogicStark sum_coeff = 0, and_coeff = 1` // `OR => sum_coeff = 1, and_coeff = -1` @@ -276,11 +284,21 @@ impl, const D: usize> Stark for LogicStark sum_coeff = 0, and_coeff = 1` // `OR => sum_coeff = 1, and_coeff = -1`