Skip to content

Commit

Permalink
new(tests): EOF - EIP-3540 EXTCODE* mid-creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobacz committed Jun 14, 2024
1 parent 04bcb54 commit fd9255c
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_extcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
test execution semantics changes
"""
from typing import List

import pytest
from ethereum.crypto.hash import keccak256

Expand Down Expand Up @@ -77,3 +79,73 @@ def test_legacy_calls_eof_sstore(
post=post,
tx=tx,
)


smallest_runtime_subcontainer = Section.Container(
container=Container(
sections=[
Section.Code(code=Op.STOP),
],
)
)
empty_code_hash = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"


@pytest.mark.parametrize(
["opcode", "expected_result", "call_suffix", "load_code"],
[
pytest.param(Op.EXTCODESIZE, "0x00", [], b"", id="extcodesize"),
pytest.param(Op.EXTCODEHASH, empty_code_hash, [], b"", id="extcodehash"),
pytest.param(Op.EXTCODECOPY, b"", [0, 0, 32], Op.MLOAD(0), id="extcodecopy"),
],
)
def test_extcode_mid_creation(
state_test: StateTestFiller,
pre: Alloc,
opcode: Op,
expected_result: bytes,
call_suffix: List[int],
load_code: bytes,
):
"""
Verifies behavior of EXTCODE* opcodes when they target EOF contract mid-creation.
"""
env = Environment()
sender = pre.fund_eoa()
callback_address = pre.deploy_contract(
code=opcode(Op.CALLDATALOAD(0), *call_suffix) + load_code + Op.SSTORE(0, unchecked=True),
storage={0: 0xB17D}, # a canary to be overwritten
)
contract_address = pre.deploy_contract(
code=Container(
sections=[
Section.Code(
code=Op.SSTORE(0, Op.EOFCREATE[0](0, 0, 0, 0)) + Op.STOP,
max_stack_height=4,
),
Section.Container(
container=Container(
sections=[
Section.Code(
code=Op.MSTORE(0, Op.ADDRESS)
+ Op.EXTCALL(callback_address, 0, 32, 0)
+ Op.RETURNCONTRACT[0](0, 0),
max_stack_height=4,
),
smallest_runtime_subcontainer,
]
)
),
],
),
)
# Storage in 0 should have the address,
post = {callback_address: Account(storage={0: expected_result})}
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)

0 comments on commit fd9255c

Please sign in to comment.