Skip to content

Commit

Permalink
new(tests): CALLF with truncated immediate bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jan 23, 2025
1 parent b792235 commit b8c24d6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
GeneralStateTests/VMTests/vmTests/push.json
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
[
Expand Down
2 changes: 1 addition & 1 deletion tests/osaka/eip7692_eof_v1/eof_tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8c24d6

Please sign in to comment.