diff --git a/converted-ethereum-tests.txt b/converted-ethereum-tests.txt index 8d1cc2907ca..9da29b98290 100644 --- a/converted-ethereum-tests.txt +++ b/converted-ethereum-tests.txt @@ -1,3 +1,7 @@ +([#1236](https://github.com/ethereum/execution-spec-tests/pull/1236)) +GeneralStateTests/VMTests/vmTests/calldataload.json +GeneralStateTests/VMTests/vmTests/calldatasize.json + ([#1056](https://github.com/ethereum/execution-spec-tests/pull/1056)) GeneralStateTests/VMTests/vmTests/calldatacopy.json diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6635f5c8b71..373f53e5d5c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -68,6 +68,7 @@ consume cache --help - ✨ Add EIP-7702 incorrect-rlp-encoding tests ([#1347](https://github.com/ethereum/execution-spec-tests/pull/1347)). - ✨ Add EIP-2935 tests for all call opcodes ([#1379](https://github.com/ethereum/execution-spec-tests/pull/1379)). - ✨ Add more tests for EIP-7702: max-fee-per-gas verification, delegation-designation as initcode tests ([#1372](https://github.com/ethereum/execution-spec-tests/pull/1372)). +- ✨ Port [calldataload](https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml) and [calldatasize](https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml) tests ([#1236](https://github.com/ethereum/execution-spec-tests/pull/1236)). ## [v4.1.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v4.1.0) - 2025-03-11 diff --git a/tests/frontier/opcodes/test_calldataload.py b/tests/frontier/opcodes/test_calldataload.py new file mode 100644 index 00000000000..495bb372176 --- /dev/null +++ b/tests/frontier/opcodes/test_calldataload.py @@ -0,0 +1,92 @@ +"""test `CALLDATALOAD` opcode.""" + +import pytest + +from ethereum_test_forks import Byzantium, Fork +from ethereum_test_tools import Account, Alloc, StateTestFiller, Transaction +from ethereum_test_tools import Macros as Om +from ethereum_test_tools.vm.opcode import Opcodes as Op + + +@pytest.mark.parametrize( + "calldata,calldata_offset,expected_storage", + [ + ( + b"\x25\x60", + 0x0, + 0x2560000000000000000000000000000000000000000000000000000000000000, + ), + ( + b"\xff" * 32 + b"\x23", + 0x1, + 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF23, + ), + ( + bytes.fromhex("123456789ABCDEF00000000000000000000000000000000000000000000000000024"), + 0x5, + 0xBCDEF00000000000000000000000000000000000000000000000000024000000, + ), + ], + ids=[ + "two_bytes", + "word_n_byte", + "34_bytes", + ], +) +def test_calldataload( + state_test: StateTestFiller, + calldata: bytes, + calldata_offset: int, + fork: Fork, + pre: Alloc, + expected_storage: Account, +): + """ + Test `CALLDATALOAD` opcode. + + Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml + """ + address_a = pre.deploy_contract( + (Op.PUSH1[calldata_offset] + Op.CALLDATALOAD + Op.PUSH1[0x0] + Op.SSTORE + Op.STOP), + ) + + address_b = pre.deploy_contract( + Om.MSTORE(calldata, 0x0) + + Op.CALL( + gas=Op.SUB(Op.GAS(), 0x100), + address=address_a, + value=0x0, + args_offset=0x0, + args_size=len(calldata), + ret_offset=0x0, + ret_size=0x0, + ) + ) + + to = pre.deploy_contract( + code=( + Op.ADD(0x1000, Op.CALLDATALOAD(offset=0x4)) + + Op.CALL( + gas=Op.SUB(Op.GAS(), 0x100), + address=address_b, + value=0x0, + args_offset=0x0, + args_size=0x0, + ret_offset=0x0, + ret_size=0x0, + ) + + Op.STOP + ), + ) + + tx = Transaction( + data=calldata, + gas_limit=100_000, + protected=fork >= Byzantium, + sender=pre.fund_eoa(), + to=to, + ) + post = { + address_a: Account(storage={0x00: expected_storage}), + } + state_test(pre=pre, post=post, tx=tx) diff --git a/tests/frontier/opcodes/test_calldatasize.py b/tests/frontier/opcodes/test_calldatasize.py new file mode 100644 index 00000000000..b0616c4b120 --- /dev/null +++ b/tests/frontier/opcodes/test_calldatasize.py @@ -0,0 +1,50 @@ +"""test `CALLDATASIZE` opcode.""" + +import pytest + +from ethereum_test_forks import Byzantium, Fork +from ethereum_test_tools import Account, Alloc, StateTestFiller, Transaction +from ethereum_test_tools import Macros as Om +from ethereum_test_tools.vm.opcode import Opcodes as Op + + +@pytest.mark.parametrize( + "args_size", + [0, 2, 16, 33, 257], +) +def test_calldataload( + state_test: StateTestFiller, + fork: Fork, + args_size: int, + pre: Alloc, +): + """ + Test `CALLDATASIZE` opcode. + + Based on https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml + """ + address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE)) + + to = pre.deploy_contract( + code=( + Om.MSTORE(b"\x01" * args_size, 0x0) + + Op.CALL( + gas=Op.SUB(Op.GAS(), 0x100), + address=address, + value=0x0, + args_offset=0x0, + args_size=args_size, + ret_offset=0x0, + ret_size=0x0, + ) + ) + ) + + tx = Transaction( + gas_limit=100_000, + protected=fork >= Byzantium, + sender=pre.fund_eoa(), + to=to, + ) + post = {address: Account(storage={0x00: args_size})} + state_test(pre=pre, post=post, tx=tx) diff --git a/tests/homestead/coverage/test_coverage.py b/tests/homestead/coverage/test_coverage.py index 608cd1284dc..b7240c38a31 100644 --- a/tests/homestead/coverage/test_coverage.py +++ b/tests/homestead/coverage/test_coverage.py @@ -41,6 +41,9 @@ def test_coverage( + Op.PUSH2(0x0102) + Op.PUSH3(0x010203) + Op.PUSH4(0x01020304) + + Op.PUSH32(0x0101010101010101010101010101010101010101010101010101010101010101) + + Op.MSTORE8(0x00, 0x01) + + Op.ADD(0x02, 0x03) + Op.POP(0x01) # lllc tests insert codecopy when using lll(seq()) + Op.CODECOPY(0, 16, 4),