From 0b939b92876205e62dd3ca62b688d55c9355a5a7 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Fri, 14 Jan 2022 17:03:35 +0800 Subject: [PATCH 01/10] init: increase RwTable size --- src/zkevm_specs/evm/instruction.py | 19 ++++++------------- src/zkevm_specs/evm/table.py | 24 +++++++++++++----------- src/zkevm_specs/util/typing.py | 1 + 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/zkevm_specs/evm/instruction.py b/src/zkevm_specs/evm/instruction.py index c8bf630e5..3802223fa 100644 --- a/src/zkevm_specs/evm/instruction.py +++ b/src/zkevm_specs/evm/instruction.py @@ -2,7 +2,7 @@ from enum import IntEnum, auto from typing import Optional, Sequence, Tuple, Union -from ..util import Array4, Array8, linear_combine, RLCStore, MAX_N_BYTES, N_BYTES_GAS +from ..util import Array4, Array10, linear_combine, RLCStore, MAX_N_BYTES, N_BYTES_GAS from .opcode import Opcode from .step import StepState from .table import ( @@ -259,7 +259,7 @@ def opcode_lookup_at(self, index: int, is_code: bool) -> int: else: return self.bytecode_lookup(self.curr.opcode_source, index, is_code) - def rw_lookup(self, rw: RW, tag: RWTableTag, inputs: Sequence[int], rw_counter: Optional[int] = None) -> Array8: + def rw_lookup(self, rw: RW, tag: RWTableTag, inputs: Sequence[int], rw_counter: Optional[int] = None) -> Array10: if rw_counter is None: rw_counter = self.curr.rw_counter + self.rw_counter_offset self.rw_counter_offset += 1 @@ -271,13 +271,13 @@ def state_write_only_persistent( tag: RWTableTag, inputs: Sequence[int], is_persistent: bool, - ) -> Array8: + ) -> Array10: assert tag.write_only_persistent() if is_persistent: return self.rw_lookup(RW.Write, tag, inputs) - return 8 * [None] + return 10 * [None] def state_write_with_reversion( self, @@ -285,7 +285,7 @@ def state_write_with_reversion( inputs: Sequence[int], is_persistent: bool, rw_counter_end_of_reversion: int, - ) -> Array8: + ) -> Array10: assert tag.write_with_reversion() row = self.rw_lookup(RW.Write, tag, inputs) @@ -296,14 +296,7 @@ def state_write_with_reversion( if not is_persistent: # Swap value and value_prev inputs = list(row[3:]) - if tag == RWTableTag.TxAccessListAccount: - inputs[2], inputs[3] = inputs[3], inputs[2] - elif tag == RWTableTag.TxAccessListStorageSlot: - inputs[3], inputs[4] = inputs[4], inputs[3] - elif tag == RWTableTag.Account: - inputs[2], inputs[3] = inputs[3], inputs[2] - elif tag == RWTableTag.AccountStorage: - inputs[3], inputs[4] = inputs[4], inputs[3] + inputs[-3], inputs[-4] = inputs[-4], inputs[-3] self.rw_lookup(RW.Write, tag, inputs, rw_counter=rw_counter) return row diff --git a/src/zkevm_specs/evm/table.py b/src/zkevm_specs/evm/table.py index a970b09d2..13a566dac 100644 --- a/src/zkevm_specs/evm/table.py +++ b/src/zkevm_specs/evm/table.py @@ -1,7 +1,7 @@ from typing import Sequence, Set, Tuple from enum import IntEnum, auto -from ..util import Array3, Array4, Array8 +from ..util import Array3, Array4, Array10 from .execution_state import ExecutionState from .opcode import ( invalid_opcodes, @@ -244,20 +244,22 @@ class Tables: # Each row in RWTable contains: # - rw_counter # - is_write - # - tag - # - value1 - # - value2 - # - value3 - # - value4 - # - value5 - rw_table: Set[Array8] + # - key1 (tag) + # - key2 + # - key3 + # - key4 + # - value + # - value_prev + # - aux1 + # - aux2 + rw_table: Set[Array10] def __init__( self, block_table: Set[Array3], tx_table: Set[Array4], bytecode_table: Set[Array4], - rw_table: Set[Array8], + rw_table: Set[Array10], ) -> None: self.block_table = block_table self.tx_table = tx_table @@ -280,8 +282,8 @@ def bytecode_lookup(self, inputs: Sequence[int]) -> Array4: assert len(inputs) <= 4 return _lookup("bytecode_table", self.bytecode_table, inputs) - def rw_lookup(self, inputs: Sequence[int]) -> Array8: - assert len(inputs) <= 8 + def rw_lookup(self, inputs: Sequence[int]) -> Array10: + assert len(inputs) <= 10 return _lookup("rw_table", self.rw_table, inputs) diff --git a/src/zkevm_specs/util/typing.py b/src/zkevm_specs/util/typing.py index 370f562db..0ab5b8234 100644 --- a/src/zkevm_specs/util/typing.py +++ b/src/zkevm_specs/util/typing.py @@ -8,6 +8,7 @@ Array3 = NewType("Array3", Tuple[int, int, int]) Array4 = NewType("Array4", Tuple[int, int, int, int]) Array8 = NewType("Array8", Tuple[int, int, int, int, int, int, int, int]) +Array10 = NewType("Array10", Tuple[int, int, int, int, int, int, int, int, int, int]) Array32 = NewType( "Array32", Tuple[ From 74198e373818ef1e5d0999bb93919d811e43805d Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 17 Jan 2022 09:57:25 +0800 Subject: [PATCH 02/10] fix test except begin_tx --- tests/evm/test_add.py | 6 +++--- tests/evm/test_coinbase.py | 2 +- tests/evm/test_jump.py | 2 +- tests/evm/test_jumpi.py | 4 ++-- tests/evm/test_push.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/evm/test_add.py b/tests/evm/test_add.py index 8ba0371b8..558a33467 100644 --- a/tests/evm/test_add.py +++ b/tests/evm/test_add.py @@ -45,9 +45,9 @@ def test_add(opcode: Opcode, a_bytes: bytes, b_bytes: bytes, c_bytes: Optional[b bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1022, a, 0, 0), - (10, RW.Read, RWTableTag.Stack, 1, 1023, b, 0, 0), - (11, RW.Write, RWTableTag.Stack, 1, 1023, c, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1022, a, 0, 0, 0, 0), + (10, RW.Read, RWTableTag.Stack, 1, 1023, b, 0, 0, 0, 0), + (11, RW.Write, RWTableTag.Stack, 1, 1023, c, 0, 0, 0, 0), ] ), ) diff --git a/tests/evm/test_coinbase.py b/tests/evm/test_coinbase.py index e82f43995..b5d5ec771 100644 --- a/tests/evm/test_coinbase.py +++ b/tests/evm/test_coinbase.py @@ -32,7 +32,7 @@ def test_coinbase(opcode: Opcode, address: U160): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Write, RWTableTag.Stack, 1, 1023, coinbase_rlc, 0, 0), + (9, RW.Write, RWTableTag.Stack, 1, 1023, coinbase_rlc, 0, 0, 0, 0), ] ), ) diff --git a/tests/evm/test_jump.py b/tests/evm/test_jump.py index 8e6cb1769..e8fc0fed5 100644 --- a/tests/evm/test_jump.py +++ b/tests/evm/test_jump.py @@ -35,7 +35,7 @@ def test_jump(opcode: Opcode, dest_bytes: bytes): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1021, dest, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1021, dest, 0, 0, 0, 0), ] ), ) diff --git a/tests/evm/test_jumpi.py b/tests/evm/test_jumpi.py index 221796fee..0b59d8c95 100644 --- a/tests/evm/test_jumpi.py +++ b/tests/evm/test_jumpi.py @@ -93,8 +93,8 @@ def test_jumpi_cond_zero(opcode: Opcode, cond_bytes: bytes, dest_bytes: bytes): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1021, dest, 0, 0), - (10, RW.Read, RWTableTag.Stack, 1, 1022, cond, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1021, dest, 0, 0, 0, 0), + (10, RW.Read, RWTableTag.Stack, 1, 1022, cond, 0, 0, 0, 0), ], ), ) diff --git a/tests/evm/test_push.py b/tests/evm/test_push.py index d663a2aaf..dc171bd39 100644 --- a/tests/evm/test_push.py +++ b/tests/evm/test_push.py @@ -41,7 +41,7 @@ def test_push(opcode: Opcode, value_be_bytes: bytes): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (8, RW.Write, RWTableTag.Stack, 1, 1023, value, 0, 0), + (8, RW.Write, RWTableTag.Stack, 1, 1023, value, 0, 0, 0, 0), ] ), ) From ee16a519860542d51b800975a940b5b2f7ab319c Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 17 Jan 2022 10:26:14 +0800 Subject: [PATCH 03/10] fix test_ begin_tx --- src/zkevm_specs/evm/instruction.py | 22 +++++++++--------- tests/evm/test_begin_tx.py | 36 +++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/zkevm_specs/evm/instruction.py b/src/zkevm_specs/evm/instruction.py index 3802223fa..380d3e22b 100644 --- a/src/zkevm_specs/evm/instruction.py +++ b/src/zkevm_specs/evm/instruction.py @@ -330,7 +330,7 @@ def account_write( RWTableTag.Account, [account_address, account_field_tag], ) - return row[5], row[6] + return row[-4], row[-3] def account_write_with_reversion( self, @@ -345,7 +345,7 @@ def account_write_with_reversion( is_persistent, rw_counter_end_of_reversion, ) - return row[5], row[6] + return row[-4], row[-3] def add_balance(self, account_address: int, values: Sequence[int]): balance, balance_prev = self.account_write(account_address, AccountFieldTag.Balance) @@ -389,7 +389,7 @@ def sub_balance_with_reversion( def account_read(self, account_address: int, account_field_tag: AccountFieldTag) -> Tuple[int, int]: row = self.rw_lookup(RW.Read, RWTableTag.Account, [account_address, account_field_tag]) - return row[5], row[6] + return row[-4], row[-3] def add_account_to_access_list( self, @@ -399,9 +399,9 @@ def add_account_to_access_list( row = self.rw_lookup( RW.Write, RWTableTag.TxAccessListAccount, - [tx_id, account_address, 1], + [tx_id, account_address, 0, 1], ) - return row[5] - row[6] + return row[-4] - row[-3] def add_account_to_access_list_with_reversion( self, @@ -412,11 +412,11 @@ def add_account_to_access_list_with_reversion( ) -> bool: row = self.state_write_with_reversion( RWTableTag.TxAccessListAccount, - [tx_id, account_address, 1], + [tx_id, account_address, 0, 1], is_persistent, rw_counter_end_of_reversion, ) - return row[5] - row[6] + return row[-4] - row[-3] def add_storage_slot_to_access_list( self, @@ -425,10 +425,10 @@ def add_storage_slot_to_access_list( storage_slot: int, ) -> bool: row = self.state_write_with_reversion( - RWTableTag.TxAccessListAccount, + RWTableTag.TxAccessListStorageSlot, [tx_id, account_address, storage_slot, 1], ) - return row[6] - row[7] + return row[-4] - row[-3] def add_storage_slot_to_access_list_with_reversion( self, @@ -439,12 +439,12 @@ def add_storage_slot_to_access_list_with_reversion( rw_counter_end_of_reversion: int, ) -> bool: row = self.state_write_with_reversion( - RWTableTag.TxAccessListAccount, + RWTableTag.TxAccessListStorageSlot, [tx_id, account_address, storage_slot, 1], is_persistent, rw_counter_end_of_reversion, ) - return row[6] - row[7] + return row[-4] - row[-3] def transfer_with_gas_fee( self, diff --git a/tests/evm/test_begin_tx.py b/tests/evm/test_begin_tx.py index 9908a97a6..2b12b9c85 100644 --- a/tests/evm/test_begin_tx.py +++ b/tests/evm/test_begin_tx.py @@ -58,7 +58,7 @@ def test_begin_tx(tx: Transaction, result: bool): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (1, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, 1, 0, 0), + (1, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, 1, 0, 0, 0, 0), ( 2, RW.Read, @@ -68,20 +68,24 @@ def test_begin_tx(tx: Transaction, result: bool): 0 if result else 20, 0, 0, + 0, + 0, ), - (3, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.IsPersistent, result, 0, 0), - (4, RW.Write, RWTableTag.Account, tx.caller_address, AccountFieldTag.Nonce, tx.nonce + 1, tx.nonce, 0), - (5, RW.Write, RWTableTag.TxAccessListAccount, 1, tx.caller_address, 1, 0, 0), - (6, RW.Write, RWTableTag.TxAccessListAccount, 1, tx.callee_address, 1, 0, 0), + (3, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.IsPersistent, result, 0, 0, 0, 0), + (4, RW.Write, RWTableTag.Account, tx.caller_address, AccountFieldTag.Nonce, 0, tx.nonce + 1, tx.nonce, 0, 0), + (5, RW.Write, RWTableTag.TxAccessListAccount, 1, tx.caller_address, 0, 1, 0, 0, 0), + (6, RW.Write, RWTableTag.TxAccessListAccount, 1, tx.callee_address, 0, 1, 0, 0, 0), ( 7, RW.Write, RWTableTag.Account, tx.caller_address, AccountFieldTag.Balance, + 0, caller_balance, caller_balance_prev, 0, + 0, ), ( 8, @@ -89,9 +93,11 @@ def test_begin_tx(tx: Transaction, result: bool): RWTableTag.Account, tx.callee_address, AccountFieldTag.Balance, + 0, callee_balance, callee_balance_prev, 0, + 0, ), ( 9, @@ -99,15 +105,17 @@ def test_begin_tx(tx: Transaction, result: bool): RWTableTag.Account, tx.callee_address, AccountFieldTag.CodeHash, + 0, bytecode_hash, bytecode_hash, 0, + 0, ), - (10, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.Depth, 1, 0, 0), - (11, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallerAddress, tx.caller_address, 0, 0), - (12, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CalleeAddress, tx.callee_address, 0, 0), - (13, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataOffset, 0, 0, 0), - (14, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataLength, len(tx.call_data), 0, 0), + (10, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.Depth, 1, 0, 0, 0, 0), + (11, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallerAddress, tx.caller_address, 0, 0, 0, 0), + (12, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CalleeAddress, tx.callee_address, 0, 0, 0, 0), + (13, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataOffset, 0, 0, 0, 0, 0), + (14, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataLength, len(tx.call_data), 0, 0, 0, 0), ( 15, RW.Read, @@ -117,8 +125,10 @@ def test_begin_tx(tx: Transaction, result: bool): rlc_store.to_rlc(tx.value, 32), 0, 0, + 0, + 0, ), - (16, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.IsStatic, 0, 0, 0), + (16, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.IsStatic, 0, 0, 0, 0, 0), ] + ( [] @@ -130,9 +140,11 @@ def test_begin_tx(tx: Transaction, result: bool): RWTableTag.Account, tx.callee_address, AccountFieldTag.Balance, + 0, callee_balance_prev, callee_balance, 0, + 0, ), ( 20, @@ -140,9 +152,11 @@ def test_begin_tx(tx: Transaction, result: bool): RWTableTag.Account, tx.caller_address, AccountFieldTag.Balance, + 0, caller_balance_prev, caller_balance, 0, + 0, ), ] ) From a2dea647eaf32582b067735306843bac1fc3dfb9 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 17 Jan 2022 10:48:02 +0800 Subject: [PATCH 04/10] clean up --- src/zkevm_specs/evm/table.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/zkevm_specs/evm/table.py b/src/zkevm_specs/evm/table.py index 13a566dac..fc186e16f 100644 --- a/src/zkevm_specs/evm/table.py +++ b/src/zkevm_specs/evm/table.py @@ -108,15 +108,8 @@ def write_with_reversion(self) -> bool: RWTableTag.TxAccessListStorageSlot, RWTableTag.Account, RWTableTag.AccountStorage, - ] - - # For state writes which don't affect future execution before reversion, we - # don't need to write them with reversion, instead we only need to write - # them (enable the lookup) when is_persistent is True. - def write_only_persistent(self) -> bool: - return self in [ - RWTableTag.TxRefund, RWTableTag.AccountDestructed, + RWTableTag.TxRefund, ] From b69f88ebe76364be22f72d0669f52bdd14fccfae Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 17 Jan 2022 10:52:00 +0800 Subject: [PATCH 05/10] lint codes --- tests/evm/test_begin_tx.py | 52 +++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/tests/evm/test_begin_tx.py b/tests/evm/test_begin_tx.py index 2b12b9c85..2c26c0f17 100644 --- a/tests/evm/test_begin_tx.py +++ b/tests/evm/test_begin_tx.py @@ -72,7 +72,18 @@ def test_begin_tx(tx: Transaction, result: bool): 0, ), (3, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.IsPersistent, result, 0, 0, 0, 0), - (4, RW.Write, RWTableTag.Account, tx.caller_address, AccountFieldTag.Nonce, 0, tx.nonce + 1, tx.nonce, 0, 0), + ( + 4, + RW.Write, + RWTableTag.Account, + tx.caller_address, + AccountFieldTag.Nonce, + 0, + tx.nonce + 1, + tx.nonce, + 0, + 0, + ), (5, RW.Write, RWTableTag.TxAccessListAccount, 1, tx.caller_address, 0, 1, 0, 0, 0), (6, RW.Write, RWTableTag.TxAccessListAccount, 1, tx.callee_address, 0, 1, 0, 0, 0), ( @@ -112,10 +123,43 @@ def test_begin_tx(tx: Transaction, result: bool): 0, ), (10, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.Depth, 1, 0, 0, 0, 0), - (11, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallerAddress, tx.caller_address, 0, 0, 0, 0), - (12, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CalleeAddress, tx.callee_address, 0, 0, 0, 0), + ( + 11, + RW.Read, + RWTableTag.CallContext, + 1, + CallContextFieldTag.CallerAddress, + tx.caller_address, + 0, + 0, + 0, + 0, + ), + ( + 12, + RW.Read, + RWTableTag.CallContext, + 1, + CallContextFieldTag.CalleeAddress, + tx.callee_address, + 0, + 0, + 0, + 0, + ), (13, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataOffset, 0, 0, 0, 0, 0), - (14, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataLength, len(tx.call_data), 0, 0, 0, 0), + ( + 14, + RW.Read, + RWTableTag.CallContext, + 1, + CallContextFieldTag.CallDataLength, + len(tx.call_data), + 0, + 0, + 0, + 0, + ), ( 15, RW.Read, From c110cb193799cf4a4fbfd73efea1c1cf85dd3878 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 17 Jan 2022 15:09:03 +0800 Subject: [PATCH 06/10] fix call_context_lookup --- src/zkevm_specs/evm/instruction.py | 2 +- tests/evm/test_begin_tx.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/zkevm_specs/evm/instruction.py b/src/zkevm_specs/evm/instruction.py index 380d3e22b..0a6de00c2 100644 --- a/src/zkevm_specs/evm/instruction.py +++ b/src/zkevm_specs/evm/instruction.py @@ -305,7 +305,7 @@ def call_context_lookup(self, tag: CallContextFieldTag, rw: RW = RW.Read, call_i if call_id is None: call_id = self.curr.call_id - return self.rw_lookup(rw, RWTableTag.CallContext, [call_id, tag])[5] + return self.rw_lookup(rw, RWTableTag.CallContext, [call_id, tag])[-4] def stack_pop(self) -> int: stack_pointer_offset = self.stack_pointer_offset diff --git a/tests/evm/test_begin_tx.py b/tests/evm/test_begin_tx.py index 2c26c0f17..f3072d095 100644 --- a/tests/evm/test_begin_tx.py +++ b/tests/evm/test_begin_tx.py @@ -58,20 +58,20 @@ def test_begin_tx(tx: Transaction, result: bool): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (1, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, 1, 0, 0, 0, 0), + (1, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, 0, 1, 0, 0, 0), ( 2, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.RWCounterEndOfReversion, - 0 if result else 20, 0, + 0 if result else 20, 0, 0, 0, ), - (3, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.IsPersistent, result, 0, 0, 0, 0), + (3, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.IsPersistent, 0, result, 0, 0, 0), ( 4, RW.Write, @@ -122,15 +122,15 @@ def test_begin_tx(tx: Transaction, result: bool): 0, 0, ), - (10, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.Depth, 1, 0, 0, 0, 0), + (10, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.Depth, 0, 1, 0, 0, 0), ( 11, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallerAddress, - tx.caller_address, 0, + tx.caller_address, 0, 0, 0, @@ -141,8 +141,8 @@ def test_begin_tx(tx: Transaction, result: bool): RWTableTag.CallContext, 1, CallContextFieldTag.CalleeAddress, - tx.callee_address, 0, + tx.callee_address, 0, 0, 0, @@ -154,8 +154,8 @@ def test_begin_tx(tx: Transaction, result: bool): RWTableTag.CallContext, 1, CallContextFieldTag.CallDataLength, - len(tx.call_data), 0, + len(tx.call_data), 0, 0, 0, @@ -166,8 +166,8 @@ def test_begin_tx(tx: Transaction, result: bool): RWTableTag.CallContext, 1, CallContextFieldTag.Value, - rlc_store.to_rlc(tx.value, 32), 0, + rlc_store.to_rlc(tx.value, 32), 0, 0, 0, From d7d3557689554ad95f15513be54a095ea23885d9 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 17 Jan 2022 16:03:54 +0800 Subject: [PATCH 07/10] fix stack_lookup --- src/zkevm_specs/evm/instruction.py | 2 +- tests/evm/test_add.py | 6 +++--- tests/evm/test_coinbase.py | 2 +- tests/evm/test_jump.py | 2 +- tests/evm/test_jumpi.py | 8 ++++---- tests/evm/test_push.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/zkevm_specs/evm/instruction.py b/src/zkevm_specs/evm/instruction.py index 0a6de00c2..b45125727 100644 --- a/src/zkevm_specs/evm/instruction.py +++ b/src/zkevm_specs/evm/instruction.py @@ -318,7 +318,7 @@ def stack_push(self) -> int: def stack_lookup(self, rw: RW, stack_pointer_offset: int) -> int: stack_pointer = self.curr.stack_pointer + stack_pointer_offset - return self.rw_lookup(rw, RWTableTag.Stack, [self.curr.call_id, stack_pointer])[5] + return self.rw_lookup(rw, RWTableTag.Stack, [self.curr.call_id, stack_pointer])[-4] def account_write( self, diff --git a/tests/evm/test_add.py b/tests/evm/test_add.py index 558a33467..40ab84e06 100644 --- a/tests/evm/test_add.py +++ b/tests/evm/test_add.py @@ -45,9 +45,9 @@ def test_add(opcode: Opcode, a_bytes: bytes, b_bytes: bytes, c_bytes: Optional[b bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1022, a, 0, 0, 0, 0), - (10, RW.Read, RWTableTag.Stack, 1, 1023, b, 0, 0, 0, 0), - (11, RW.Write, RWTableTag.Stack, 1, 1023, c, 0, 0, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1022, 0, a, 0, 0, 0), + (10, RW.Read, RWTableTag.Stack, 1, 1023, 0, b, 0, 0, 0), + (11, RW.Write, RWTableTag.Stack, 1, 1023, 0, c, 0, 0, 0), ] ), ) diff --git a/tests/evm/test_coinbase.py b/tests/evm/test_coinbase.py index b5d5ec771..fa65aa5cd 100644 --- a/tests/evm/test_coinbase.py +++ b/tests/evm/test_coinbase.py @@ -32,7 +32,7 @@ def test_coinbase(opcode: Opcode, address: U160): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Write, RWTableTag.Stack, 1, 1023, coinbase_rlc, 0, 0, 0, 0), + (9, RW.Write, RWTableTag.Stack, 1, 1023, 0, coinbase_rlc, 0, 0, 0), ] ), ) diff --git a/tests/evm/test_jump.py b/tests/evm/test_jump.py index e8fc0fed5..8b817d11c 100644 --- a/tests/evm/test_jump.py +++ b/tests/evm/test_jump.py @@ -35,7 +35,7 @@ def test_jump(opcode: Opcode, dest_bytes: bytes): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1021, dest, 0, 0, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1021, 0, dest, 0, 0, 0), ] ), ) diff --git a/tests/evm/test_jumpi.py b/tests/evm/test_jumpi.py index 0b59d8c95..be45890bd 100644 --- a/tests/evm/test_jumpi.py +++ b/tests/evm/test_jumpi.py @@ -36,8 +36,8 @@ def test_jumpi_cond_nonzero(opcode: Opcode, cond_bytes: bytes, dest_bytes: bytes bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1021, dest, 0, 0), - (10, RW.Read, RWTableTag.Stack, 1, 1022, cond, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1021, 0, dest, 0, 0, 0), + (10, RW.Read, RWTableTag.Stack, 1, 1022, 0, cond, 0, 0, 0), ], ), ) @@ -93,8 +93,8 @@ def test_jumpi_cond_zero(opcode: Opcode, cond_bytes: bytes, dest_bytes: bytes): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1021, dest, 0, 0, 0, 0), - (10, RW.Read, RWTableTag.Stack, 1, 1022, cond, 0, 0, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1021, 0, dest, 0, 0, 0), + (10, RW.Read, RWTableTag.Stack, 1, 1022, 0, cond, 0, 0, 0), ], ), ) diff --git a/tests/evm/test_push.py b/tests/evm/test_push.py index dc171bd39..e8b56a49b 100644 --- a/tests/evm/test_push.py +++ b/tests/evm/test_push.py @@ -41,7 +41,7 @@ def test_push(opcode: Opcode, value_be_bytes: bytes): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (8, RW.Write, RWTableTag.Stack, 1, 1023, value, 0, 0, 0, 0), + (8, RW.Write, RWTableTag.Stack, 1, 1023, 0, value, 0, 0, 0), ] ), ) From fc3bf7935478ed4749f9573ee7df8cc2bf2c43f6 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 17 Jan 2022 18:12:57 +0800 Subject: [PATCH 08/10] update --- tests/evm/test_caller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/evm/test_caller.py b/tests/evm/test_caller.py index 9668f3af0..83346b86c 100644 --- a/tests/evm/test_caller.py +++ b/tests/evm/test_caller.py @@ -31,8 +31,8 @@ def test_caller(opcode: Opcode, address: U160): bytecode_table=set(bytecode.table_assignments(rlc_store)), rw_table=set( [ - (9, RW.Write, RWTableTag.Stack, 1, 1023, caller_rlc, 0, 0), - (10, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallerAddress, address, 0, 0), + (9, RW.Write, RWTableTag.Stack, 1, 1023, 0, caller_rlc, 0, 0, 0), + (10, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallerAddress, 0, address, 0, 0, 0), ] ), ) From a4b426736d305fa7c3cccbe744dbe0bf75c92496 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Thu, 20 Jan 2022 11:17:48 +0800 Subject: [PATCH 09/10] fix --- src/zkevm_specs/evm/instruction.py | 4 ++-- tests/evm/test_end_block.py | 2 +- tests/evm/test_end_tx.py | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/zkevm_specs/evm/instruction.py b/src/zkevm_specs/evm/instruction.py index dd217cb9e..d9a570682 100644 --- a/src/zkevm_specs/evm/instruction.py +++ b/src/zkevm_specs/evm/instruction.py @@ -516,7 +516,7 @@ def add_account_to_access_list( row = self.rw_lookup( RW.Write, RWTableTag.TxAccessListAccount, - [tx_id, account_address, 1], + [tx_id, account_address, 0, 1], ) return row[-4] - row[-3] @@ -530,7 +530,7 @@ def add_account_to_access_list_with_reversion( ) -> bool: row = self.state_write_with_reversion( RWTableTag.TxAccessListAccount, - [tx_id, account_address, 1], + [tx_id, account_address, 0, 1], is_persistent, rw_counter_end_of_reversion, state_write_counter, diff --git a/tests/evm/test_end_block.py b/tests/evm/test_end_block.py index 21873f85b..005b1be8f 100644 --- a/tests/evm/test_end_block.py +++ b/tests/evm/test_end_block.py @@ -31,7 +31,7 @@ def test_end_block(is_last_step: bool): chain( # dummy read/write for counting [(i, *7 * [0]) for i in range(22)], - [(22, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, tx.id, 0, 0)] + [(22, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, 0, tx.id, 0, 0, 0)] if is_last_step else [], ) diff --git a/tests/evm/test_end_tx.py b/tests/evm/test_end_tx.py index b69725937..284ce88f3 100644 --- a/tests/evm/test_end_tx.py +++ b/tests/evm/test_end_tx.py @@ -58,17 +58,19 @@ def test_end_tx(tx: Transaction, gas_left: int, refund: int, is_last_tx: bool): bytecode_table=set(), rw_table=set( [ - (17, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, tx.id, 0, 0), - (18, RW.Read, RWTableTag.TxRefund, tx.id, refund, refund, 0, 0), + (17, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.TxId, 0, tx.id, 0, 0, 0), + (18, RW.Read, RWTableTag.TxRefund, tx.id, 0, 0, refund, refund, 0, 0), ( 19, RW.Write, RWTableTag.Account, tx.caller_address, AccountFieldTag.Balance, + 0, RLC(caller_balance, randomness), RLC(caller_balance_prev, randomness), 0, + 0, ), ( 20, @@ -76,15 +78,17 @@ def test_end_tx(tx: Transaction, gas_left: int, refund: int, is_last_tx: bool): RWTableTag.Account, block.coinbase, AccountFieldTag.Balance, + 0, RLC(coinbase_balance, randomness), RLC(coinbase_balance_prev, randomness), 0, + 0, ), ] + ( [] if is_last_tx - else [(21, RW.Read, RWTableTag.CallContext, 22, CallContextFieldTag.TxId, tx.id + 1, 0, 0)] + else [(21, RW.Read, RWTableTag.CallContext, 22, CallContextFieldTag.TxId, 0, tx.id + 1, 0, 0, 0)] ) ), ) From 47b195badf9981a4ed1625da7a086e65ac69b9ce Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Mon, 24 Jan 2022 12:16:38 +0800 Subject: [PATCH 10/10] fix --- tests/evm/test_calldatasize.py | 4 ++-- tests/evm/test_caller.py | 2 +- tests/evm/test_callvalue.py | 4 ++-- tests/evm/test_slt_sgt.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/evm/test_calldatasize.py b/tests/evm/test_calldatasize.py index 84bbeecac..0f652fee3 100644 --- a/tests/evm/test_calldatasize.py +++ b/tests/evm/test_calldatasize.py @@ -35,8 +35,8 @@ def test_calldatasize(calldatasize: U64): bytecode_table=set(bytecode.table_assignments(randomness)), rw_table=set( [ - (9, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataLength, calldatasize, 0, 0), - (10, RW.Write, RWTableTag.Stack, 1, 1023, RLC(calldatasize, randomness, N_BYTES_U64), 0, 0), + (9, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallDataLength, 0, calldatasize, 0, 0, 0), + (10, RW.Write, RWTableTag.Stack, 1, 1023, 0, RLC(calldatasize, randomness, N_BYTES_U64), 0, 0, 0), ] ), ) diff --git a/tests/evm/test_caller.py b/tests/evm/test_caller.py index c2c802e8c..b04988eac 100644 --- a/tests/evm/test_caller.py +++ b/tests/evm/test_caller.py @@ -37,7 +37,7 @@ def test_caller(caller: U160): rw_table=set( [ (9, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.CallerAddress, 0, caller, 0, 0, 0), - (10, RW.Write, RWTableTag.Stack, 1, 1023, 0, RLC(caller, randomness, N_BYTES_ACCOUNT_ADDRESS), 0, 0, 0), + (10, RW.Write, RWTableTag.Stack, 1, 1023, 0, RLC(caller, randomness, N_BYTES_ACCOUNT_ADDRESS), 0, 0, 0), ] ), ) diff --git a/tests/evm/test_callvalue.py b/tests/evm/test_callvalue.py index 5e4b619bc..48cf38ba1 100644 --- a/tests/evm/test_callvalue.py +++ b/tests/evm/test_callvalue.py @@ -38,8 +38,8 @@ def test_callvalue(callvalue: U256): bytecode_table=set(bytecode.table_assignments(randomness)), rw_table=set( [ - (9, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.Value, callvalue_rlc, 0, 0), - (10, RW.Write, RWTableTag.Stack, 1, 1023, callvalue_rlc, 0, 0), + (9, RW.Read, RWTableTag.CallContext, 1, CallContextFieldTag.Value, 0, callvalue_rlc, 0, 0, 0), + (10, RW.Write, RWTableTag.Stack, 1, 1023, 0, callvalue_rlc, 0, 0, 0), ] ), ) diff --git a/tests/evm/test_slt_sgt.py b/tests/evm/test_slt_sgt.py index 7d26ccb5c..f0fcb015d 100644 --- a/tests/evm/test_slt_sgt.py +++ b/tests/evm/test_slt_sgt.py @@ -201,9 +201,9 @@ def test_slt_sgt(opcode: Opcode, a: int, b: int, res: int): bytecode_table=set(bytecode.table_assignments(randomness)), rw_table=set( [ - (9, RW.Read, RWTableTag.Stack, 1, 1022, a, 0, 0), - (10, RW.Read, RWTableTag.Stack, 1, 1023, b, 0, 0), - (11, RW.Write, RWTableTag.Stack, 1, 1023, res, 0, 0), + (9, RW.Read, RWTableTag.Stack, 1, 1022, 0, a, 0, 0, 0), + (10, RW.Read, RWTableTag.Stack, 1, 1023, 0, b, 0, 0, 0), + (11, RW.Write, RWTableTag.Stack, 1, 1023, 0, res, 0, 0, 0), ] ), )