Skip to content

Commit

Permalink
new(tests): Add test for CALLF runtime stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 12, 2024
1 parent 63b9305 commit eb2a41e
Showing 1 changed file with 159 additions and 0 deletions.
159 changes: 159 additions & 0 deletions tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,162 @@ def test_callf_stack_size_1024(
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_with_inputs_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in called function with inputs"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
),
Section.Code(
Op.PUSH0 + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_3_functions_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in nested called function"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1022
+ Op.CALLF[1]
+ Op.POP * 1022
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1022,
),
Section.Code(
Op.PUSH0 + Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
Section.Code(
Op.PUSH0 + Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_stack_overflow(
eof_state_test: EOFStateTestFiller,
):
"""Test stack overflowing 1024 items in called function"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
),
Section.Code(
Op.PUSH0 + Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
Section.Code(
Op.PUSH0 + Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
],
),
container_post=Account(storage={slot_code_worked: 0}),
)


def test_callf_3_functions_with_inputs_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in nested called function with inputs"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1022
+ Op.CALLF[1]
+ Op.POP * 1022
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1022,
),
Section.Code(
Op.PUSH0 + Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
Section.Code(
Op.PUSH0 + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_with_inputs_stack_overflow(
eof_state_test: EOFStateTestFiller,
):
"""Test stack overflowing 1024 items in called function with inputs"""
eof_state_test(
data=Container(
sections=[
Section.Code(
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1023,
),
Section.Code(
Op.PUSH0 + Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
Section.Code(
Op.PUSH0 + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
],
),
container_post=Account(storage={slot_code_worked: 0}),
)

0 comments on commit eb2a41e

Please sign in to comment.