Skip to content

Commit

Permalink
Merge pull request #1109 from shemnon/eof/create-data-overwrite
Browse files Browse the repository at this point in the history
feat(tests): EOF - EIP-7620: verify RETURNCONTRACT does not overwrite containing contract
  • Loading branch information
shemnon authored Jan 28, 2025
2 parents b16de8d + f18e9bd commit 8288c0b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/osaka/eip7692_eof_v1/eip7620_eof_create/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
slot_max_depth = next(_slot)
slot_call_or_create = next(_slot)
slot_counter = next(_slot)
slot_data_load = next(_slot)

slot_last_slot = next(_slot)

value_code_worked = 0x2015
value_canary_should_not_change = 0x2019
value_canary_to_be_overwritten = 0x2009
value_long_value = b"abcdefghijklmnopqrstuvwxyz123456"

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

Expand Down
51 changes: 50 additions & 1 deletion tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
slot_calldata,
slot_code_worked,
slot_create_address,
slot_data_load,
slot_last_slot,
slot_returndata_size,
smallest_initcode_subcontainer,
smallest_runtime_subcontainer,
value_canary_to_be_overwritten,
value_code_worked,
value_long_value,
)
from .spec import EOFCREATE_FAILURE

Expand All @@ -54,7 +56,6 @@ def test_simple_eofcreate(
),
Section.Container(container=smallest_initcode_subcontainer),
],
data=b"abcdef",
),
storage={0: 0xB17D}, # a canary to be overwritten
)
Expand All @@ -76,6 +77,54 @@ def test_simple_eofcreate(
state_test(env=env, pre=pre, post=post, tx=tx)


def test_eofcreate_then_dataload(
state_test: StateTestFiller,
pre: Alloc,
):
"""Verifies that a contract returned with auxdata does not overwrite the parent data."""
env = Environment()
sender = pre.fund_eoa()
small_auxdata_container = Container(
sections=[
Section.Code(code=Op.RETURNCONTRACT[0](0, 32)),
Section.Container(container=smallest_runtime_subcontainer),
],
)
contract_address = pre.deploy_contract(
code=Container(
sections=[
Section.Code(
code=Op.SSTORE(0, Op.EOFCREATE[0](0, 0, 0, 0))
+ Op.SSTORE(slot_data_load, Op.DATALOAD(0))
+ Op.STOP,
),
Section.Container(
container=small_auxdata_container,
),
Section.Data(data=value_long_value),
],
),
storage={slot_data_load: value_canary_to_be_overwritten},
)

post = {
contract_address: Account(
storage={
0: compute_eofcreate_address(contract_address, 0, small_auxdata_container),
slot_data_load: value_long_value,
}
)
}
tx = Transaction(
to=contract_address,
gas_limit=10_000_000,
gas_price=10,
protected=False,
sender=sender,
)
state_test(env=env, pre=pre, post=post, tx=tx)


def test_eofcreate_then_call(
state_test: StateTestFiller,
pre: Alloc,
Expand Down

0 comments on commit 8288c0b

Please sign in to comment.