diff --git a/src/zkevm_specs/evm_circuit/typing.py b/src/zkevm_specs/evm_circuit/typing.py index d4d35cc17..f2052d541 100644 --- a/src/zkevm_specs/evm_circuit/typing.py +++ b/src/zkevm_specs/evm_circuit/typing.py @@ -783,23 +783,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, 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, identifier) - self._append_padding_row(identifier) return self def _exp_by_squaring(self, base: int, exponent: int, steps: List[Tuple[int, int, int]]): @@ -856,24 +854,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=Word(0), - exponent=Word(0), - exponentiation=Word(0), - a=Word(0), - b=Word(0), - c=Word(0), - d=Word(0), - q=Word(0), - r=FQ(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=Word(1), + exponent=Word(1), + exponentiation=Word(1), + a=Word(1), + b=Word(1), + c=Word(0), + d=Word(1), + q=Word(0), + r=FQ(1), + ) ) - ) + return self def _append_step( self, diff --git a/src/zkevm_specs/exp_circuit.py b/src/zkevm_specs/exp_circuit.py index 24a5d0380..43d1190da 100644 --- a/src/zkevm_specs/exp_circuit.py +++ b/src/zkevm_specs/exp_circuit.py @@ -28,9 +28,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 f7a64b2a1..2b73a8040 100644 --- a/tests/evm/test_exp.py +++ b/tests/evm/test_exp.py @@ -62,7 +62,11 @@ def test_exp(base_int: int, exponent_int: int): .stack_write(CALL_ID, 1023, exponentiation) ) - exp_circuit = ExpCircuit().add_event(base.int_value(), exponent.int_value(), rw_dict.rw_counter) + exp_circuit = ( + ExpCircuit() + .add_event(base.int_value(), exponent.int_value(), rw_dict.rw_counter) + .fill_dummy_events() + ) tables = Tables( block_table=set(Block().table_assignments()),