From c4a5dc5bfcdbd37697afbe06c2599c0117c6c81f Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 8 Nov 2024 17:01:17 -0700 Subject: [PATCH] Prague initial commit --- eth/vm/forks/prague/__init__.py | 50 +++++++++++++++++++++++++++++ eth/vm/forks/prague/blocks.py | 39 ++++++++++++++++++++++ eth/vm/forks/prague/computation.py | 14 ++++++++ eth/vm/forks/prague/constants.py | 0 eth/vm/forks/prague/headers.py | 26 +++++++++++++++ eth/vm/forks/prague/logic.py | 0 eth/vm/forks/prague/opcodes.py | 25 +++++++++++++++ eth/vm/forks/prague/receipts.py | 7 ++++ eth/vm/forks/prague/state.py | 14 ++++++++ eth/vm/forks/prague/transactions.py | 47 +++++++++++++++++++++++++++ 10 files changed, 222 insertions(+) create mode 100644 eth/vm/forks/prague/__init__.py create mode 100644 eth/vm/forks/prague/blocks.py create mode 100644 eth/vm/forks/prague/computation.py create mode 100644 eth/vm/forks/prague/constants.py create mode 100644 eth/vm/forks/prague/headers.py create mode 100644 eth/vm/forks/prague/logic.py create mode 100644 eth/vm/forks/prague/opcodes.py create mode 100644 eth/vm/forks/prague/receipts.py create mode 100644 eth/vm/forks/prague/state.py create mode 100644 eth/vm/forks/prague/transactions.py diff --git a/eth/vm/forks/prague/__init__.py b/eth/vm/forks/prague/__init__.py new file mode 100644 index 0000000000..2c555b7b19 --- /dev/null +++ b/eth/vm/forks/prague/__init__.py @@ -0,0 +1,50 @@ +from typing import ( + Type, +) + +from eth._utils.db import ( + get_block_header_by_hash, +) +from eth.abc import ( + BlockAPI, + BlockHeaderAPI, + StateAPI, + TransactionFieldsAPI, +) +from eth.rlp.blocks import ( + BaseBlock, +) +from eth.vm.forks.cancun import ( + CancunVM, +) +from eth.vm.state import ( + BaseState, +) +from eth_utils import ( + ValidationError, + to_int, +) + +from .blocks import ( + PragueBlock, +) +from .headers import ( + create_prague_header_from_parent, +) +from .state import ( + PragueState, +) + + +class PragueVM(CancunVM): + # fork name + fork = "prague" + + # classes + block_class: Type[BaseBlock] = PragueBlock + _state_class: Type[BaseState] = PragueState + + # methods + create_header_from_parent = staticmethod( # type: ignore + create_prague_header_from_parent() + ) diff --git a/eth/vm/forks/prague/blocks.py b/eth/vm/forks/prague/blocks.py new file mode 100644 index 0000000000..ba1aa4ce66 --- /dev/null +++ b/eth/vm/forks/prague/blocks.py @@ -0,0 +1,39 @@ +from typing import ( + Type, +) + +from rlp.sedes import ( + CountableList, +) + +from eth.abc import ( + ReceiptBuilderAPI, + TransactionBuilderAPI, +) +from eth.rlp.headers import ( + BlockHeader, +) +from eth.vm.forks.cancun.block import ( + CancunBlock, +) + +from ..shanghai.withdrawals import ( + Withdrawal, +) +from .receipts import ( + PragueReceiptBuilder, +) +from .transactions import ( + PragueTransactionBuilder, +) + + +class PragueBlock(CancunBlock): + transaction_builder: Type[TransactionBuilderAPI] = PragueTransactionBuilder + receipt_builder: Type[ReceiptBuilderAPI] = PragueReceiptBuilder + fields = [ + ("header", BlockHeader), + ("transactions", CountableList(transaction_builder)), + ("uncles", CountableList(None, max_length=0)), + ("withdrawals", CountableList(Withdrawal)), + ] diff --git a/eth/vm/forks/prague/computation.py b/eth/vm/forks/prague/computation.py new file mode 100644 index 0000000000..055a35cd44 --- /dev/null +++ b/eth/vm/forks/prague/computation.py @@ -0,0 +1,14 @@ +from eth.vm.forks.cancun.computation import ( + CancunComputation, +) +from eth.vm.forks.prague.opcodes import ( + PRAGUE_OPCODES, +) + + +class PragueComputation(CancunComputation): + """ + A class for all execution computations in the ``Prague`` hard fork + """ + + opcodes = PRAGUE_OPCODES diff --git a/eth/vm/forks/prague/constants.py b/eth/vm/forks/prague/constants.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/eth/vm/forks/prague/headers.py b/eth/vm/forks/prague/headers.py new file mode 100644 index 0000000000..831e4a9260 --- /dev/null +++ b/eth/vm/forks/prague/headers.py @@ -0,0 +1,26 @@ +from typing import ( + Any, + Dict, + Optional, +) + +from toolz import ( + curry, +) + +from eth.abc import ( + BlockHeaderAPI, +) +from eth.rlp.headers import ( + BlockHeader, +) + + +@curry +def create_prague_header_from_parent( + parent_header: Optional[BlockHeaderAPI], + **header_params: Any, +) -> BlockHeaderAPI: + all_fields: Dict[Any, Any] = {} + + return BlockHeader(**all_fields) diff --git a/eth/vm/forks/prague/logic.py b/eth/vm/forks/prague/logic.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/eth/vm/forks/prague/opcodes.py b/eth/vm/forks/prague/opcodes.py new file mode 100644 index 0000000000..1e92e21364 --- /dev/null +++ b/eth/vm/forks/prague/opcodes.py @@ -0,0 +1,25 @@ +import copy +from typing import ( + Dict, +) + +from eth_utils.toolz import ( + merge, +) + +from eth.abc import ( + OpcodeAPI, +) +from eth.vm.forks.cancun.opcodes import ( + CANCUN_OPCODES, +) + +UPDATED_OPCODES: Dict[int, OpcodeAPI] = {} + +NEW_OPCODES: Dict[int, OpcodeAPI] = {} + +PRAGUE_OPCODES: Dict[int, OpcodeAPI] = merge( + copy.deepcopy(CANCUN_OPCODES), + UPDATED_OPCODES, + NEW_OPCODES, +) diff --git a/eth/vm/forks/prague/receipts.py b/eth/vm/forks/prague/receipts.py new file mode 100644 index 0000000000..9240f233ab --- /dev/null +++ b/eth/vm/forks/prague/receipts.py @@ -0,0 +1,7 @@ +from eth.vm.forks.cancun.receipts import ( + CancunReceiptBuilder, +) + + +class PragueReceiptBuilder(CancunReceiptBuilder): + pass diff --git a/eth/vm/forks/prague/state.py b/eth/vm/forks/prague/state.py new file mode 100644 index 0000000000..06492837b8 --- /dev/null +++ b/eth/vm/forks/prague/state.py @@ -0,0 +1,14 @@ +from eth.vm.forks.cancun import ( + CancunState, +) +from eth.vm.forks.cancun.state import ( + CancunTransactionExecutor, +) + + +class PragueTransactionExecutor(CancunTransactionExecutor): + pass + + +class PragueState(CancunState): + pass diff --git a/eth/vm/forks/prague/transactions.py b/eth/vm/forks/prague/transactions.py new file mode 100644 index 0000000000..cd26683909 --- /dev/null +++ b/eth/vm/forks/prague/transactions.py @@ -0,0 +1,47 @@ +from abc import ( + ABC, +) +from typing import ( + Type, +) + +import rlp + +from eth.abc import ( + SignedTransactionAPI, +) +from eth.rlp.transactions import ( + SignedTransactionMethods, +) +from eth.vm.forks.berlin.transactions import ( + TypedTransaction, +) +from eth.vm.forks.cancun.transactions import ( + CancunLegacyTransaction, + CancunTransactionBuilder, + CancunUnsignedLegacyTransaction, +) + + +class PragueLegacyTransaction(CancunLegacyTransaction, ABC): + pass + + +class PragueUnsignedLegacyTransaction(CancunUnsignedLegacyTransaction): + pass + + +class SetCodeTransaction( + rlp.Serializable, SignedTransactionMethods, SignedTransactionAPI +): + pass + + +class PragueTypedTransaction(TypedTransaction): + pass + + +class PragueTransactionBuilder(CancunTransactionBuilder): + legacy_signed = PragueLegacyTransaction + legacy_unsigned = PragueUnsignedLegacyTransaction + typed_transaction: Type[TypedTransaction] = PragueTypedTransaction