Skip to content

Commit 1c9444a

Browse files
committed
convert calldataload and calldatasize tests
1 parent 92511c7 commit 1c9444a

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
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
@@ -67,6 +67,7 @@ consume cache --help
6767
- ✨ Add additional test coverage for EIP-152 Blake2 precompiles ([#1244](https://github.com/ethereum/execution-spec-tests/pull/1244)). Refactor to add variables for spec constants and common fixture code. ([#1395](https://github.com/ethereum/execution-spec-tests/pull/1395)).
6868
- ✨ Add EIP-7702 incorrect-rlp-encoding tests ([#1347](https://github.com/ethereum/execution-spec-tests/pull/1347)).
6969
- ✨ Add EIP-2935 tests for all call opcodes ([#1379](https://github.com/ethereum/execution-spec-tests/pull/1379)).
70+
- ✨ 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)).
7071

7172
## [v4.1.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v4.1.0) - 2025-03-11
7273

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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, Bytecode, StateTestFiller, Transaction
7+
from ethereum_test_tools.vm.opcode import Opcodes as Op
8+
9+
10+
@pytest.mark.parametrize(
11+
"mstore,args_size,code_for_address_a,tx_data,address_a_storage",
12+
[
13+
(
14+
(Op.MSTORE8(offset=0x0, value=0x25) + Op.MSTORE8(offset=0x1, value=0x60)),
15+
0x2,
16+
(Op.PUSH1[0x0] + Op.CALLDATALOAD + Op.PUSH1[0x0] + Op.SSTORE),
17+
b"\x00",
18+
Account(
19+
storage={0x00: 0x2560000000000000000000000000000000000000000000000000000000000000}
20+
),
21+
),
22+
(
23+
(
24+
Op.MSTORE(
25+
offset=0x0,
26+
value=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
27+
)
28+
+ Op.MSTORE8(offset=0x20, value=0x23)
29+
),
30+
0x21,
31+
(Op.PUSH1[0x1] + Op.CALLDATALOAD + Op.PUSH1[0x0] + Op.SSTORE + Op.STOP),
32+
b"\x01",
33+
Account(
34+
storage={0x00: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF23}
35+
),
36+
),
37+
(
38+
(
39+
Op.MSTORE(
40+
offset=0x0,
41+
value=0x123456789ABCDEF0000000000000000000000000000000000000000000000000,
42+
)
43+
+ Op.MSTORE8(offset=0x20, value=0x0)
44+
+ Op.MSTORE8(offset=0x21, value=0x24)
45+
),
46+
0x22,
47+
(Op.PUSH1[0x5] + Op.CALLDATALOAD + Op.PUSH1[0x0] + Op.SSTORE + Op.STOP),
48+
b"\x02",
49+
Account(
50+
storage={0x00: 0xBCDEF00000000000000000000000000000000000000000000000000024000000}
51+
),
52+
),
53+
],
54+
ids=[
55+
"two_bytes",
56+
"word_n_byte",
57+
"34_bytes",
58+
],
59+
)
60+
def test_calldataload(
61+
state_test: StateTestFiller,
62+
mstore: Bytecode,
63+
args_size: int,
64+
code_for_address_a: Bytecode,
65+
fork: Fork,
66+
tx_data: bytes,
67+
pre: Alloc,
68+
address_a_storage: Account,
69+
):
70+
"""
71+
Test `CALLDATALOAD` opcode.
72+
73+
Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml
74+
"""
75+
address_a = pre.deploy_contract(code_for_address_a)
76+
77+
address_b = pre.deploy_contract(
78+
mstore
79+
+ Op.CALL(
80+
gas=Op.SUB(Op.GAS(), 0x100),
81+
address=address_a,
82+
value=0x0,
83+
args_offset=0x0,
84+
args_size=args_size,
85+
ret_offset=0x0,
86+
ret_size=0x0,
87+
)
88+
)
89+
90+
to = pre.deploy_contract(
91+
code=(
92+
Op.ADD(0x1000, Op.CALLDATALOAD(offset=0x4))
93+
+ Op.CALL(
94+
gas=Op.SUB(Op.GAS(), 0x100),
95+
address=address_b,
96+
value=0x0,
97+
args_offset=0x0,
98+
args_size=0x0,
99+
ret_offset=0x0,
100+
ret_size=0x0,
101+
)
102+
+ Op.STOP
103+
),
104+
)
105+
106+
tx = Transaction(
107+
data=tx_data,
108+
gas_limit=100_000,
109+
gas_price=0x0A,
110+
protected=fork >= Byzantium,
111+
sender=pre.fund_eoa(),
112+
to=to,
113+
value=0x01,
114+
)
115+
post = {address_a: address_a_storage}
116+
state_test(pre=pre, post=post, tx=tx)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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.vm.opcode import Opcodes as Op
8+
9+
10+
@pytest.mark.parametrize(
11+
"args_size,sha3_len,storage",
12+
[
13+
("0002", "01", Account(storage={0x00: 0x02})),
14+
("0011", "01", Account(storage={0x00: 0x11})),
15+
("0021", "01", Account(storage={0x00: 0x21})),
16+
("0031", "01", Account(storage={0x00: 0x31})),
17+
("0101", "01", Account(storage={0x00: 0x101})),
18+
("0002", "02", Account(storage={0x00: 0x02})),
19+
("0011", "02", Account(storage={0x00: 0x11})),
20+
("0021", "02", Account(storage={0x00: 0x21})),
21+
("0031", "02", Account(storage={0x00: 0x31})),
22+
("0101", "02", Account(storage={0x00: 0x101})),
23+
("0002", "03", Account(storage={0x00: 0x02})),
24+
("0011", "03", Account(storage={0x00: 0x11})),
25+
("0021", "03", Account(storage={0x00: 0x21})),
26+
("0031", "03", Account(storage={0x00: 0x31})),
27+
("0101", "03", Account(storage={0x00: 0x101})),
28+
("0002", "04", Account(storage={0x00: 0x02})),
29+
("0011", "04", Account(storage={0x00: 0x11})),
30+
("0021", "04", Account(storage={0x00: 0x21})),
31+
("0031", "04", Account(storage={0x00: 0x31})),
32+
("0101", "04", Account(storage={0x00: 0x101})),
33+
],
34+
ids=[
35+
"data1_2",
36+
"data1_11",
37+
"data1_21",
38+
"data1_31",
39+
"data1_101",
40+
"data2_2",
41+
"data2_11",
42+
"data2_21",
43+
"data2_31",
44+
"data2_101",
45+
"data3_2",
46+
"data3_11",
47+
"data3_21",
48+
"data3_31",
49+
"data3_101",
50+
"data4_2",
51+
"data4_11",
52+
"data4_21",
53+
"data4_31",
54+
"data4_101",
55+
],
56+
)
57+
def test_calldataload(
58+
state_test: StateTestFiller,
59+
fork: Fork,
60+
args_size: str,
61+
sha3_len: str,
62+
pre: Alloc,
63+
storage: Account,
64+
):
65+
"""
66+
Test `CALLDATASIZE` opcode.
67+
68+
Based on https://github.com/ethereum/tests/blob/81862e4848585a438d64f911a19b3825f0f4cd95/src/GeneralStateTestsFiller/VMTests/vmTests/calldatasizeFiller.yml
69+
"""
70+
address = pre.deploy_contract(Op.SSTORE(key=0x0, value=Op.CALLDATASIZE))
71+
72+
to = pre.deploy_contract(
73+
code=(
74+
Op.MSTORE(offset=0x0, value=Op.SHA3(offset=0x0, size=Op.CALLDATALOAD(offset=0x24)))
75+
+ Op.CALL(
76+
gas=Op.SUB(Op.GAS(), 0x100),
77+
address=address,
78+
value=0x0,
79+
args_offset=0x0,
80+
args_size=Op.CALLDATALOAD(offset=0x4),
81+
ret_offset=0x0,
82+
ret_size=0x0,
83+
)
84+
)
85+
)
86+
tx_data = bytes.fromhex("1a8451e6" + "00" * 30 + args_size + "00" * 31 + sha3_len)
87+
88+
tx = Transaction(
89+
data=tx_data,
90+
gas_limit=100_000,
91+
gas_price=0x0A,
92+
protected=fork >= Byzantium,
93+
sender=pre.fund_eoa(),
94+
to=to,
95+
value=0x01,
96+
)
97+
post = {address: storage}
98+
state_test(pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)