From b8c24d67fdb8c29dd7e0b02f25af8b0cbf5f649f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 23 Jan 2025 16:08:11 +0100 Subject: [PATCH] new(tests): CALLF with truncated immediate bytes --- converted-ethereum-tests.txt | 3 +- .../eip4750_functions/test_code_validation.py | 54 +++++++++++++++++++ tests/osaka/eip7692_eof_v1/eof_tracker.md | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/converted-ethereum-tests.txt b/converted-ethereum-tests.txt index eab09f89b3..961d937768 100644 --- a/converted-ethereum-tests.txt +++ b/converted-ethereum-tests.txt @@ -13,6 +13,7 @@ EOFTests/EIP3670/validInvalid.json EOFTests/EIP4200/validInvalid.json EOFTests/efValidation/EOF1_embedded_container_.json EOFTests/efValidation/EOF1_eofcreate_valid_.json +EOFTests/efValidation/EOF1_callf_truncated_.json EOFTests/efValidation/EOF1_valid_rjump_.json EOFTests/efValidation/EOF1_valid_rjumpi_.json EOFTests/efValidation/EOF1_valid_rjumpv_.json @@ -59,4 +60,4 @@ GeneralStateTests/Cancun/stEIP1153-transientStorage/18_tloadAfterStore.json GeneralStateTests/Cancun/stEIP1153-transientStorage/20_oogUndoesTransientStoreInCall.json ([#975](https://github.com/ethereum/execution-spec-tests/pull/975)) -GeneralStateTests/VMTests/vmTests/push.json \ No newline at end of file +GeneralStateTests/VMTests/vmTests/push.json diff --git a/tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py b/tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py index 62088382e3..e8e9ac4119 100644 --- a/tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py +++ b/tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py @@ -12,6 +12,7 @@ MAX_OPERAND_STACK_HEIGHT, ) from ethereum_test_tools.vm.opcode import Opcodes as Op +from ethereum_test_vm import Bytecode from .. import EOF_FORK_NAME @@ -175,6 +176,59 @@ def test_eof_validity( eof_test(data=container) +@pytest.mark.parametrize( + "container", + [ + Container( + name="imm0", + sections=[ + Section.Code( + code=Op.CALLF, + ) + ], + validity_error=EOFException.TRUNCATED_INSTRUCTION, + ), + Container( + name="imm1", + sections=[ + Section.Code( + code=Op.CALLF + Bytecode(b"\x00"), + ) + ], + validity_error=EOFException.TRUNCATED_INSTRUCTION, + ), + Container( + name="imm_from_next_section", + sections=[ + Section.Code( + code=Op.PUSH0 + Op.PUSH0 + Op.CALLF[1] + Op.STOP, + ), + Section.Code( + code=Op.CALLF + Bytecode(b"\x00"), # would be valid with "02" + Op.RETF. + code_inputs=2, + code_outputs=1, + max_stack_height=2, + ), + Section.Code( + code=Op.SUB + Op.RETF, # SUB (0x02) can be confused with CALLF[2]. + code_inputs=2, + code_outputs=1, + max_stack_height=2, + ), + ], + validity_error=EOFException.TRUNCATED_INSTRUCTION, + ), + ], + ids=container_name, +) +def test_callf_truncated_immediate( + eof_test: EOFTestFiller, + container: Container, +): + """Test cases for CALLF instructions with truncated immediate bytes.""" + eof_test(data=container, expect_exception=EOFException.TRUNCATED_INSTRUCTION) + + @pytest.mark.parametrize( "container", [ diff --git a/tests/osaka/eip7692_eof_v1/eof_tracker.md b/tests/osaka/eip7692_eof_v1/eof_tracker.md index d6f4f3a67a..20374f342a 100644 --- a/tests/osaka/eip7692_eof_v1/eof_tracker.md +++ b/tests/osaka/eip7692_eof_v1/eof_tracker.md @@ -151,7 +151,7 @@ - [ ] Valid CALLFs (ethereum/tests: ./src/EOFTestsFiller/efExample/validInvalidFiller.yml) - [ ] CALLFs to non-existing sections (ethereum/tests: ./src/EOFTestsFiller/efExample/validInvalidFiller.yml src/EOFTestsFiller/efValidation/callf_invalid_code_section_index_Copier.json src/EOFTestsFiller/EIP4750/validInvalidFiller.yml) -- [ ] Truncated CALLF immediate (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_callf_truncated_Copier.json src/EOFTestsFiller/EIP4750/validInvalidFiller.yml) +- [x] Truncated CALLF immediate ([`tests/osaka/eip7692_eof_v1/eip4750_functions/test_code_validation.py::test_callf_truncated_immediate`](./eip4750_functions/test_code_validation/test_callf_truncated_immediate.md)) - [ ] Unreachable code sections (ethereum/tests: src/EOFTestsFiller/efValidation/unreachable_code_sections_Copier.json) - [ ] Sections reachable from other sections, but not reachable from section 0 (ethereum/tests: src/EOFTestsFiller/efValidation/unreachable_code_sections_Copier.json) - [ ] Unreachable code section that calls itself with JUMPF