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

[WIP] new(tests): EIP-7002: Execution layer triggerable withdrawals #531

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions src/ethereum_test_forks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
London,
MuirGlacier,
Paris,
Prague,
Shanghai,
)
from .forks.transition import (
Expand Down Expand Up @@ -60,6 +61,7 @@
"Shanghai",
"ShanghaiToCancunAtTime15k",
"Cancun",
"Prague",
"get_transition_forks",
"forks_from",
"forks_from_until",
Expand Down
8 changes: 8 additions & 0 deletions src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def header_beacon_root_required(cls, block_number: int, timestamp: int) -> bool:
"""
pass

@classmethod
@abstractmethod
def header_requests_required(cls, block_number: int, timestamp: int) -> bool:
"""
Returns true if the header must contain beacon chain requests
"""
pass

@classmethod
@abstractmethod
def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
Expand Down
Binary file not shown.
69 changes: 69 additions & 0 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
All Ethereum fork class definitions.
"""

from hashlib import sha256
from os.path import realpath
from pathlib import Path
from typing import List, Mapping, Optional

from semver import Version

from ..base_fork import BaseFork

CURRENT_FILE = Path(realpath(__file__))
CURRENT_FOLDER = CURRENT_FILE.parent


# All forks must be listed here !!! in the order they were introduced !!!
class Frontier(BaseFork, solc_name="homestead"):
Expand Down Expand Up @@ -89,6 +95,13 @@ def blob_gas_per_blob(cls, block_number: int, timestamp: int) -> int:
"""
return 0

@classmethod
def header_requests_required(cls, block_number: int, timestamp: int) -> bool:
"""
At genesis, header must not contain beacon chain requests.
"""
return False

@classmethod
def engine_new_payload_version(
cls, block_number: int = 0, timestamp: int = 0
Expand Down Expand Up @@ -474,3 +487,59 @@ def solc_min_version(cls) -> Version:
Returns the minimum version of solc that supports this fork.
"""
return Version.parse("1.0.0") # set a high version; currently unknown

@classmethod
def pre_allocation_blockchain(cls) -> Mapping:
"""
Prague requires pre-allocation of the beacon chain deposit contract for EIP-6110, and
the exits contract for EIP-7002.
"""
new_allocation = {}

# Add the beacon chain deposit contract
DEPOSIT_CONTRACT_TREE_DEPTH = 32
storage = {}
next_hash = sha256(b"\x00" * 64).digest()
for i in range(DEPOSIT_CONTRACT_TREE_DEPTH + 2, DEPOSIT_CONTRACT_TREE_DEPTH * 2 + 1):
storage[i] = next_hash
next_hash = sha256(next_hash + next_hash).digest()

with open(CURRENT_FOLDER / "deposit_contract.bin", mode="rb") as f:
new_allocation.update(
{
0x00000000219AB540356CBB839CBE05303D7705FA: {
"nonce": 1,
"code": f.read(),
"storage": storage,
}
}
)

# Add the withdrawal request contract
with open(CURRENT_FOLDER / "withdrawal_request.bin", mode="rb") as f:
new_allocation.update(
{
0x00A3CA265EBCB825B45F985A16CEFB49958CE017: {
"nonce": 1,
"code": f.read(),
},
}
)
return new_allocation | super(Prague, cls).pre_allocation_blockchain()

@classmethod
def header_requests_required(cls, block_number: int, timestamp: int) -> bool:
"""
Prague requires that the execution layer block contains the beacon
chain requests.
"""
return True

@classmethod
def engine_new_payload_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
Starting at Prague, new payload calls must use version 4
"""
return 4
Binary file added src/ethereum_test_forks/forks/withdrawal_request.bin
Binary file not shown.
7 changes: 6 additions & 1 deletion src/ethereum_test_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Account,
Address,
Alloc,
DepositRequest,
EngineAPIError,
Environment,
Hash,
Expand All @@ -31,6 +32,7 @@
TestPrivateKey2,
Transaction,
Withdrawal,
WithdrawalRequest,
add_kzg_version,
ceiling_division,
compute_create2_address,
Expand All @@ -56,7 +58,7 @@
TestInfo,
)
from .spec.blockchain.types import Block, Header
from .vm import Macro, Opcode, OpcodeCallArg, Opcodes
from .vm import Macro, Macros, Opcode, OpcodeCallArg, Opcodes

__all__ = (
"SPEC_TYPES",
Expand All @@ -75,6 +77,7 @@
"Code",
"CodeGasMeasure",
"Conditional",
"DepositRequest",
"EngineAPIError",
"Environment",
"EOFException",
Expand All @@ -85,6 +88,7 @@
"Header",
"Initcode",
"Macro",
"Macros",
"Opcode",
"OpcodeCallArg",
"Opcodes",
Expand All @@ -104,6 +108,7 @@
"Transaction",
"TransactionException",
"Withdrawal",
"WithdrawalRequest",
"Yul",
"YulCompiler",
"add_kzg_version",
Expand Down
6 changes: 6 additions & 0 deletions src/ethereum_test_tools/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
AccessList,
Account,
Alloc,
DepositRequest,
Environment,
Removable,
Requests,
Storage,
Transaction,
Withdrawal,
WithdrawalRequest,
)

__all__ = (
Expand All @@ -55,6 +58,7 @@
"Alloc",
"Bloom",
"Bytes",
"DepositRequest",
"EngineAPIError",
"EmptyOmmersRoot",
"EmptyTrieRoot",
Expand All @@ -64,6 +68,7 @@
"HexNumber",
"Number",
"Removable",
"Requests",
"Storage",
"TestAddress",
"TestAddress2",
Expand All @@ -72,6 +77,7 @@
"TestPrivateKey2",
"Transaction",
"Withdrawal",
"WithdrawalRequest",
"ZeroPaddedHexNumber",
"add_kzg_version",
"ceiling_division",
Expand Down
16 changes: 16 additions & 0 deletions src/ethereum_test_tools/common/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,19 @@ class HeaderNonce(FixedSizeBytes[8]): # type: ignore
"""

pass


class BLSPublicKey(FixedSizeBytes[48]): # type: ignore
"""
Class that helps represent BLS public keys in tests.
"""

pass


class BLSSignature(FixedSizeBytes[96]): # type: ignore
"""
Class that helps represent BLS signatures in tests.
"""

pass