Skip to content

test_callf_max_stack()

Documentation for tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py::test_callf_max_stack@49a16fac.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py::test_callf_max_stack --fork Osaka

CALLF where a normal execution would not overflow, but EIP-4750 CALLF rule #4 triggers.

Code Section 0 - calls #1 with the configured height, but we load some operands so the return stack does not overflow Code Section 1 - expands stack, calls #2, THEN recursively calls itself until input is zero, and returns. Code Section 2 - Just returns, zero inputs, zero outputs

This will catch CALLF execution rule #3: always fail if the operand stack is full. Not checking rule 3 results in a call to section 2 and not overfilling the stack (as it is just RETF).

Source code in tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
@pytest.mark.parametrize(
    ("stack_height", "failure"),
    (
        pytest.param(1018, False, id="no_max_stack"),
        pytest.param(1019, False, id="with_max_stack"),
        pytest.param(1020, True, id="over_max_stack"),
    ),
)
def test_callf_max_stack(
    stack_height: int,
    failure: bool,
    state_test: StateTestFiller,
    pre: Alloc,
):
    """
    CALLF where a normal execution would not overflow, but EIP-4750 CALLF rule #4 triggers.

    Code Section 0 - calls #1 with the configured height, but we load some operands so the
                     return stack does not overflow
    Code Section 1 - expands stack, calls #2, THEN recursively calls itself until input is zero,
                     and returns.
    Code Section 2 - Just returns, zero inputs, zero outputs

    This will catch  CALLF execution rule #3: always fail if the operand stack is full. Not
    checking rule 3 results in a call to section 2 and not overfilling the stack (as it is just
    RETF).
    """
    env = Environment()
    sender = pre.fund_eoa()
    contract_address = pre.deploy_contract(
        code=Container(
            sections=[
                Section.Code(
                    code=Op.PUSH0 * 4  # fill the stack up a little bit
                    + Op.PUSH2(stack_height)
                    + Op.CALLF[1]
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.RETURN(0, 0),
                    max_stack_height=7,
                ),
                Section.Code(
                    Op.PUSH1(1)  # arg, 1
                    + Op.SWAP1  # 1, arg
                    + Op.SUB  # arg-1,
                    + Op.DUP1  # arg-1, arg-1
                    + Op.CALLF[2]  # arg-1, arg-1
                    + Op.ISZERO  # jump?, arg-1,
                    + Op.RJUMPI[5]  # arg-1
                    + Op.DUP1  # arg-1, arg-1
                    + Op.CALLF[1]  # ret, arg-1
                    + Op.POP  # arg-1
                    + Op.RETF,
                    code_inputs=1,
                    code_outputs=1,
                    max_stack_height=2,
                ),
                Section.Code(
                    Op.RETF,
                    code_inputs=0,
                    code_outputs=0,
                    max_stack_height=0,
                ),
            ],
        ),
        storage={
            slot_code_worked: (
                value_canary_should_not_change if failure else value_canary_to_be_overwritten
            ),
        },
    )

    post = {
        contract_address: Account(
            storage={
                slot_code_worked: (
                    value_canary_should_not_change if failure else value_code_worked
                ),
            }
        )
    }

    tx = Transaction(
        to=contract_address,
        gas_limit=100_000,
        sender=sender,
    )
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) stack_height failure
...fork_Osaka-blockchain_test-no_max_stack 1018 False
...fork_Osaka-blockchain_test-with_max_stack 1019 False
...fork_Osaka-blockchain_test-over_max_stack 1020 True
...fork_Osaka-state_test-no_max_stack 1018 False
...fork_Osaka-state_test-with_max_stack 1019 False
...fork_Osaka-state_test-over_max_stack 1020 True