Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(tests): add tests for DATALOADN validation and execution
Browse files Browse the repository at this point in the history
chfast committed Jan 30, 2025
1 parent 47087df commit c66ef61
Showing 4 changed files with 87 additions and 14 deletions.
3 changes: 2 additions & 1 deletion converted-ethereum-tests.txt
Original file line number Diff line number Diff line change
@@ -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
@@ -70,4 +71,4 @@ GeneralStateTests/Cancun/stEIP1153-transientStorage/20_oogUndoesTransientStoreIn
GeneralStateTests/VMTests/vmTests/push.json

([#1067](https://github.com/ethereum/execution-spec-tests/pull/1067))
GeneralStateTests/stPreCompiledContracts/blake2B.json
GeneralStateTests/stPreCompiledContracts/blake2B.json
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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,24 @@
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.DATALOADN[index] + Op.SSTORE(0, unchecked=True) + Op.STOP,
),
Section.Data(index * b"\xbe" + sentinel.to_bytes(32) + 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))
6 changes: 3 additions & 3 deletions tests/osaka/eip7692_eof_v1/eof_tracker.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c66ef61

Please sign in to comment.