Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
316e6fe
refactor(tests): merge STATICCALL ecrecover tests, drop signer EOA
marioevz Nov 6, 2026
f0c0c7d
refactor(tests): merge STATICCALL-to-precompile tests, drop signer EOA
marioevz Nov 6, 2026
d031803
refactor(tests): merge static A <-> B call tests, drop fixed addresses
marioevz Nov 6, 2026
803ca79
fix(tests): merge static context-check tests, observe nested checks
marioevz Nov 6, 2026
8c8e830
fix(tests): deploy static_internal_call_store_clears_oog callee normally
marioevz Nov 6, 2026
0799315
fix(tests): make static_loop_calls_depth_then_revert reach the ping-pong
marioevz Nov 6, 2026
cd80aa3
fix(tests): merge static recursive bomb pre-call tests, store depth
marioevz Nov 6, 2026
cd5b5bd
refactor(tests): merge static_call50000bytes_contract50 tests
marioevz Nov 6, 2026
9c85e4a
fix(tests): call every RETURN bound in static_return_bounds
marioevz Nov 6, 2026
c7f7c29
fix(tests): merge static hash-precompile tests, derive outputs and gas
marioevz Nov 6, 2026
c64f655
fix(tests): drop duplicate static call1024 tests, fix copy-paste post
marioevz Nov 6, 2026
6e3a819
fix(tests): merge static LOG tests, make the failed call observable
marioevz Nov 6, 2026
aa884bb
refactor(tests): merge static call output tests, add returning callee
marioevz Nov 6, 2026
11620af
refactor(tests): merge static_call_OOG_additionalGasCosts tests
marioevz Nov 6, 2026
8da715c
refactor(tests): fix mypy types in merged stStaticCall tests
marioevz Nov 6, 2026
8929b06
fix(tests): observe identity output in static hash precompile test
marioevz Nov 17, 2026
40d22ab
fix(tests): restore CheckOpcodes3 paths in static_check_opcodes
marioevz Nov 17, 2026
fdb7ee1
refactor(tests): derive static ecrecover call gas from the fork
marioevz Nov 17, 2026
fbd6806
refactor(tests): drop legacy source blocks, describe stStaticCall tests
marioevz Nov 17, 2026
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
134 changes: 134 additions & 0 deletions tests/ported_static/stStaticCall/test_static_ab_acalls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"""
A non-static frame A STATICCALLs B, which STATICCALLs A back.

Ported from:
state_tests/stStaticCall/static_ABAcalls0Filler.json
state_tests/stStaticCall/static_ABAcalls1Filler.json
state_tests/stStaticCall/static_ABAcalls2Filler.json
state_tests/stStaticCall/static_ABAcalls3Filler.json
state_tests/stStaticCall/static_ABAcallsSuicide0Filler.json

@manually-enhanced: Do not overwrite. Merged; B calls back via CALLER.
"""

import pytest
from execution_testing import (
Account,
Address,
Alloc,
Bytecode,
Hash,
Op,
StateTestFiller,
Transaction,
)

REFERENCE_SPEC_GIT_PATH = "N/A"
REFERENCE_SPEC_VERSION = "N/A"

TX_VALUE = 100_000
RESULT_SLOT = 1
RESULT_SENTINEL = 0xFF
COUNTER_SLOT = 0


def frame_code(
body: str,
writes: str,
call_gas: Bytecode | int,
callee: Bytecode | Address,
) -> Bytecode:
"""Return the code of one side of the A <-> B ping-pong."""
store = Op.SSTORE if writes == "storage" else Op.MSTORE
load = Op.SLOAD if writes == "storage" else Op.MLOAD
call = Op.STATICCALL(gas=call_gas, address=callee)
if body == "result":
return store(RESULT_SLOT, call)
if body == "result_plus_one":
return store(RESULT_SLOT, Op.ADD(1, call))
if body == "counter":
return store(COUNTER_SLOT, Op.ADD(load(COUNTER_SLOT), 1)) + call
raise ValueError(f"Unknown body: {body}")


@pytest.mark.ported_from(
[
"state_tests/stStaticCall/static_ABAcalls0Filler.json",
"state_tests/stStaticCall/static_ABAcalls1Filler.json",
"state_tests/stStaticCall/static_ABAcalls2Filler.json",
"state_tests/stStaticCall/static_ABAcalls3Filler.json",
"state_tests/stStaticCall/static_ABAcallsSuicide0Filler.json",
],
)
@pytest.mark.valid_from("Cancun")
@pytest.mark.parametrize("writes", ["storage", "memory"])
@pytest.mark.parametrize(
"body, relative_gas, self_destruct",
[
pytest.param("result", False, False, id="acalls0"),
pytest.param("result", True, False, id="acalls1"),
pytest.param("counter", True, False, id="acalls2"),
pytest.param("result", False, True, id="acalls_suicide0"),
],
)
def test_static_ab_acalls(
state_test: StateTestFiller,
pre: Alloc,
body: str,
relative_gas: bool,
self_destruct: bool,
writes: str,
) -> None:
"""
Verify only the outermost, non-static A frame keeps its writes.

Every frame below it is static, so B's writes and A's re-entered
writes fail. With `self_destruct`, A sends its balance to B after
the call.
"""
a_gas: Bytecode | int = (
Op.SUB(Op.GAS, 100_000) if relative_gas else 100_000
)
b_gas: Bytecode | int = Op.SUB(Op.GAS, 100_000) if relative_gas else 50_000
b_body = "result_plus_one" if body == "result" else body
b = pre.deploy_contract(
code=frame_code(b_body, writes, b_gas, Op.CALLER) + Op.STOP
)
a_code = frame_code(body, writes, a_gas, b)
if self_destruct:
a_code += Op.SELFDESTRUCT(b)
seeded = body == "result" and writes == "storage"
a = pre.deploy_contract(
code=a_code + Op.STOP,
storage={RESULT_SLOT: RESULT_SENTINEL} if seeded else {},
)
entry = pre.deploy_contract(
code=Op.SSTORE(
0, Op.CALL(address=Op.CALLDATALOAD(0), value=Op.CALLVALUE)
)
+ Op.SSTORE(1, 1)
+ Op.STOP
)

tx = Transaction(
sender=pre.fund_eoa(),
to=entry,
data=Hash(a, left_padding=True),
value=TX_VALUE,
)

a_storage: dict[int, int] = {}
if writes == "storage":
if body == "counter":
a_storage = {COUNTER_SLOT: 1}
else:
a_storage = {RESULT_SLOT: 0}
post = {
entry: Account(storage={0: 1, 1: 1}),
a: Account(
storage=a_storage, balance=0 if self_destruct else TX_VALUE
),
b: Account(storage={}, balance=TX_VALUE if self_destruct else 0),
}

state_test(pre=pre, post=post, tx=tx)
193 changes: 0 additions & 193 deletions tests/ported_static/stStaticCall/test_static_ab_acalls0.py

This file was deleted.

Loading
Loading