Skip to content

Commit

Permalink
new(tests): EOF - EIP-7069: call precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobacz committed Sep 25, 2024
1 parent 4e6b78d commit 9ed640d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/prague/eip7692_eof_v1/eip7069_extcall/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,75 @@ def test_eof_calls_eof_mstore(
)


identity = Address(0x04)
# `blake2f`` is chosen for the test because it fails unless args_size == 213, which is what we are
# interested in.
blake2f = Address(0x09)


@pytest.mark.parametrize(
"opcode",
[
Op.EXTCALL,
Op.EXTDELEGATECALL,
Op.EXTSTATICCALL,
],
)
@pytest.mark.parametrize(
"precompile", [pytest.param(identity, id="identity"), pytest.param(blake2f, id="blake2f")]
)
def test_eof_calls_precompile(
state_test: StateTestFiller,
pre: Alloc,
sender: EOA,
opcode: Op,
precompile: Address,
):
"""Test EOF contracts calling precompiles"""
env = Environment()

caller_contract = Container.Code(
Op.MSTORE(0, value_returndata_magic)
+ Op.SSTORE(slot_call_result, opcode(address=precompile, args_offset=0, args_size=32))
+ Op.SSTORE(slot_returndatasize, Op.RETURNDATASIZE)
+ Op.SSTORE(slot_returndata, Op.RETURNDATALOAD(0))
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.STOP,
)
calling_contract_address = pre.deploy_contract(caller_contract)

tx = Transaction(
sender=sender,
to=Address(calling_contract_address),
gas_limit=5000000,
data="",
)

calling_storage = {
slot_code_worked: value_code_worked,
slot_call_result: value_eof_call_reverted
if opcode == Op.EXTDELEGATECALL
else value_eof_call_failed
if precompile == blake2f
else value_eof_call_worked,
slot_returndatasize: 0 if opcode == Op.EXTDELEGATECALL or precompile == blake2f else 32,
slot_returndata: 0
if opcode == Op.EXTDELEGATECALL or precompile == blake2f
else value_returndata_magic,
}

post = {
calling_contract_address: Account(storage=calling_storage),
}

state_test(
env=env,
pre=pre,
post=post,
tx=tx,
)


@pytest.mark.parametrize(
"opcode",
[
Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bidict
big0
big1
bigint
blake2f
blobgasfee
blockchain
BlockchainFixtures
Expand Down

0 comments on commit 9ed640d

Please sign in to comment.