From eb2a41e490a692648fe4b9570c84e8bebdbf0131 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Thu, 11 Jul 2024 15:42:36 +0200 Subject: [PATCH] new(tests): Add test for CALLF runtime stack overflow --- .../eip4750_functions/test_callf_execution.py | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py b/tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py index adf1033e4b..15d373c738 100644 --- a/tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py +++ b/tests/prague/eip7692_eof_v1/eip4750_functions/test_callf_execution.py @@ -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}), + )