Skip to content

Commit 59d79a1

Browse files
pacrobfelix314159
authored andcommitted
feat(tests): converting calldataload and calldatasize tests (ethereum#1236)
1 parent 9138e41 commit 59d79a1

File tree

7 files changed

+168
-337
lines changed

7 files changed

+168
-337
lines changed

converted-ethereum-tests.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
([#1236](https://github.com/ethereum/execution-spec-tests/pull/1236))
2+
GeneralStateTests/VMTests/vmTests/calldataload.json
3+
GeneralStateTests/VMTests/vmTests/calldatasize.json
4+
15
([#1056](https://github.com/ethereum/execution-spec-tests/pull/1056))
26
GeneralStateTests/VMTests/vmTests/calldatacopy.json
37

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2424
### 🧪 Test Cases
2525

2626
- 🔀 Automatically apply the `zkevm` marker to all tests under `./tests/zkevm/` and `./tests/prague/eip2537_bls_12_381_precompiles/` via conftest configuration ([#1534](https://github.com/ethereum/execution-spec-tests/pull/1534)).
27+
- ✨ 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)).
2728

2829
## [v4.4.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v4.4.0) - 2025-04-29
2930

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
"""test `CALLDATALOAD` opcode."""
2+
3+
import pytest
4+
5+
from ethereum_test_forks import Byzantium, Fork
6+
from ethereum_test_tools import Account, Alloc, StateTestFiller, Transaction
7+
from ethereum_test_tools import Macros as Om
8+
from ethereum_test_tools.vm.opcode import Opcodes as Op
9+
10+
11+
@pytest.mark.parametrize(
12+
"calldata,calldata_offset,expected_storage",
13+
[
14+
(
15+
b"\x25\x60",
16+
0x0,
17+
0x2560000000000000000000000000000000000000000000000000000000000000,
18+
),
19+
(
20+
b"\xff" * 32 + b"\x23",
21+
0x1,
22+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF23,
23+
),
24+
(
25+
bytes.fromhex("123456789ABCDEF00000000000000000000000000000000000000000000000000024"),
26+
0x5,
27+
0xBCDEF00000000000000000000000000000000000000000000000000024000000,
28+
),
29+
],
30+
ids=[
31+
"two_bytes",
32+
"word_n_byte",
33+
"34_bytes",
34+
],
35+
)
36+
@pytest.mark.parametrize("calldata_source", ["contract", "tx"])
37+
def test_calldataload(
38+
state_test: StateTestFiller,
39+
calldata: bytes,
40+
calldata_offset: int,
41+
fork: Fork,
42+
pre: Alloc,
43+
expected_storage: Account,
44+
calldata_source: str,
45+
):
46+
"""
47+
Test `CALLDATALOAD` opcode.
48+
49+
Tests two scenarios:
50+
- calldata_source is "contract": CALLDATALOAD reads from calldata passed by another contract
51+
- calldata_source is "tx": CALLDATALOAD reads directly from transaction calldata
52+
53+
Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml
54+
"""
55+
contract_address = pre.deploy_contract(
56+
Op.SSTORE(0, Op.CALLDATALOAD(offset=calldata_offset)) + Op.STOP,
57+
)
58+
59+
if calldata_source == "contract":
60+
to = pre.deploy_contract(
61+
Om.MSTORE(calldata, 0x0)
62+
+ Op.CALL(
63+
gas=Op.SUB(Op.GAS(), 0x100),
64+
address=contract_address,
65+
value=0x0,
66+
args_offset=0x0,
67+
args_size=len(calldata),
68+
ret_offset=0x0,
69+
ret_size=0x0,
70+
)
71+
+ Op.STOP
72+
)
73+
74+
tx = Transaction(
75+
data=calldata,
76+
gas_limit=100_000,
77+
protected=fork >= Byzantium,
78+
sender=pre.fund_eoa(),
79+
to=to,
80+
)
81+
82+
else:
83+
tx = Transaction(
84+
data=calldata,
85+
gas_limit=100_000,
86+
protected=fork >= Byzantium,
87+
sender=pre.fund_eoa(),
88+
to=contract_address,
89+
)
90+
91+
post = {contract_address: Account(storage={0x00: expected_storage})}
92+
state_test(pre=pre, post=post, tx=tx)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""test `CALLDATASIZE` opcode."""
2+
3+
import pytest
4+
5+
from ethereum_test_forks import Byzantium, Fork
6+
from ethereum_test_tools import Account, Alloc, StateTestFiller, Transaction
7+
from ethereum_test_tools import Macros as Om
8+
from ethereum_test_tools.vm.opcode import Opcodes as Op
9+
10+
11+
@pytest.mark.parametrize(
12+
"args_size",
13+
[0, 2, 16, 33, 257],
14+
)
15+
@pytest.mark.parametrize("calldata_source", ["contract", "tx"])
16+
def test_calldatasize(
17+
state_test: StateTestFiller,
18+
fork: Fork,
19+
args_size: int,
20+
pre: Alloc,
21+
calldata_source: str,
22+
):
23+
"""
24+
Test `CALLDATASIZE` opcode.
25+
26+
Tests two scenarios:
27+
- calldata_source is "contract": CALLDATASIZE reads from calldata passed by another contract
28+
- calldata_source is "tx": CALLDATASIZE reads directly from transaction calldata
29+
30+
Based on https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml
31+
"""
32+
contract_address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE))
33+
calldata = b"\x01" * args_size
34+
35+
if calldata_source == "contract":
36+
to = pre.deploy_contract(
37+
code=(
38+
Om.MSTORE(calldata, 0x0)
39+
+ Op.CALL(
40+
gas=Op.SUB(Op.GAS(), 0x100),
41+
address=contract_address,
42+
value=0x0,
43+
args_offset=0x0,
44+
args_size=args_size,
45+
ret_offset=0x0,
46+
ret_size=0x0,
47+
)
48+
)
49+
)
50+
51+
tx = Transaction(
52+
gas_limit=100_000,
53+
protected=fork >= Byzantium,
54+
sender=pre.fund_eoa(),
55+
to=to,
56+
)
57+
58+
else:
59+
tx = Transaction(
60+
data=calldata,
61+
gas_limit=100_000,
62+
protected=fork >= Byzantium,
63+
sender=pre.fund_eoa(),
64+
to=contract_address,
65+
)
66+
67+
post = {contract_address: Account(storage={0x00: args_size})}
68+
state_test(pre=pre, post=post, tx=tx)

tests/homestead/coverage/test_coverage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def test_coverage(
4141
+ Op.PUSH2(0x0102)
4242
+ Op.PUSH3(0x010203)
4343
+ Op.PUSH4(0x01020304)
44+
+ Op.PUSH32(0x0101010101010101010101010101010101010101010101010101010101010101)
45+
+ Op.MSTORE8(0x00, 0x01)
46+
+ Op.ADD(0x02, 0x03)
4447
+ Op.POP(0x01)
4548
# lllc tests insert codecopy when using lll(seq())
4649
+ Op.CODECOPY(0, 16, 4),

tests/static/state_tests/VMTests/vmTests/calldataloadFiller.yml

Lines changed: 0 additions & 166 deletions
This file was deleted.

0 commit comments

Comments
 (0)