Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests): EOF - EIP-4750: parametrize CALLF execution tests #913

Merged
Merged
Changes from all commits
Commits
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
142 changes: 57 additions & 85 deletions tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)


def test_callf_stack_size_1024(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in called function"""
eof_state_test(
data=Container(
@pytest.mark.parametrize(
"container",
(
Container(
name="no_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand All @@ -45,16 +44,8 @@ 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(
Container(
name="with_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand All @@ -72,16 +63,8 @@ def test_callf_with_inputs_stack_size_1024(
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_stack_size_1024_at_callf(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in called function at CALLF instruction"""
eof_state_test(
data=Container(
Container(
name="at_callf",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand All @@ -107,16 +90,8 @@ def test_callf_stack_size_1024_at_callf(
),
],
),
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_stack_size_1024_at_push(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in nested called function at PUSH0 instruction"""
eof_state_test(
data=Container(
Container(
name="at_push0",
sections=[
Section.Code(
code=Op.PUSH0 * 1022
Expand Down Expand Up @@ -144,90 +119,80 @@ def test_callf_stack_size_1024_at_push(
),
],
),
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(
Container(
name="nested_with_inputs_at_push0",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
code=Op.PUSH0 * 1022
marioevz marked this conversation as resolved.
Show resolved Hide resolved
+ Op.CALLF[1]
+ Op.POP * 1023
+ Op.POP * 1022
+ Op.SSTORE(slot_code_worked, value_code_worked)
marioevz marked this conversation as resolved.
Show resolved Hide resolved
+ Op.RETURN(0, 0),
max_stack_height=1023,
max_stack_height=1022,
),
Section.Code(
Op.PUSH0 +
# Stack has 1024 items
# Stack has 1023 items
Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
Section.Code(
Op.PUSH0 +
# Runtime stack overflow
# Stack has 1024 items
Op.POP + Op.RETF,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
),
],
),
container_post=Account(storage={slot_code_worked: 0}),
),
ids=lambda x: x.name,
)
def test_callf_operand_stack_size_max(eof_state_test: EOFStateTestFiller, container: Container):
"""Test operand stack reaching 1024 items"""
eof_state_test(
data=container,
container_post=Account(storage={slot_code_worked: value_code_worked}),
)


def test_callf_with_inputs_stack_size_1024_at_push(
eof_state_test: EOFStateTestFiller,
):
"""Test stack reaching 1024 items in nested called function with inputs at PUSH0 instruction"""
eof_state_test(
data=Container(
@pytest.mark.parametrize(
"container",
(
Container(
name="no_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1022
code=Op.PUSH0 * 1023
+ Op.CALLF[1]
+ Op.POP * 1022
+ Op.POP * 1023
+ Op.SSTORE(slot_code_worked, value_code_worked)
+ Op.RETURN(0, 0),
max_stack_height=1022,
max_stack_height=1023,
),
Section.Code(
Op.PUSH0 +
# Stack has 1023 items
# Stack has 1024 items
Op.CALLF[2] + Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
Section.Code(
Op.PUSH0 +
# Stack has 1024 items
# Runtime stack overflow
Op.POP + Op.RETF,
code_inputs=3,
code_outputs=3,
max_stack_height=4,
code_inputs=0,
code_outputs=0,
max_stack_height=1,
),
],
),
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(
Container(
name="with_inputs",
sections=[
Section.Code(
code=Op.PUSH0 * 1023
Expand Down Expand Up @@ -255,6 +220,13 @@ def test_callf_with_inputs_stack_overflow(
),
],
),
),
ids=lambda x: x.name,
)
def test_callf_operand_stack_overflow(eof_state_test: EOFStateTestFiller, container: Container):
"""Test stack overflowing 1024 items in called function"""
marioevz marked this conversation as resolved.
Show resolved Hide resolved
eof_state_test(
data=container,
container_post=Account(storage={slot_code_worked: 0}),
)

Expand Down