Skip to content

Commit b152eca

Browse files
committed
selfdestruct in initcode
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
1 parent d4ed12c commit b152eca

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/zkevm/test_worst_stateful_opcodes.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,52 @@ def test_worst_selfdestruct_created(
660660
post=post,
661661
tx=code_tx,
662662
)
663+
664+
665+
@pytest.mark.valid_from("Cancun")
666+
@pytest.mark.parametrize("value_bearing", [True, False])
667+
def test_worst_selfdestruct_initcode(
668+
state_test: StateTestFiller,
669+
pre: Alloc,
670+
value_bearing: bool,
671+
):
672+
"""Test running a block with as many SELFDESTRUCTs as possible executed in initcode."""
673+
env = Environment()
674+
pre.fund_address(env.fee_recipient, 1)
675+
676+
# code = Op.SELFDESTRUCT(Op.COINBASE)
677+
initcode = 0x41FF
678+
code = (
679+
Op.MSTORE(0, initcode)
680+
+ While(
681+
body=Op.POP(
682+
Op.CALL(
683+
address=Op.CREATE(
684+
value=1 if value_bearing else 0,
685+
offset=30,
686+
size=2,
687+
)
688+
)
689+
),
690+
# Stop before we run out of gas for the whole tx execution.
691+
# The value was found by trial-error rounded to the next 1000 multiple.
692+
condition=Op.GT(Op.GAS, 10_000),
693+
)
694+
+ Op.SSTORE(0, 42) # Done for successful tx execution assertion below.
695+
)
696+
# The 0 storage slot is initialize to avoid creation costs in SSTORE above.
697+
code_addr = pre.deploy_contract(code=code, balance=100_000, storage={0: 1})
698+
code_tx = Transaction(
699+
to=code_addr,
700+
gas_limit=env.gas_limit,
701+
gas_price=10,
702+
sender=pre.fund_eoa(),
703+
)
704+
705+
post = {code_addr: Account(storage={0: 42})} # Check for successful execution.
706+
state_test(
707+
env=env,
708+
pre=pre,
709+
post=post,
710+
tx=code_tx,
711+
)

0 commit comments

Comments
 (0)