From 1199abe56be2d44cc73a8910ab34d22dbc1a8d81 Mon Sep 17 00:00:00 2001 From: pdobacz <5735525+pdobacz@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:52:01 +0200 Subject: [PATCH] new(tests): EIP-5656/7692 - EOFize remainder of MCOPY tests --- tests/cancun/eip5656_mcopy/test_mcopy.py | 2 + .../eip5656_mcopy/test_mcopy_contexts.py | 44 +++++++------------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/tests/cancun/eip5656_mcopy/test_mcopy.py b/tests/cancun/eip5656_mcopy/test_mcopy.py index 53aaada64b..1e8ca50c19 100644 --- a/tests/cancun/eip5656_mcopy/test_mcopy.py +++ b/tests/cancun/eip5656_mcopy/test_mcopy.py @@ -175,6 +175,7 @@ def post(code_address: Address, code_storage: Storage) -> Mapping: # noqa: D103 "out_of_bounds_memory_extension", ], ) +@pytest.mark.with_all_evm_code_types @pytest.mark.valid_from("Cancun") def test_valid_mcopy_operations( state_test: StateTestFiller, @@ -202,6 +203,7 @@ def test_valid_mcopy_operations( @pytest.mark.parametrize("src", [0x00, 0x20]) @pytest.mark.parametrize("length", [0x00, 0x01]) @pytest.mark.parametrize("initial_memory", [bytes()], ids=["empty_memory"]) +@pytest.mark.with_all_evm_code_types @pytest.mark.valid_from("Cancun") def test_mcopy_on_empty_memory( state_test: StateTestFiller, diff --git a/tests/cancun/eip5656_mcopy/test_mcopy_contexts.py b/tests/cancun/eip5656_mcopy/test_mcopy_contexts.py index 26e0bf156a..47266f7348 100644 --- a/tests/cancun/eip5656_mcopy/test_mcopy_contexts.py +++ b/tests/cancun/eip5656_mcopy/test_mcopy_contexts.py @@ -26,7 +26,7 @@ def initial_memory_length() -> int: # noqa: D103 @pytest.fixture def callee_bytecode( initial_memory_length: int, - opcode: Op, + call_opcode: Op, ) -> Bytecode: """ Callee simply performs mcopy operations that should not have any effect on the @@ -44,7 +44,7 @@ def callee_bytecode( bytecode += Op.MCOPY(0x00, initial_memory_length * 2, 1) bytecode += Op.MCOPY(initial_memory_length * 2, 0x00, 1) - if opcode != Op.STATICCALL: + if call_opcode != Op.STATICCALL and call_opcode != Op.EXTSTATICCALL: # Simple sstore to make sure we actually ran the code bytecode += Op.SSTORE(200_000, 1) @@ -58,7 +58,7 @@ def callee_bytecode( def initial_memory( callee_bytecode: Bytecode, initial_memory_length: int, - opcode: Op, + call_opcode: Op, ) -> bytes: """ Initial memory for the test. @@ -67,7 +67,7 @@ def initial_memory( ret = bytes(list(islice(cycle(range(0x01, 0x100)), initial_memory_length))) - if opcode in [Op.CREATE, Op.CREATE2]: + if call_opcode in [Op.CREATE, Op.CREATE2]: # We also need to put the callee_bytecode as initcode in memory for create operations ret = bytes(callee_bytecode) + ret[len(callee_bytecode) :] @@ -85,7 +85,7 @@ def caller_bytecode( initial_memory: bytes, callee_address: Address, callee_bytecode: Bytecode, - opcode: Op, + call_opcode: Op, caller_storage: Storage, ) -> Bytecode: """ @@ -99,10 +99,10 @@ def caller_bytecode( bytecode += Op.MSTORE(i, Op.PUSH32(initial_memory[i : i + 0x20])) # Perform the call to the contract that is going to perform mcopy - if opcode in [Op.CALL, Op.CALLCODE, Op.DELEGATECALL, Op.STATICCALL]: - bytecode += opcode(address=callee_address) - elif opcode in [Op.CREATE, Op.CREATE2]: - bytecode += opcode(size=len(callee_bytecode)) + if call_opcode in [Op.CREATE, Op.CREATE2]: + bytecode += call_opcode(size=len(callee_bytecode)) + else: + bytecode += call_opcode(address=callee_address) # First save msize bytecode += Op.SSTORE(100_000, Op.MSIZE()) @@ -141,12 +141,12 @@ def post( # noqa: D103 caller_address: Address, caller_storage: Storage, callee_address: Address, - opcode: Op, + call_opcode: Op, ) -> Mapping: callee_storage: Storage.StorageDictType = {} - if opcode in [Op.DELEGATECALL, Op.CALLCODE]: + if call_opcode in [Op.DELEGATECALL, Op.CALLCODE, Op.EXTDELEGATECALL]: caller_storage[200_000] = 1 - elif opcode in [Op.CALL]: + elif call_opcode in [Op.CALL, Op.EXTCALL]: callee_storage[200_000] = 1 return { caller_address: Account(storage=caller_storage), @@ -154,15 +154,7 @@ def post( # noqa: D103 } -@pytest.mark.parametrize( - "opcode", - [ - Op.CALL, - Op.DELEGATECALL, - Op.STATICCALL, - Op.CALLCODE, - ], -) +@pytest.mark.with_all_call_opcodes @pytest.mark.valid_from("Cancun") def test_no_memory_corruption_on_upper_call_stack_levels( state_test: StateTestFiller, @@ -172,13 +164,7 @@ def test_no_memory_corruption_on_upper_call_stack_levels( ): """ Perform a subcall with any of the following opcodes, which uses MCOPY during its execution, - and verify that the caller's memory is unaffected: - - `CALL` - - `CALLCODE` - - `DELEGATECALL` - - `STATICCALL` - - TODO: [EOF] Add EOF EXT*CALL opcodes + and verify that the caller's memory is unaffected """ state_test( env=Environment(), @@ -189,7 +175,7 @@ def test_no_memory_corruption_on_upper_call_stack_levels( @pytest.mark.parametrize( - "opcode", + "call_opcode", [ Op.CREATE, Op.CREATE2,