From b9b8309fc1d6a557a0a743b3e146bc4fd8f748d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 24 Oct 2024 15:02:21 +0200 Subject: [PATCH] new(tests): add migrated CALLF execution test cases --- converted-ethereum-tests.txt | 2 + .../eip4750_functions/test_callf_execution.py | 105 ++++++++++++++++++ tests/osaka/eip7692_eof_v1/eof_tracker.md | 2 +- 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/converted-ethereum-tests.txt b/converted-ethereum-tests.txt index b42c9749c1..195b3f9219 100644 --- a/converted-ethereum-tests.txt +++ b/converted-ethereum-tests.txt @@ -21,6 +21,8 @@ EOFTests/efValidation/EOF1_returncontract_valid_.json EIPTests/StateTests/stEOF/stEIP3540/EOF1_Execution.json EIPTests/StateTests/stEOF/stEIP4200/EOF1_RJUMP_RJUMPI_RJUMPV_Execution.json +EIPTests/StateTests/stEOF/stEIP4750/CALLF_RETF_Execution.json +EIPTests/StateTests/stEOF/stEIP5450/EOF1_CALLF_Execution.json ([#440](https://github.com/ethereum/execution-spec-tests/pull/440)) GeneralStateTests/Cancun/stEIP1153-transientStorage/01_tloadBeginningTxn.json diff --git a/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py b/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py index f49859b063..bae7f80176 100644 --- a/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py +++ b/tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py @@ -111,6 +111,65 @@ def test_callf_fibonacci(eof_state_test: EOFStateTestFiller, n, result): ) +@pytest.mark.parametrize( + "container", + ( + Container( + name="callf_sub_retf", + sections=[ + Section.Code( + Op.SSTORE( + slot_code_worked, + Op.PUSH1[1] + Op.PUSH2[value_code_worked + 1] + Op.CALLF[1], + ) + + Op.STOP, + max_stack_height=2, + ), + Section.Code( + Op.SUB + Op.RETF, + code_inputs=2, + code_outputs=1, + max_stack_height=2, + ), + ], + ), + Container( + name="max_code_sections_retf2", + sections=[ + Section.Code( + Op.CALLF[1] + Op.SSTORE + Op.STOP, + max_stack_height=2, + ) + ] + + [ + Section.Code( + Op.CALLF[i] + Op.RETF, + code_inputs=0, + code_outputs=2, + max_stack_height=2, + ) + for i in range(2, 1024) + ] + + [ + Section.Code( + Op.PUSH2[value_code_worked] + Op.PUSH1[slot_code_worked] + Op.RETF, + code_inputs=0, + code_outputs=2, + max_stack_height=2, + ), + ], + ), + ), + ids=lambda x: x.name, +) +def test_callf(eof_state_test: EOFStateTestFiller, container: Container): + """Test basic usage of CALLF and RETF instructions""" + eof_state_test( + data=container, + container_post=Account(storage={slot_code_worked: value_code_worked}), + ) + + @pytest.mark.parametrize( "container", ( @@ -237,6 +296,52 @@ def test_callf_fibonacci(eof_state_test: EOFStateTestFiller, n, result): ), ], ), + Container( + name="store_value_unmodified_by_callf", + sections=[ + Section.Code( + Op.PUSH2[value_code_worked] # to be stored after CALLF + + Op.PUSH0 # input to CALLF + + Op.CALLF[1] + + Op.PUSH1[slot_code_worked] + + Op.SSTORE + + Op.STOP, + max_stack_height=2, + ), + Section.Code( + Op.POP # clear input + + Op.PUSH0 * 1023 # reach max stack height + + Op.POP * 1023 + + Op.RETF, # return nothing + code_inputs=1, + code_outputs=0, + max_stack_height=1023, + ), + ], + ), + Container( + name="with_rjumpi", + sections=[ + Section.Code( + Op.PUSH1[1] # input[1] to CALLF + + Op.PUSH0 # input[0] to CALLF + + Op.CALLF[1] + + Op.SSTORE(slot_code_worked, value_code_worked) + + Op.STOP, + max_stack_height=2, + ), + Section.Code( + Op.POP # clear input[0] + + Op.RJUMPI[2 * 1023] # jump to RETF based on input[1] + + Op.PUSH0 * 1023 # reach max stack height + + Op.POP * 1023 + + Op.RETF, # return nothing + code_inputs=2, + code_outputs=0, + max_stack_height=1023, + ), + ], + ), ), ids=lambda x: x.name, ) diff --git a/tests/osaka/eip7692_eof_v1/eof_tracker.md b/tests/osaka/eip7692_eof_v1/eof_tracker.md index c52880ba92..a8593dfa07 100644 --- a/tests/osaka/eip7692_eof_v1/eof_tracker.md +++ b/tests/osaka/eip7692_eof_v1/eof_tracker.md @@ -325,7 +325,7 @@ ### Execution -- [ ] Max stack size (1024) in CALLF-ed function (ethereum/tests: src/EIPTestsFiller/StateTests/stEOF/stEIP4200/EOF1_CALLF_ExecutionFiller.yml) +- [x] Max stack size (1024) in CALLF-ed function ([`tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py::test_callf_operand_stack_size_max`](./eip4750_functions/test_callf_execution/test_callf_operand_stack_size_max.md) ## EIP-6206: EOF - JUMPF and non-returning functions