Skip to content

Commit 96c2be9

Browse files
committed
convert calldatacopy from yml
1 parent edbace1 commit 96c2be9

File tree

4 files changed

+186
-3
lines changed

4 files changed

+186
-3
lines changed

converted-ethereum-tests.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
([#1056](https://github.com/ethereum/execution-spec-tests/pull/1056))
2+
GeneralStateTests/VMTests/vmTests/calldatacopy.json
3+
14
([#748](https://github.com/ethereum/execution-spec-tests/pull/748))
25
GeneralStateTests/stBadOpcode/badOpcodes.json
36
GeneralStateTests/stBugs/evmBytecode.json

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2525
- 🔀 Update EIP-7002 according to [spec updates](https://github.com/ethereum/EIPs/pull/9119) ([#1024](https://github.com/ethereum/execution-spec-tests/pull/1024)).
2626
- 🔀 Update EIP-2935 according to [spec updates](https://github.com/ethereum/EIPs/pull/9144) ([#1046](https://github.com/ethereum/execution-spec-tests/pull/1046))
2727
-[EIP-7691](https://eips.ethereum.org/EIPS/eip-7691) Blob throughput increase tests by parametrization of existing EIP-4844 tests ([#1023](https://github.com/ethereum/execution-spec-tests/pull/1023))
28+
- ✨ Port [calldatacopy test](https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml) ([#1056](https://github.com/ethereum/execution-spec-tests/pull/1056)).
2829

2930
### 🛠️ Framework
3031

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ dependencies = [
4444
"pyyaml>=6.0.2,<7",
4545
"types-pyyaml>=6.0.12.20240917,<7",
4646
"pytest-json-report>=1.5.0,<2",
47-
# TODO: bump questionary to a newer release, when it becomes available.
47+
# TODO: bump questionary to a newer release, when it becomes available.
4848
# The current release questionary 2.0.1 requires `prompt_toolkit = ">=2.0,<=3.0.36"`.
4949
# This conflicts with ipython; while not an EEST dependency, ipython a very useful tool:
5050
# https://ethereum.github.io/execution-spec-tests/main/dev/interactive_usage/
5151
"questionary @ git+https://github.com/tmbo/questionary@ff22aeae1cd9c1c734f14329934e349bec7873bc",
52-
"prompt_toolkit>=3.0.48,<4", # ensure we have a new enough version for ipython
52+
"prompt_toolkit>=3.0.48,<4", # ensure we have a new enough version for ipython
5353
]
5454

5555
[project.urls]
@@ -119,4 +119,4 @@ ignore = ["D205", "D203", "D212", "D415", "C901"]
119119

120120
[tool.mypy]
121121
mypy_path = ["src", "$MYPY_CONFIG_FILE_DIR/stubs"]
122-
plugins = ["pydantic.mypy"]
122+
plugins = ["pydantic.mypy"]
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
"""test `CALLDATACOPY` opcode."""
2+
3+
from re import M
4+
5+
import pytest
6+
7+
from ethereum_test_forks import Fork
8+
from ethereum_test_forks.forks.forks import Byzantium
9+
from ethereum_test_tools import Account, Alloc, Bytecode, StateTestFiller, Transaction
10+
from ethereum_test_tools.vm.opcode import Opcodes as Op
11+
12+
13+
# @pytest.mark.valid_from("Byzantium")
14+
@pytest.mark.parametrize(
15+
"code,tx_data,code_address_storage,to_address_storage",
16+
[
17+
(
18+
(
19+
Op.CALLDATACOPY(dest_offset=0, offset=1, size=2)
20+
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
21+
+ Op.RETURN(offset=0, size=Op.MSIZE)
22+
),
23+
b"\x00",
24+
Account(
25+
storage={0x00: 0x3456000000000000000000000000000000000000000000000000000000000000}
26+
),
27+
Account(
28+
storage={0x00: 0x3456000000000000000000000000000000000000000000000000000000000000}
29+
),
30+
),
31+
(
32+
(
33+
Op.CALLDATACOPY(dest_offset=0, offset=1, size=1)
34+
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
35+
+ Op.RETURN(offset=0, size=Op.MSIZE)
36+
),
37+
b"\x01",
38+
Account(
39+
storage={0x00: 0x3400000000000000000000000000000000000000000000000000000000000000},
40+
),
41+
Account(
42+
storage={0x00: 0x3400000000000000000000000000000000000000000000000000000000000000},
43+
),
44+
),
45+
(
46+
(
47+
Op.CALLDATACOPY(dest_offset=0, offset=1, size=0)
48+
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
49+
+ Op.RETURN(offset=0, size=Op.MSIZE)
50+
),
51+
b"\x02",
52+
Account(
53+
storage={0x00: 0x00},
54+
),
55+
Account(
56+
storage={0x00: 0x00},
57+
),
58+
),
59+
(
60+
(
61+
Op.CALLDATACOPY(dest_offset=0, offset=0, size=0)
62+
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
63+
+ Op.RETURN(offset=0, size=Op.MSIZE)
64+
),
65+
b"\x03",
66+
Account(
67+
storage={0x00: 0x00},
68+
),
69+
Account(
70+
storage={0x00: 0x00},
71+
),
72+
),
73+
(
74+
(
75+
Op.CALLDATACOPY(
76+
dest_offset=0,
77+
offset=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA,
78+
size=0xFF,
79+
)
80+
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
81+
+ Op.RETURN(offset=0, size=Op.MSIZE)
82+
),
83+
b"\x04",
84+
Account(storage={0x00: 0x00}),
85+
Account(storage={0x00: 0x00}),
86+
),
87+
(
88+
(
89+
Op.CALLDATACOPY(
90+
dest_offset=0,
91+
offset=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA,
92+
size=0x9,
93+
)
94+
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0))
95+
+ Op.RETURN(offset=0, size=Op.MSIZE)
96+
),
97+
b"\x05",
98+
Account(storage={0x00: 0x00}),
99+
Account(storage={0x00: 0x00}),
100+
),
101+
(
102+
(Op.SSTORE(key=0x1, value=0x1) + Op.PUSH1[0x1] + Op.PUSH1[0x2] + Op.CALLDATACOPY),
103+
b"\x10",
104+
Account(storage={0x01: 0x00}),
105+
None,
106+
),
107+
(
108+
(
109+
Op.JUMP(pc=0x5)
110+
+ Op.JUMPDEST
111+
+ Op.STOP
112+
+ Op.JUMPDEST
113+
+ Op.MSTORE8(offset=0x1F, value=0x42)
114+
+ Op.CALLDATACOPY(dest_offset=0x1F, offset=0x0, size=0x103)
115+
+ Op.MLOAD(offset=0x0)
116+
+ Op.DUP1
117+
+ Op.PUSH1[0x60]
118+
+ Op.JUMPI(pc=0x3, condition=Op.EQ)
119+
+ Op.SSTORE(key=0xFF, value=0xBADC0FFEE)
120+
),
121+
b"\x11",
122+
Account(storage={0xFF: 0xBADC0FFEE}),
123+
None,
124+
),
125+
],
126+
ids=[
127+
"cdc 0 1 2",
128+
"cdc 0 1 1",
129+
"cdc 0 1 0",
130+
"cdc 0 0 0",
131+
"cdc 0 neg6 ff",
132+
"cdc 0 neg6 9",
133+
"underflow",
134+
"sec",
135+
],
136+
)
137+
def test_calldatacopy(
138+
state_test: StateTestFiller,
139+
code: Bytecode,
140+
fork: Fork,
141+
tx_data: bytes,
142+
pre: Alloc,
143+
code_address_storage: Account,
144+
to_address_storage: Account | None,
145+
):
146+
"""
147+
Test `CALLDATACOPY` opcode.
148+
149+
Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.ym
150+
"""
151+
code_address = pre.deploy_contract(code)
152+
to = pre.deploy_contract(
153+
code=(
154+
Op.MSTORE(offset=0x0, value=0x1234567890ABCDEF01234567890ABCDEF0)
155+
+ Op.CALL(
156+
0xFFFFFF, Op.ADD(0x1000, Op.CALLDATALOAD(offset=0x4)), 0x0, 0xF, 0x10, 0x20, 0x40
157+
)
158+
+ Op.POP
159+
+ Op.SSTORE(key=0x0, value=Op.MLOAD(offset=0x20))
160+
+ Op.SSTORE(key=0x1, value=Op.MLOAD(offset=0x40))
161+
+ Op.STOP
162+
),
163+
nonce=0,
164+
)
165+
166+
tx = Transaction(
167+
data=tx_data,
168+
gas_limit=0x100_000,
169+
gas_price=0x0A,
170+
protected=fork >= Byzantium,
171+
sender=pre.fund_eoa(),
172+
to=to,
173+
value=0x01,
174+
)
175+
if to_address_storage:
176+
post = {code_address: code_address_storage, to: to_address_storage}
177+
else:
178+
post = {code_address: code_address_storage}
179+
state_test(pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)