diff --git a/converted-ethereum-tests.txt b/converted-ethereum-tests.txt index b266d7e4d2..6fb06a1f14 100644 --- a/converted-ethereum-tests.txt +++ b/converted-ethereum-tests.txt @@ -16,6 +16,7 @@ EOFTests/EIP3670/validInvalid.json EOFTests/EIP4200/validInvalid.json EOFTests/EIP4750/validInvalid.json EOFTests/efValidation/callf_into_nonreturning_.json +EOFTests/efValidation/dataloadn_.json EOFTests/efValidation/EOF1_embedded_container_.json EOFTests/efValidation/EOF1_eofcreate_valid_.json EOFTests/efValidation/EOF1_callf_truncated_.json diff --git a/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py b/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py index 6d40b95213..5e5fdd578a 100644 --- a/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py +++ b/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py @@ -89,6 +89,15 @@ ] INVALID: List[Container] = [ + Container( + name="DATALOADN_0_empty_data", + sections=[ + Section.Code( + code=Op.DATALOADN[0] + Op.POP + Op.STOP, + ), + ], + validity_error=EOFException.INVALID_DATALOADN_INDEX, + ), Container( name="DATALOADN_max_empty_data", sections=[ @@ -98,6 +107,56 @@ ], validity_error=EOFException.INVALID_DATALOADN_INDEX, ), + Container( + name="DATALOADN_1_over_data", + sections=[ + Section.Code( + code=Op.DATALOADN[1] + Op.POP + Op.STOP, + ), + Section.Data(b"\x00"), + ], + validity_error=EOFException.INVALID_DATALOADN_INDEX, + ), + Container( + name="DATALOADN_32_over_data", + sections=[ + Section.Code( + code=Op.DATALOADN[32] + Op.POP + Op.STOP, + ), + Section.Data(b"\xda" * 32), + ], + validity_error=EOFException.INVALID_DATALOADN_INDEX, + ), + Container( + name="DATALOADN_0_data_31", + sections=[ + Section.Code( + code=Op.DATALOADN[0] + Op.POP + Op.STOP, + ), + Section.Data(b"\xda" * 31), + ], + validity_error=EOFException.INVALID_DATALOADN_INDEX, + ), + Container( + name="DATALOADN_32_data_63", + sections=[ + Section.Code( + code=Op.DATALOADN[32] + Op.POP + Op.STOP, + ), + Section.Data(b"\xda" * 63), + ], + validity_error=EOFException.INVALID_DATALOADN_INDEX, + ), + Container( + name="DATALOADN_max_imm", + sections=[ + Section.Code( + code=Op.DATALOADN[0xFFFF] + Op.POP + Op.STOP, + ), + Section.Data(b"\xda" * 32), + ], + validity_error=EOFException.INVALID_DATALOADN_INDEX, + ), Container( name="DATALOADN_max_small_data", sections=[ @@ -143,14 +202,11 @@ def container_name(c: Container): VALID, ids=container_name, ) -def test_legacy_initcode_valid_eof_v1_contract( +def test_valid_containers_with_data_section( eof_test: EOFTestFiller, container: Container, ): - """ - Test creating various types of valid EOF V1 contracts using legacy - initcode and a contract creating transaction. - """ + """Test EOF validation of valid containers with data sections.""" assert container.validity_error is None, ( f"Valid container with validity error: {container.validity_error}" ) @@ -164,14 +220,11 @@ def test_legacy_initcode_valid_eof_v1_contract( INVALID, ids=container_name, ) -def test_legacy_initcode_invalid_eof_v1_contract( +def test_invalid_containers_with_data_section( eof_test: EOFTestFiller, container: Container, ): - """ - Test creating various types of valid EOF V1 contracts using legacy - initcode and a contract creating transaction. - """ + """Test EOF validation of invalid containers with data sections.""" assert container.validity_error is not None, "Invalid container without validity error" eof_test( container=container, diff --git a/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_data_opcodes.py b/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_data_opcodes.py index b4b0ecb58f..0c274d8a01 100644 --- a/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_data_opcodes.py +++ b/tests/osaka/eip7692_eof_v1/eip7480_data_section/test_data_opcodes.py @@ -2,6 +2,7 @@ import pytest +from ethereum_test_specs import EOFStateTestFiller from ethereum_test_tools import Account, Alloc, Environment, StateTestFiller, Transaction from ethereum_test_tools.eof.v1 import Container, Section from ethereum_test_tools.vm.opcode import Opcodes as Op @@ -14,6 +15,26 @@ pytestmark = pytest.mark.valid_from(EOF_FORK_NAME) +@pytest.mark.parametrize("index", [0, 1, 31, 32, 33, 63, 64]) +@pytest.mark.parametrize("suffix_len", [0, 1, 31, 32, 24000]) +def test_dataloadn(eof_state_test: EOFStateTestFiller, index: int, suffix_len: int): + """Basic tests for DATALOADN execution.""" + sentinel = 0x8000000000000000000000000000000000000000000000000000000000000001 + eof_state_test( + container=Container( + sections=[ + Section.Code( + Op.SSTORE(0, Op.DATALOADN[index]) + Op.STOP, + ), + Section.Data( + index * b"\xbe" + sentinel.to_bytes(32, byteorder="big") + suffix_len * b"\xaf" + ), + ], + ), + container_post=Account(storage={0: sentinel}), + ) + + def create_data_test(offset: int, datasize: int): """Generate data load operators test cases based on load offset and data section size.""" data = b"".join(i.to_bytes(length=2, byteorder="big") for i in range(1, datasize // 2 + 1)) diff --git a/tests/osaka/eip7692_eof_v1/eof_tracker.md b/tests/osaka/eip7692_eof_v1/eof_tracker.md index 89e1793da6..b95be30bd1 100644 --- a/tests/osaka/eip7692_eof_v1/eof_tracker.md +++ b/tests/osaka/eip7692_eof_v1/eof_tracker.md @@ -354,10 +354,10 @@ ### Validation -- [ ] Valid DATALOADN with various offsets (ethereum/tests: src/EOFTestsFiller/efValidation/dataloadn_Copier.json) +- [x] Valid DATALOADN with various offsets ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_data_opcodes.py::test_dataloadn`](./eip7480_data_section/test_data_opcodes/test_dataloadn.md) - [x] Truncated DATALOADN immediate ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py::test_dataloadn_truncated_immediate`](./eip7480_data_section/test_code_validation/test_dataloadn_truncated_immediate.md) -- [ ] DATALOADN offset out of bounds (ethereum/tests: src/EOFTestsFiller/efValidation/dataloadn_Copier.json) -- [ ] DATALOADN accessing not full word (ethereum/tests: src/EOFTestsFiller/efValidation/dataloadn_Copier.json) +- [x] DATALOADN offset out of bounds ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py::test_invalid_containers_with_data_section`](./eip7480_data_section/test_code_validation/test_invalid_containers_with_data_section.md) +- [x] DATALOADN accessing not full word ([`tests/osaka/eip7692_eof_v1/eip7480_data_section/test_code_validation.py::test_invalid_containers_with_data_section`](./eip7480_data_section/test_code_validation/test_invalid_containers_with_data_section.md) ## EIP-663: SWAPN, DUPN and EXCHANGE instructions