Skip to content

Commit

Permalink
new(tests): add migrated CALLF execution test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Oct 29, 2024
1 parent d20b3c4 commit 8298c2f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
2 changes: 2 additions & 0 deletions converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 105 additions & 0 deletions tests/osaka/eip7692_eof_v1/eip4750_functions/test_callf_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
(
Expand Down Expand Up @@ -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,
)
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 @@ -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
Expand Down

0 comments on commit 8298c2f

Please sign in to comment.