Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ethereum_test_forks to be EIP/RIP based #1164

Open
marioevz opened this issue Jan 31, 2025 · 0 comments
Open

Refactor ethereum_test_forks to be EIP/RIP based #1164

marioevz opened this issue Jan 31, 2025 · 0 comments
Assignees

Comments

@marioevz
Copy link
Member

Explore the possibility to refactor the fork definitions of src/ethereum_test_forks/forks/forks.py to be distributed in EIP class definitions.

For example, for class Prague, 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:

@classmethod
def system_contracts(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]:
"""Prague introduces the system contracts for EIP-6110, EIP-7002, EIP-7251 and EIP-2935."""
return [
Address(0x00000000219AB540356CBB839CBE05303D7705FA),
Address(0x00000961EF480EB55E80D19AD83579A64C007002),
Address(0x0000BBDDC7CE488642FB579F8B00F3A590007251),
Address(0x0000F90827F1C53A10CB7A02335B175320002935),
] + super(Prague, cls).system_contracts(block_number, timestamp)

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

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:

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:

@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:

uv run fill --fork=Prague+EIP1234

And then Prague class could be re-defined on the fly to be:

class CustomPrague(Prague, EIP1234):
  ...

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants