ethereum / ethereum/execution-specs

Refactor `ethereum_test_forks` to be EIP/RIP based

Open
#1,512 5 comments 0 reactions 1 assignee Claimed by @spencer-tb View on GitHub
stale
Dominant language
Python
Stars
1.2k
Forks
505
Avg merge
2d 14h
Merged PRs (30d)
116

Description

Explore the possibility to refactor the fork definitions of [`src/ethereum_test_forks/forks/forks.py`](https://github.com/ethereum/execution-spec-tests/blob/main/src/ethereum_test_forks/forks/forks.py) to be distributed in EIP class definitions.

For example, for [`class Prague`](https://github.com/ethereum/execution-spec-tests/blob/fef9a263f2a4c9cb7d6568b5dde1e0eea8fe1da1/src/ethereum_test_forks/forks/forks.py#L1044), there's currently a single definition of, for example, the `system_contracts` method that contains all the contracts added by each EIP included in Prague:
https://github.com/ethereum/execution-spec-tests/blob/fef9a263f2a4c9cb7d6568b5dde1e0eea8fe1da1/src/ethereum_test_forks/forks/forks.py#L1091-L1099

But we could theoretically split this method to be defined in a separate class for each EIP:

```python
class EIP6110:
@classmethod
def system_contracts(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]:
"""EIP-6110 introduces the beacon chain as a system contract."""
return [
Address(0x00000000219AB540356CBB839CBE05303D7705FA),
] + super(EIP6110, cls).system_contracts(block_number, timestamp)
```

And then Prague simply inherit all EIPs on definition:

```python
class Prague(Cancun, EIP6110, EIP7002, ...
```

Theoretically we could now know the EIP composition of every fork and enable/disable tests for the forks that incorporate the EIP that is supposed to test:

```python
@pytest.mark.valid_from(eip=1234)
def test_eip_1234_features(state_test: StateTestFiller):
...
```

Also we could more easily think of define custom forks which enable or disable certain EIPs, by dynamically redefining the fork plus some custom EIP:

```python
uv run fill --fork=Prague+EIP1234
```

And then `Prague` class could be re-defined on the fly to be:
```python
class CustomPrague(Prague, EIP1234):
...
```

It would be more difficult to define fork with a certain EIP removed, but it would not be impossible.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.