From 8ce811b1df6c4fab01f86b71d275eb8c484d456f 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 | 58 +++++++++++++++++++ 1 file changed, 58 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 56dbd017cb..bd5392ad02 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,61 @@ 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_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, + ), + ], + ), + # TODO expect execution exceptional abort? + validity_error=EOFException.UNDEFINED_EXCEPTION, + )