Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): EOF - EIP-7620: verify RETURNCONTRACT does not overwrite containing contract #1109

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading