.. py:module:: ethereum.paris.spec Ethereum Specification ^^^^^^^^^^^^^^^^^^^^^^ .. contents:: Table of Contents :backlinks: none :local: Introduction ------------ Entry point for the Ethereum specification. .. only:: stage1 Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: ethereum.paris.spec.BlockChain Functions ~~~~~~~~~ .. autoapisummary:: :nosignatures: ethereum.paris.spec.apply_fork ethereum.paris.spec.get_last_256_block_hashes ethereum.paris.spec.state_transition ethereum.paris.spec.validate_header ethereum.paris.spec.apply_body ethereum.paris.spec.process_transaction ethereum.paris.spec.validate_transaction ethereum.paris.spec.calculate_intrinsic_cost ethereum.paris.spec.recover_sender ethereum.paris.spec.signing_hash_pre155 ethereum.paris.spec.signing_hash_155 ethereum.paris.spec.signing_hash_2930 ethereum.paris.spec.signing_hash_1559 ethereum.paris.spec.compute_header_hash ethereum.paris.spec.check_gas_limit Attributes ~~~~~~~~~~ .. autoapisummary:: ethereum.paris.spec.BASE_FEE_MAX_CHANGE_DENOMINATOR ethereum.paris.spec.ELASTICITY_MULTIPLIER ethereum.paris.spec.GAS_LIMIT_ADJUSTMENT_FACTOR ethereum.paris.spec.GAS_LIMIT_MINIMUM ethereum.paris.spec.EMPTY_OMMER_HASH Module Details --------------- BASE_FEE_MAX_CHANGE_DENOMINATOR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:data:: BASE_FEE_MAX_CHANGE_DENOMINATOR .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :lines: 63-63 ELASTICITY_MULTIPLIER ~~~~~~~~~~~~~~~~~~~~~ .. py:data:: ELASTICITY_MULTIPLIER .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :lines: 64-64 GAS_LIMIT_ADJUSTMENT_FACTOR ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:data:: GAS_LIMIT_ADJUSTMENT_FACTOR .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :lines: 65-65 GAS_LIMIT_MINIMUM ~~~~~~~~~~~~~~~~~ .. py:data:: GAS_LIMIT_MINIMUM .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :lines: 66-66 EMPTY_OMMER_HASH ~~~~~~~~~~~~~~~~ .. py:data:: EMPTY_OMMER_HASH .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :lines: 67-67 BlockChain ~~~~~~~~~~ History and current state of the block chain. .. class:: BlockChain .. py:attribute:: blocks :annotation: :List[ethereum.paris.eth_types.Block] .. py:attribute:: state :annotation: :ethereum.paris.state.State .. py:attribute:: chain_id :annotation: :ethereum.base_types.Uint64 apply_fork ~~~~~~~~~~ .. function:: apply_fork(old: BlockChain) -> BlockChain :noindexentry: Transforms the state from the previous hard fork (`old`) into the block chain object for this hard fork and returns it. When forks need to implement an irregular state transition, this function is used to handle the irregularity. See the :ref:`DAO Fork ` for an example. :param old: Previous block chain object. :returns: **new** -- Upgraded block chain object for this hard fork. :rtype: `BlockChain` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: apply_fork get_last_256_block_hashes ~~~~~~~~~~~~~~~~~~~~~~~~~ .. function:: get_last_256_block_hashes(chain: BlockChain) -> List[ethereum.paris.eth_types.Hash32] :noindexentry: Obtain the list of hashes of the previous 256 blocks in order of increasing block number. This function will return less hashes for the first 256 blocks. The ``BLOCKHASH`` opcode needs to access the latest hashes on the chain, therefore this function retrieves them. :param chain: History and current state. :returns: **recent_block_hashes** -- Hashes of the recent 256 blocks in order of increasing block number. :rtype: `List[Hash32]` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: get_last_256_block_hashes state_transition ~~~~~~~~~~~~~~~~ .. function:: state_transition(chain: BlockChain, block: ethereum.paris.eth_types.Block) -> None :noindexentry: Attempts to apply a block to an existing block chain. All parts of the block's contents need to be verified before being added to the chain. Blocks are verified by ensuring that the contents of the block make logical sense with the contents of the parent block. The information in the block's header must also match the corresponding information in the block. To implement Ethereum, in theory clients are only required to store the most recent 255 blocks of the chain since as far as execution is concerned, only those blocks are accessed. Practically, however, clients should store more blocks to handle reorgs. :param chain: History and current state. :param block: Block to apply to `chain`. .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: state_transition validate_header ~~~~~~~~~~~~~~~ .. function:: validate_header(header: ethereum.paris.eth_types.Header, parent_header: ethereum.paris.eth_types.Header) -> None :noindexentry: Verifies a block header. In order to consider a block's header valid, the logic for the quantities in the header should match the logic for the block itself. For example the header timestamp should be greater than the block's parent timestamp because the block was created *after* the parent block. Additionally, the block's number should be directly folowing the parent block's number since it is the next block in the sequence. :param header: Header to check for correctness. :param parent_header: Parent Header of the header to check for correctness .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: validate_header apply_body ~~~~~~~~~~ .. function:: apply_body(state: ethereum.paris.state.State, block_hashes: List[ethereum.paris.eth_types.Hash32], coinbase: ethereum.paris.eth_types.Address, block_number: ethereum.base_types.Uint, base_fee_per_gas: ethereum.base_types.Uint, block_gas_limit: ethereum.base_types.Uint, block_time: ethereum.base_types.U256, prev_randao: ethereum.base_types.Bytes32, transactions: Tuple[Union[ethereum.paris.eth_types.LegacyTransaction, ethereum.base_types.Bytes], Ellipsis], chain_id: ethereum.base_types.Uint64) -> Tuple[ethereum.base_types.Uint, ethereum.paris.eth_types.Root, ethereum.paris.eth_types.Root, ethereum.paris.eth_types.Bloom, ethereum.paris.state.State] :noindexentry: Executes a block. Many of the contents of a block are stored in data structures called tries. There is a transactions trie which is similar to a ledger of the transactions stored in the current block. There is also a receipts trie which stores the results of executing a transaction, like the post state and gas used. This function creates and executes the block that is to be added to the chain. :param state: Current account state. :param block_hashes: List of hashes of the previous 256 blocks in the order of increasing block number. :param coinbase: Address of account which receives block reward and transaction fees. :param block_number: Position of the block within the chain. :param base_fee_per_gas: Base fee per gas of within the block. :param block_gas_limit: Initial amount of gas available for execution in this block. :param block_time: Time the block was produced, measured in seconds since the epoch. :param prev_randao: The previous randao from the beacon chain. :param transactions: Transactions included in the block. :param ommers: Headers of ancestor blocks which are not direct parents (formerly uncles.) :param chain_id: ID of the executing chain. :returns: * **gas_available** (`ethereum.base_types.Uint`) -- Remaining gas after all transactions have been executed. * **transactions_root** (`ethereum.eth_types.Root`) -- Trie root of all the transactions in the block. * **receipt_root** (`ethereum.eth_types.Root`) -- Trie root of all the receipts in the block. * **block_logs_bloom** (`Bloom`) -- Logs bloom of all the logs included in all the transactions of the block. * **state** (`ethereum.eth_types.State`) -- State after all transactions have been executed. .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: apply_body process_transaction ~~~~~~~~~~~~~~~~~~~ .. function:: process_transaction(env: ethereum.paris.vm.Environment, tx: ethereum.paris.eth_types.Transaction) -> Tuple[ethereum.base_types.U256, Tuple[ethereum.paris.eth_types.Log, Ellipsis], bool] :noindexentry: Execute a transaction against the provided environment. This function processes the actions needed to execute a transaction. It decrements the sender's account after calculating the gas fee and refunds them the proper amount after execution. Calling contracts, deploying code, and incrementing nonces are all examples of actions that happen within this function or from a call made within this function. Accounts that are marked for deletion are processed and destroyed after execution. :param env: Environment for the Ethereum Virtual Machine. :param tx: Transaction to execute. :returns: * **gas_left** (`ethereum.base_types.U256`) -- Remaining gas after execution. * **logs** (`Tuple[ethereum.eth_types.Log, ...]`) -- Logs generated during execution. .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: process_transaction validate_transaction ~~~~~~~~~~~~~~~~~~~~ .. function:: validate_transaction(tx: ethereum.paris.eth_types.Transaction) -> bool :noindexentry: Verifies a transaction. The gas in a transaction gets used to pay for the intrinsic cost of operations, therefore if there is insufficient gas then it would not be possible to execute a transaction and it will be declared invalid. Additionally, the nonce of a transaction must not equal or exceed the limit defined in `EIP-2681 `_. In practice, defining the limit as ``2**64-1`` has no impact because sending ``2**64-1`` transactions is improbable. It's not strictly impossible though, ``2**64-1`` transactions is the entire capacity of the Ethereum blockchain at 2022 gas limits for a little over 22 years. :param tx: Transaction to validate. :returns: **verified** -- True if the transaction can be executed, or False otherwise. :rtype: `bool` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: validate_transaction calculate_intrinsic_cost ~~~~~~~~~~~~~~~~~~~~~~~~ .. function:: calculate_intrinsic_cost(tx: ethereum.paris.eth_types.Transaction) -> ethereum.base_types.Uint :noindexentry: Calculates the gas that is charged before execution is started. The intrinsic cost of the transaction is charged before execution has begun. Functions/operations in the EVM cost money to execute so this intrinsic cost is for the operations that need to be paid for as part of the transaction. Data transfer, for example, is part of this intrinsic cost. It costs ether to send data over the wire and that ether is accounted for in the intrinsic cost calculated in this function. This intrinsic cost must be calculated and paid for before execution in order for all operations to be implemented. :param tx: Transaction to compute the intrinsic cost of. :returns: **verified** -- The intrinsic cost of the transaction. :rtype: `ethereum.base_types.Uint` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: calculate_intrinsic_cost recover_sender ~~~~~~~~~~~~~~ .. function:: recover_sender(chain_id: ethereum.base_types.Uint64, tx: ethereum.paris.eth_types.Transaction) -> ethereum.paris.eth_types.Address :noindexentry: Extracts the sender address from a transaction. The v, r, and s values are the three parts that make up the signature of a transaction. In order to recover the sender of a transaction the two components needed are the signature (``v``, ``r``, and ``s``) and the signing hash of the transaction. The sender's public key can be obtained with these two values and therefore the sender address can be retrieved. :param tx: Transaction of interest. :param chain_id: ID of the executing chain. :returns: **sender** -- The address of the account that signed the transaction. :rtype: `ethereum.eth_types.Address` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: recover_sender signing_hash_pre155 ~~~~~~~~~~~~~~~~~~~ .. function:: signing_hash_pre155(tx: ethereum.paris.eth_types.LegacyTransaction) -> ethereum.paris.eth_types.Hash32 :noindexentry: Compute the hash of a transaction used in a legacy (pre EIP 155) signature. :param tx: Transaction of interest. :returns: **hash** -- Hash of the transaction. :rtype: `ethereum.eth_types.Hash32` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: signing_hash_pre155 signing_hash_155 ~~~~~~~~~~~~~~~~ .. function:: signing_hash_155(tx: ethereum.paris.eth_types.LegacyTransaction) -> ethereum.paris.eth_types.Hash32 :noindexentry: Compute the hash of a transaction used in a EIP 155 signature. :param tx: Transaction of interest. :returns: **hash** -- Hash of the transaction. :rtype: `ethereum.eth_types.Hash32` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: signing_hash_155 signing_hash_2930 ~~~~~~~~~~~~~~~~~ .. function:: signing_hash_2930(tx: ethereum.paris.eth_types.AccessListTransaction) -> ethereum.paris.eth_types.Hash32 :noindexentry: Compute the hash of a transaction used in a EIP 2930 signature. :param tx: Transaction of interest. :returns: **hash** -- Hash of the transaction. :rtype: `ethereum.eth_types.Hash32` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: signing_hash_2930 signing_hash_1559 ~~~~~~~~~~~~~~~~~ .. function:: signing_hash_1559(tx: ethereum.paris.eth_types.FeeMarketTransaction) -> ethereum.paris.eth_types.Hash32 :noindexentry: Compute the hash of a transaction used in a EIP 1559 signature. :param tx: Transaction of interest. :returns: **hash** -- Hash of the transaction. :rtype: `eth1spec.eth_types.Hash32` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: signing_hash_1559 compute_header_hash ~~~~~~~~~~~~~~~~~~~ .. function:: compute_header_hash(header: ethereum.paris.eth_types.Header) -> ethereum.paris.eth_types.Hash32 :noindexentry: Computes the hash of a block header. The header hash of a block is the canonical hash that is used to refer to a specific block and completely distinguishes a block from another. ``keccak256`` is a function that produces a 256 bit hash of any input. It also takes in any number of bytes as an input and produces a single hash for them. A hash is a completely unique output for a single input. So an input corresponds to one unique hash that can be used to identify the input exactly. Prior to using the ``keccak256`` hash function, the header must be encoded using the Recursive-Length Prefix. See :ref:`rlp`. RLP encoding the header converts it into a space-efficient format that allows for easy transfer of data between nodes. The purpose of RLP is to encode arbitrarily nested arrays of binary data, and RLP is the primary encoding method used to serialize objects in Ethereum's execution layer. The only purpose of RLP is to encode structure; encoding specific data types (e.g. strings, floats) is left up to higher-order protocols. :param header: Header of interest. :returns: **hash** -- Hash of the header. :rtype: `ethereum.eth_types.Hash32` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: compute_header_hash check_gas_limit ~~~~~~~~~~~~~~~ .. function:: check_gas_limit(gas_limit: ethereum.base_types.Uint, parent_gas_limit: ethereum.base_types.Uint) -> bool :noindexentry: Validates the gas limit for a block. The bounds of the gas limit, ``max_adjustment_delta``, is set as the quotient of the parent block's gas limit and the ``GAS_LIMIT_ADJUSTMENT_FACTOR``. Therefore, if the gas limit that is passed through as a parameter is greater than or equal to the *sum* of the parent's gas and the adjustment delta then the limit for gas is too high and fails this function's check. Similarly, if the limit is less than or equal to the *difference* of the parent's gas and the adjustment delta *or* the predefined ``GAS_LIMIT_MINIMUM`` then this function's check fails because the gas limit doesn't allow for a sufficient or reasonable amount of gas to be used on a block. :param gas_limit: Gas limit to validate. :param parent_gas_limit: Gas limit of the parent block. :returns: **check** -- True if gas limit constraints are satisfied, False otherwise. :rtype: `bool` .. undocinclude:: /../src/ethereum/paris/spec.py :language: python :pyobject: check_gas_limit