diff --git a/src/zkevm_specs/evm/typing.py b/src/zkevm_specs/evm/typing.py index cec6dc81b..7c7ee3b49 100644 --- a/src/zkevm_specs/evm/typing.py +++ b/src/zkevm_specs/evm/typing.py @@ -742,23 +742,21 @@ def add(self, data: bytes, r: FQ) -> KeccakCircuit: class ExpCircuit: rows: List[ExpCircuitRow] - pad_rows: List[ExpCircuitRow] + max_exp_steps: int + OFFSET_INCREMENT = 7 - def __init__(self, pad_rows: Optional[List[ExpCircuitRow]] = None) -> None: + def __init__(self, max_exp_steps: int = 100) -> None: self.rows = [] - self.pad_rows = [] - if pad_rows is not None: - self.pad_rows = pad_rows + self.max_exp_steps = max_exp_steps def table(self) -> Sequence[ExpCircuitRow]: - return self.rows + self.pad_rows + return self.rows def add_event(self, base: int, exponent: int, randomness: FQ, identifier: IntOrFQ): steps: List[Tuple[int, int, int]] = [] exponentiation = self._exp_by_squaring(base, exponent, steps) steps.reverse() self._append_steps(base, exponent, exponentiation, steps, randomness, identifier) - self._append_padding_row(identifier) return self def _exp_by_squaring(self, base: int, exponent: int, steps: List[Tuple[int, int, int]]): @@ -816,24 +814,28 @@ def _append_steps( # exponent is odd exponent = exponent - 1 - def _append_padding_row(self, identifier: IntOrFQ): - self.rows.append( - ExpCircuitRow( - q_usable=FQ.zero(), - is_step=FQ.zero(), - identifier=FQ(identifier), - is_last=FQ.zero(), - base=RLC(0), - exponent=RLC(0), - exponentiation=RLC(0), - a=RLC(0), - b=RLC(0), - c=RLC(0), - d=RLC(0), - q=RLC(0), - r=RLC(0), + def fill_dummy_events(self): + max_exp_rows = self.max_exp_steps * self.OFFSET_INCREMENT + rows_left = max_exp_rows - len(self.rows) + for i in range(rows_left): + self.rows.append( + ExpCircuitRow( + q_usable=FQ.one(), + is_step=FQ.zero(), + identifier=FQ.zero(), + is_last=FQ.zero(), + base=RLC(1), + exponent=RLC(1), + exponentiation=RLC(1), + a=RLC(1), + b=RLC(1), + c=RLC(0), + d=RLC(1), + q=RLC(0), + r=RLC(1), + ) ) - ) + return self def _append_step( self, diff --git a/src/zkevm_specs/exp_circuit.py b/src/zkevm_specs/exp_circuit.py index ebe3941bc..5255da8fa 100644 --- a/src/zkevm_specs/exp_circuit.py +++ b/src/zkevm_specs/exp_circuit.py @@ -29,9 +29,6 @@ def verify_step(cs: ConstraintSystem, rows: List[ExpCircuitRow]): cs.constrain_bool(rows[0].is_last) # remainder (r), i.e. odd/even parity of exponent is boolean. cs.constrain_bool(rows[0].r) - # is_last == 1 is followed by unusable row. - # is_last == 0 is following by usable row. - cs.constrain_equal(rows[0].is_last, (1 - rows[1].q_usable)) # multiplication is assigned correctly _overflow, carry_lo_hi, additional_constraints = mul_add_words( rows[0].a, rows[0].b, rows[0].c, rows[0].d diff --git a/tests/evm/test_exp.py b/tests/evm/test_exp.py index 99dfba6a8..930fcf372 100644 --- a/tests/evm/test_exp.py +++ b/tests/evm/test_exp.py @@ -69,7 +69,9 @@ def test_exp(base: int, exponent: int): .stack_write(CALL_ID, 1023, exponentiation_rlc) ) - exp_circuit = ExpCircuit().add_event(base, exponent, randomness, rw_dict.rw_counter) + exp_circuit = ( + ExpCircuit().add_event(base, exponent, randomness, rw_dict.rw_counter).fill_dummy_events() + ) tables = Tables( block_table=set(Block().table_assignments(randomness)),