Skip to content

Commit

Permalink
If no code exists at the BEACON_ROOTS_ADDRESS, make it so.
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Feb 21, 2024
1 parent 63f5d3b commit 41654b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions eth/vm/forks/cancun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from eth.abc import (
BlockHeaderAPI,
ChainContextAPI,
ChainDatabaseAPI,
ConsensusContextAPI,
StateAPI,
)
from eth.rlp.blocks import (
Expand All @@ -24,6 +27,7 @@
)
from .constants import (
BEACON_ROOTS_ADDRESS,
BEACON_ROOTS_CONTRACT_CODE,
HISTORY_BUFFER_LENGTH,
)
from .headers import (
Expand All @@ -49,6 +53,24 @@ class CancunVM(ShanghaiVM):
)
configure_header = configure_cancun_header

def __init__(
self,
header: BlockHeaderAPI,
chaindb: ChainDatabaseAPI,
chain_context: ChainContextAPI,
consensus_context: ConsensusContextAPI,
) -> None:
super().__init__(header, chaindb, chain_context, consensus_context)
self.chaindb = chaindb
self.chain_context = chain_context
self.consensus_context = consensus_context
self._initial_header = header

# If there exists no code at the BEACON_ROOTS_ADDRESS, set the code as defined
# in EIP-4788.
if self.state.get_code(BEACON_ROOTS_ADDRESS) == b"":
self.state.set_code(BEACON_ROOTS_ADDRESS, BEACON_ROOTS_CONTRACT_CODE)

@classmethod
def block_preprocessing(cls, state: StateAPI, header: BlockHeaderAPI) -> None:
super().block_preprocessing(state, header)
Expand Down
1 change: 1 addition & 0 deletions eth/vm/forks/cancun/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
BEACON_ROOTS_ADDRESS = (
b'\x00\x0f=\xf6\xd72\x80~\xf11\x9f\xb7\xb8\xbb\x85"\xd0\xbe\xac\x02'
)
BEACON_ROOTS_CONTRACT_CODE = b"3s\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x14`MW` 6\x14`$W__\xfd[_5\x80\x15`IWb\x00\x1f\xff\x81\x06\x90\x81T\x14`<W__\xfd[b\x00\x1f\xff\x01T_R` _\xf3[__\xfd[b\x00\x1f\xffB\x06B\x81U_5\x90b\x00\x1f\xff\x01U\x00" # noqa: E501

0 comments on commit 41654b0

Please sign in to comment.