Skip to content

Commit dee6fa8

Browse files
authored
Merge pull request ethereum#1109 from shemnon/eof/create-data-overwrite
feat(tests): EOF - EIP-7620: verify RETURNCONTRACT does not overwrite containing contract
2 parents e0bd914 + 81cf548 commit dee6fa8

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

osaka/eip7692_eof_v1/eip7620_eof_create/helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
slot_max_depth = next(_slot)
1919
slot_call_or_create = next(_slot)
2020
slot_counter = next(_slot)
21+
slot_data_load = next(_slot)
2122

2223
slot_last_slot = next(_slot)
2324

2425
value_code_worked = 0x2015
2526
value_canary_should_not_change = 0x2019
2627
value_canary_to_be_overwritten = 0x2009
28+
value_long_value = b"abcdefghijklmnopqrstuvwxyz123456"
2729

2830
smallest_runtime_subcontainer = Container.Code(code=Op.STOP, name="Runtime Subcontainer")
2931

osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
slot_calldata,
2525
slot_code_worked,
2626
slot_create_address,
27+
slot_data_load,
2728
slot_last_slot,
2829
slot_returndata_size,
2930
smallest_initcode_subcontainer,
3031
smallest_runtime_subcontainer,
3132
value_canary_to_be_overwritten,
3233
value_code_worked,
34+
value_long_value,
3335
)
3436
from .spec import EOFCREATE_FAILURE
3537

@@ -54,7 +56,6 @@ def test_simple_eofcreate(
5456
),
5557
Section.Container(container=smallest_initcode_subcontainer),
5658
],
57-
data=b"abcdef",
5859
),
5960
storage={0: 0xB17D}, # a canary to be overwritten
6061
)
@@ -76,6 +77,54 @@ def test_simple_eofcreate(
7677
state_test(env=env, pre=pre, post=post, tx=tx)
7778

7879

80+
def test_eofcreate_then_dataload(
81+
state_test: StateTestFiller,
82+
pre: Alloc,
83+
):
84+
"""Verifies that a contract returned with auxdata does not overwrite the parent data."""
85+
env = Environment()
86+
sender = pre.fund_eoa()
87+
small_auxdata_container = Container(
88+
sections=[
89+
Section.Code(code=Op.RETURNCONTRACT[0](0, 32)),
90+
Section.Container(container=smallest_runtime_subcontainer),
91+
],
92+
)
93+
contract_address = pre.deploy_contract(
94+
code=Container(
95+
sections=[
96+
Section.Code(
97+
code=Op.SSTORE(0, Op.EOFCREATE[0](0, 0, 0, 0))
98+
+ Op.SSTORE(slot_data_load, Op.DATALOAD(0))
99+
+ Op.STOP,
100+
),
101+
Section.Container(
102+
container=small_auxdata_container,
103+
),
104+
Section.Data(data=value_long_value),
105+
],
106+
),
107+
storage={slot_data_load: value_canary_to_be_overwritten},
108+
)
109+
110+
post = {
111+
contract_address: Account(
112+
storage={
113+
0: compute_eofcreate_address(contract_address, 0, small_auxdata_container),
114+
slot_data_load: value_long_value,
115+
}
116+
)
117+
}
118+
tx = Transaction(
119+
to=contract_address,
120+
gas_limit=10_000_000,
121+
gas_price=10,
122+
protected=False,
123+
sender=sender,
124+
)
125+
state_test(env=env, pre=pre, post=post, tx=tx)
126+
127+
79128
def test_eofcreate_then_call(
80129
state_test: StateTestFiller,
81130
pre: Alloc,

0 commit comments

Comments
 (0)