ethereum.forks.bogota.fork

Ethereum Specification.

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Entry point for the Ethereum specification.

BASE_FEE_MAX_CHANGE_DENOMINATOR

102
BASE_FEE_MAX_CHANGE_DENOMINATOR = Uint(8)

ELASTICITY_MULTIPLIER

103
ELASTICITY_MULTIPLIER = Uint(2)

EMPTY_OMMER_HASH

104
EMPTY_OMMER_HASH = keccak256(rlp.encode([]))

SYSTEM_ADDRESS

105
SYSTEM_ADDRESS = hex_to_address("0xfffffffffffffffffffffffffffffffffffffffe")

BEACON_ROOTS_ADDRESS

106
BEACON_ROOTS_ADDRESS = hex_to_address(
107
    "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"
108
)

SYSTEM_TRANSACTION_GAS

109
SYSTEM_TRANSACTION_GAS = ExecutionGas(Uint(30000000))

SYSTEM_MAX_SSTORES_PER_CALL

Upper bound on the number of new storage slots a single system call is expected to write.

110
SYSTEM_MAX_SSTORES_PER_CALL = Uint(16)

GWEI_TO_WEI

115
GWEI_TO_WEI = U256(10**9)

WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS

117
WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = hex_to_address(
118
    "0x00000961Ef480Eb55e80D19ad83579A64c007002"
119
)

CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS

120
CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS = hex_to_address(
121
    "0x0000BBdDc7CE488642fb579F8B00f3a590007251"
122
)

BUILDER_DEPOSIT_CONTRACT_ADDRESS

123
BUILDER_DEPOSIT_CONTRACT_ADDRESS = hex_to_address(
124
    "0x0000BFF46984E3725691FA540A8C7589300D8282"
125
)

BUILDER_EXIT_CONTRACT_ADDRESS

126
BUILDER_EXIT_CONTRACT_ADDRESS = hex_to_address(
127
    "0x000064D678505AD48F8CCB093BC65613800E8282"
128
)

HISTORY_STORAGE_ADDRESS

129
HISTORY_STORAGE_ADDRESS = hex_to_address(
130
    "0x0000F90827F1C53a10cb7A02335B175320002935"
131
)

MAX_BLOCK_SIZE

132
MAX_BLOCK_SIZE = 10_485_760

SAFETY_MARGIN

133
SAFETY_MARGIN = 2_097_152

MAX_RLP_BLOCK_SIZE

134
MAX_RLP_BLOCK_SIZE = MAX_BLOCK_SIZE - SAFETY_MARGIN

ChainContext

Chain context needed for block execution.

137
@final
138
@slotted_freezable
139
@dataclass
class ChainContext:

chain_id

Identify the chain for transaction signature recovery.

145
    chain_id: U64

block_hashes

Recent ancestor hashes (up to 256) for the BLOCKHASH opcode.

148
    block_hashes: List[Hash32]

parent_header

Parent header used for header validation and system contracts.

151
    parent_header: Header | PreviousHeader

BlockChain

History and current state of the block chain.

155
@final
156
@dataclass
class BlockChain:

blocks

162
    blocks: List[Block]

state

163
    state: State

chain_id

164
    chain_id: U64

apply_fork

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 <dao-fork> for an example.

Parameters

old : Previous block chain object.

Returns

new : BlockChain Upgraded block chain object for this hard fork.

def apply_fork(​old: BlockChain​) -> BlockChain:
168
    <snip>
187
    return old

get_last_256_block_hashes

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.

Parameters

chain : History and current state.

Returns

recent_block_hashes : List[Hash32] Hashes of the recent 256 blocks in order of increasing block number.

def get_last_256_block_hashes(​chain: BlockChain​) -> List[Hash32]:
191
    <snip>
211
    recent_blocks = chain.blocks[-255:]
212
    if len(recent_blocks) == 0:
213
        return []
214
215
    recent_block_hashes = []
216
217
    for block in recent_blocks:
218
        prev_block_hash = block.header.parent_hash
219
        recent_block_hashes.append(prev_block_hash)
220
221
    # We are computing the hash only for the most recent block and not for
222
    # the rest of the blocks as they have successors which have the hash of
223
    # the current block as parent hash.
224
    most_recent_block_hash = keccak256(rlp.encode(recent_blocks[-1].header))
225
    recent_block_hashes.append(most_recent_block_hash)
226
227
    return recent_block_hashes

state_transition

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.

Parameters

chain : History and current state. block : Block to apply to chain.

def state_transition(​chain: BlockChain, ​​block: Block​) -> None:
231
    <snip>
253
    chain_context = ChainContext(
254
        chain_id=chain.chain_id,
255
        block_hashes=get_last_256_block_hashes(chain),
256
        parent_header=chain.blocks[-1].header,
257
    )
258
259
    block_diff = execute_block(block, chain.state, chain_context)
260
261
    apply_changes_to_state(chain.state, block_diff)
262
    chain.blocks.append(block)
263
    if len(chain.blocks) > 255:
264
        # Real clients have to store more blocks to deal with reorgs, but the
265
        # protocol only requires the last 255
266
        chain.blocks = chain.blocks[-255:]

execute_block

Execute a block and validate the resulting roots against the header.

This method is idempotent.

Parameters

block : Block to validate and execute. pre_state : Pre-execution state provider. chain_context : Chain context that the block may need during execution.

Returns

block_diff : BlockDiff Account, storage, and code changes produced by block execution.

def execute_block(​block: Block, ​​pre_state: State, ​​chain_context: ChainContext​) -> BlockDiff:
274
    <snip>
294
    if len(rlp.encode(block)) > MAX_RLP_BLOCK_SIZE:
295
        raise InvalidBlock("Block rlp size exceeds MAX_RLP_BLOCK_SIZE")
296
297
    parent_header = chain_context.parent_header
298
    validate_header(parent_header, block.header)
299
300
    if block.ommers != ():
301
        raise InvalidBlock
302
303
    block_state = BlockState(pre_state=pre_state)
304
305
    block_env = vm.BlockEnvironment(
306
        chain_id=chain_context.chain_id,
307
        state=block_state,
308
        block_gas_limit=block.header.gas_limit,
309
        block_hashes=chain_context.block_hashes,
310
        coinbase=block.header.coinbase,
311
        number=block.header.number,
312
        base_fee_per_gas=block.header.base_fee_per_gas,
313
        time=block.header.timestamp,
314
        prev_randao=block.header.prev_randao,
315
        excess_blob_gas=block.header.excess_blob_gas,
316
        parent_beacon_block_root=block.header.parent_beacon_block_root,
317
        block_access_list_builder=BlockAccessListBuilder(),
318
        slot_number=block.header.slot_number,
319
    )
320
321
    block_output = apply_body(
322
        block_env=block_env,
323
        transactions=block.transactions,
324
        withdrawals=block.withdrawals,
325
    )
326
    block_diff = extract_block_diff(block_state)
327
    block_state_root = pre_state.compute_state_root(block_diff)
328
    transactions_root = root(block_output.transactions_trie)
329
    receipt_root = root(block_output.receipts_trie)
330
    block_logs_bloom = logs_bloom(block_output.block_logs)
331
    withdrawals_root = root(block_output.withdrawals_trie)
332
    requests_hash = compute_requests_hash(block_output.requests)
333
    computed_block_access_list_hash = hash_block_access_list(
334
        block_output.block_access_list
335
    )
336
337
    block_gas_used = max(
338
        block_output.block_gas_used,
339
        block_output.block_state_gas_used,
340
    )
341
    if block_gas_used != block.header.gas_used:
342
        raise InvalidBlock(f"{block_gas_used} != {block.header.gas_used}")
343
    if transactions_root != block.header.transactions_root:
344
        raise InvalidBlock
345
    if block_state_root != block.header.state_root:
346
        raise InvalidBlock
347
    if receipt_root != block.header.receipt_root:
348
        raise InvalidBlock
349
    if block_logs_bloom != block.header.bloom:
350
        raise InvalidBlock
351
    if withdrawals_root != block.header.withdrawals_root:
352
        raise InvalidBlock
353
    if block_output.blob_gas_used != block.header.blob_gas_used:
354
        raise InvalidBlock
355
    if requests_hash != block.header.requests_hash:
356
        raise InvalidBlock
357
    if computed_block_access_list_hash != block.header.block_access_list_hash:
358
        raise InvalidBlock("Invalid block access list hash")
359
360
    return block_diff

calculate_base_fee_per_gas

Calculates the base fee per gas for the block.

Parameters

block_gas_limit : Gas limit of the block for which the base fee is being calculated. parent_gas_limit : Gas limit of the parent block. parent_gas_used : Gas used in the parent block. parent_base_fee_per_gas : Base fee per gas of the parent block.

Returns

base_fee_per_gas : Uint Base fee per gas for the block.

def calculate_base_fee_per_gas(​block_gas_limit: Uint, ​​parent_gas_limit: Uint, ​​parent_gas_used: Uint, ​​parent_base_fee_per_gas: Uint​) -> Uint:
369
    <snip>
389
    parent_gas_target = parent_gas_limit // ELASTICITY_MULTIPLIER
390
    if not check_gas_limit(block_gas_limit, parent_gas_limit):
391
        raise InvalidBlock
392
393
    if parent_gas_used == parent_gas_target:
394
        expected_base_fee_per_gas = parent_base_fee_per_gas
395
    elif parent_gas_used > parent_gas_target:
396
        gas_used_delta = parent_gas_used - parent_gas_target
397
398
        parent_fee_gas_delta = parent_base_fee_per_gas * gas_used_delta
399
        target_fee_gas_delta = parent_fee_gas_delta // parent_gas_target
400
401
        base_fee_per_gas_delta = max(
402
            target_fee_gas_delta // BASE_FEE_MAX_CHANGE_DENOMINATOR,
403
            Uint(1),
404
        )
405
406
        expected_base_fee_per_gas = (
407
            parent_base_fee_per_gas + base_fee_per_gas_delta
408
        )
409
    else:
410
        gas_used_delta = parent_gas_target - parent_gas_used
411
412
        parent_fee_gas_delta = parent_base_fee_per_gas * gas_used_delta
413
        target_fee_gas_delta = parent_fee_gas_delta // parent_gas_target
414
415
        base_fee_per_gas_delta = (
416
            target_fee_gas_delta // BASE_FEE_MAX_CHANGE_DENOMINATOR
417
        )
418
419
        expected_base_fee_per_gas = (
420
            parent_base_fee_per_gas - base_fee_per_gas_delta
421
        )
422
423
    return Uint(expected_base_fee_per_gas)

validate_header

Verify a block header against its parent.

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 following the parent block's number since it is the next block in the sequence.

Parameters

parent_header : Header of the parent block. header : Header to check for correctness.

def validate_header(​parent_header: Header | PreviousHeader, ​​header: Header​) -> None:
429
    <snip>
447
    if header.number < Uint(1):
448
        raise InvalidBlock
449
450
    excess_blob_gas = calculate_excess_blob_gas(parent_header)
451
    if header.excess_blob_gas != excess_blob_gas:
452
        raise InvalidBlock
453
454
    if header.gas_used > header.gas_limit:
455
        raise InvalidBlock
456
457
    expected_base_fee_per_gas = calculate_base_fee_per_gas(
458
        header.gas_limit,
459
        parent_header.gas_limit,
460
        parent_header.gas_used,
461
        parent_header.base_fee_per_gas,
462
    )
463
    if expected_base_fee_per_gas != header.base_fee_per_gas:
464
        raise InvalidBlock
465
    if header.timestamp <= parent_header.timestamp:
466
        raise InvalidBlock
467
    if header.number != parent_header.number + Uint(1):
468
        raise InvalidBlock
469
    if len(header.extra_data) > 32:
470
        raise InvalidBlock
471
    if header.difficulty != 0:
472
        raise InvalidBlock
473
    if header.nonce != b"\x00\x00\x00\x00\x00\x00\x00\x00":
474
        raise InvalidBlock
475
    if header.ommers_hash != EMPTY_OMMER_HASH:
476
        raise InvalidBlock
477
478
    block_parent_hash = keccak256(rlp.encode(parent_header))
479
    if header.parent_hash != block_parent_hash:
480
        raise InvalidBlock

check_transaction

Admit a raw transaction and build its execution environment.

Recover the sender, statically validate the transaction, and check that it is includable in the block, in that order, so that a transaction invalid in several ways reports the earliest failure.

Parameters

block_env : The block scoped environment. block_output : The block output for the current block. tx : The transaction. index : The index of the current transaction.

Returns

tx_env : The environment for executing the transaction.

Raises

InvalidBlock : If the transaction is not includable. InvalidSignatureError : If the transaction's signature is invalid. InsufficientTransactionGasError : If the transaction does not provide enough gas to cover its intrinsic cost. TransactionGasLimitExceededError : If the transaction's gas limit exceeds TX_MAX_TOTAL_GAS_LIMIT. GasUsedExceedsLimitError : If the gas used by the transaction exceeds the block's gas limit. NonceMismatchError : If the nonce of the transaction is not equal to the sender's nonce. InsufficientBalanceError : If the sender's balance is not enough to pay for the transaction. InvalidSenderError : If the transaction is from an address that does not exist anymore. InsufficientMaxFeePerGasError : If the maximum fee per gas is insufficient for the transaction. InsufficientMaxFeePerBlobGasError : If the maximum fee per blob gas is insufficient for the transaction. BlobGasLimitExceededError : If the blob gas used by the transaction exceeds the block's blob gas limit.

def check_transaction(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​block_output: ethereum.forks.bogota.vm.BlockOutput, ​​tx: Transaction, ​​index: Uint​) -> ethereum.forks.bogota.vm.TransactionEnvironment:
489
    <snip>
540
    assert not isinstance(tx, FrameTransaction)
541
542
    sender = recover_sender(tx)
543
    intrinsic = validate_transaction(tx, sender)
544
    tx_state = TransactionState(parent=block_env.state)
545
546
    # Under the reservoir model any part of the gas limit can end up
547
    # in either dimension, so the whole limit is reserved in both; a
548
    # single transaction's execution gas is capped by EIP-7825.
549
    check_block_gas_capacity(
550
        block_env,
551
        block_output,
552
        min(GasCosts.TX_MAX_GAS_LIMIT, tx.gas),
553
        tx.gas,
554
        calculate_total_blob_gas(tx),
555
    )
556
557
    sender_account = get_account(tx_state, sender)
558
559
    effective_gas_price = calculate_effective_gas_price(
560
        tx, block_env.base_fee_per_gas
561
    )
562
    max_gas_fee = calculate_max_gas_fee(tx, tx.gas)
563
564
    if isinstance(tx, BlobTransaction):
565
        check_max_fee_per_blob_gas(
566
            tx.blob_versioned_hashes,
567
            tx.max_fee_per_blob_gas,
568
            block_env.excess_blob_gas,
569
        )
570
571
        max_gas_fee += Uint(calculate_total_blob_gas(tx)) * Uint(
572
            tx.max_fee_per_blob_gas
573
        )
574
        blob_versioned_hashes = tx.blob_versioned_hashes
575
    else:
576
        blob_versioned_hashes = ()
577
578
    check_nonce(tx, sender_account.nonce)
579
580
    if Uint(sender_account.balance) < max_gas_fee + Uint(tx.value):
581
        raise InsufficientBalanceError("insufficient sender balance")
582
    sender_code = get_code(tx_state, sender_account.code_hash)
583
    if sender_account.code_hash != EMPTY_CODE_HASH and not is_valid_delegation(
584
        sender_code
585
    ):
586
        raise InvalidSenderError("not EOA")
587
588
    # Split the EVM gas into an execution-gas grant (capped by the
589
    # remaining execution-gas budget) and a state gas reservoir.
590
    allocation = allocate_evm_gas(tx.gas, intrinsic)
591
592
    access_list_addresses = set()
593
    access_list_storage_keys = set()
594
    if has_access_list(tx):
595
        for access in tx.access_list:
596
            access_list_addresses.add(access.account)
597
            for slot in access.slots:
598
                access_list_storage_keys.add((access.account, slot))
599
600
    authorizations: Tuple[Authorization, ...] = ()
601
    if isinstance(tx, SetCodeTransaction):
602
        authorizations = tx.authorizations
603
604
    if isinstance(tx.to, Bytes0):
605
        is_create = True
606
        # A creation's frame runs at the address the contract
607
        # deploys to.
608
        recipient = compute_contract_address(sender, sender_account.nonce)
609
    else:
610
        is_create = False
611
        recipient = tx.to
612
613
    accounts_with_paid_writes = {sender}
614
    if is_create or tx.value > U256(0):
615
        accounts_with_paid_writes.add(recipient)
616
617
    return vm.TransactionEnvironment(
618
        origin=sender,
619
        gas_limit=tx.gas,
620
        effective_gas_price=effective_gas_price,
621
        execution_gas_grant=allocation.execution_gas,
622
        state_gas_reservoir=allocation.state_gas_reservoir,
623
        calldata_floor=intrinsic.calldata_floor,
624
        access_list_addresses=access_list_addresses,
625
        access_list_storage_keys=access_list_storage_keys,
626
        accounts_with_paid_writes=accounts_with_paid_writes,
627
        state=tx_state,
628
        blob_versioned_hashes=blob_versioned_hashes,
629
        authorizations=authorizations,
630
        index_in_block=index,
631
        tx_hash=get_transaction_hash(encode_transaction(tx)),
632
        top_level_context=vm.TopLevelContext(
633
            recipient=recipient,
634
            is_create=is_create,
635
            data=tx.data,
636
            value=tx.value,
637
        ),
638
        frame_context=None,
639
    )

make_receipt

Make the receipt for a transaction that was executed.

Parameters

tx : The executed transaction. error : Error in the top level frame of the transaction, if any. cumulative_gas_used : The total gas used so far in the block after the transaction was executed. This is the gas used after refunds. logs : The logs produced by the transaction.

Returns

receipt : The receipt for the transaction.

def make_receipt(​tx: Transaction, ​​error: Optional[EthereumException], ​​cumulative_gas_used: Uint, ​​logs: Tuple[Log, ...]​) -> Bytes | Receipt:
648
    <snip>
669
    receipt = Receipt(
670
        succeeded=error is None,
671
        cumulative_gas_used=cumulative_gas_used,
672
        bloom=logs_bloom(logs),
673
        logs=logs,
674
    )
675
676
    return encode_receipt(tx, receipt)

process_checked_system_transaction

Process a system transaction and raise an error if the contract does not contain code or if the transaction fails.

Parameters

block_env : The block scoped environment. target_address : Address of the contract to call. data : Data to pass to the contract.

Returns

system_tx_output : TransactionOutput The settled output of the system transaction.

def process_checked_system_transaction(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​target_address: Address, ​​data: Bytes​) -> TransactionOutput:
684
    <snip>
703
    # Pre-check that the system contract has code. We use a throwaway
704
    # TransactionState here that is *never* propagated back to BlockState
705
    # (no incorporate_tx_into_block call); the same get_account / get_code
706
    # lookups are performed and properly tracked by
707
    # process_unchecked_system_transaction below, which this function
708
    # always calls. Reading via a TransactionState (rather than directly
709
    # against pre_state) lets us see system contracts deployed earlier in
710
    # the same block — see EIP-7002 and EIP-7251 for this edge case.
711
    untracked_state = TransactionState(parent=block_env.state)
712
    system_contract_code = get_code(
713
        untracked_state,
714
        get_account(untracked_state, target_address).code_hash,
715
    )
716
717
    if len(system_contract_code) == 0:
718
        raise InvalidBlock(
719
            f"System contract address {target_address.hex()} does not "
720
            "contain code"
721
        )
722
723
    system_tx_output = process_unchecked_system_transaction(
724
        block_env,
725
        target_address,
726
        data,
727
    )
728
729
    if system_tx_output.error:
730
        raise InvalidBlock(
731
            f"System contract ({target_address.hex()}) call failed: "
732
            f"{system_tx_output.error}"
733
        )
734
735
    return system_tx_output

process_unchecked_system_transaction

Process a system transaction without checking if the contract contains code or if the transaction fails.

Parameters

block_env : The block scoped environment. target_address : Address of the contract to call. data : Data to pass to the contract.

Returns

system_tx_output : TransactionOutput The settled output of the system transaction.

def process_unchecked_system_transaction(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​target_address: Address, ​​data: Bytes​) -> TransactionOutput:
743
    <snip>
762
    system_tx_state = TransactionState(parent=block_env.state)
763
764
    tx_env = vm.TransactionEnvironment(
765
        origin=SYSTEM_ADDRESS,
766
        gas_limit=SYSTEM_TRANSACTION_GAS,
767
        effective_gas_price=block_env.base_fee_per_gas,
768
        execution_gas_grant=SYSTEM_TRANSACTION_GAS,
769
        state_gas_reservoir=StateGas(
770
            StateGasCosts.STORAGE_SET * SYSTEM_MAX_SSTORES_PER_CALL
771
        ),
772
        calldata_floor=Uint(0),
773
        access_list_addresses=set(),
774
        access_list_storage_keys=set(),
775
        # A system transaction charges no gas, so no write is paid for.
776
        accounts_with_paid_writes=set(),
777
        state=system_tx_state,
778
        blob_versioned_hashes=(),
779
        authorizations=(),
780
        index_in_block=None,
781
        tx_hash=None,
782
        top_level_context=vm.TopLevelContext(
783
            recipient=target_address,
784
            is_create=False,
785
            data=data,
786
            value=U256(0),
787
        ),
788
        frame_context=None,
789
    )
790
791
    system_tx_output = process_top_level(block_env, tx_env)
792
793
    incorporate_tx_into_block(
794
        system_tx_state, block_env.block_access_list_builder
795
    )
796
797
    return system_tx_output

apply_body

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.

Parameters

block_env : The block scoped environment. transactions : Transactions included in the block. withdrawals : Withdrawals to be processed in the current block.

Returns

block_output : The block output for the current block.

def apply_body(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​transactions: Tuple[LegacyTransaction | Bytes, ...], ​​withdrawals: Tuple[Withdrawal, ...]​) -> ethereum.forks.bogota.vm.BlockOutput:
805
    <snip>
830
    block_output = vm.BlockOutput()
831
832
    process_unchecked_system_transaction(
833
        block_env=block_env,
834
        target_address=BEACON_ROOTS_ADDRESS,
835
        data=block_env.parent_beacon_block_root,
836
    )
837
838
    process_unchecked_system_transaction(
839
        block_env=block_env,
840
        target_address=HISTORY_STORAGE_ADDRESS,
841
        data=block_env.block_hashes[-1],  # The parent hash
842
    )
843
844
    for i, tx in enumerate(map(decode_transaction, transactions)):
845
        process_transaction(block_env, block_output, tx, Uint(i))
846
847
    # EIP-7928: Post-execution operations use index N+1
848
    block_env.block_access_list_builder.block_access_index = BlockAccessIndex(
849
        ulen(transactions) + Uint(1)
850
    )
851
852
    process_withdrawals(block_env, block_output, withdrawals)
853
854
    process_general_purpose_requests(
855
        block_env=block_env,
856
        block_output=block_output,
857
    )
858
859
    block_output.block_access_list = build_block_access_list(
860
        block_env.block_access_list_builder, block_env.state
861
    )
862
863
    # Validate block access list gas limit constraint (EIP-7928)
864
    validate_block_access_list_gas_limit(
865
        block_access_list=block_output.block_access_list,
866
        block_gas_limit=block_env.block_gas_limit,
867
    )
868
869
    return block_output

process_general_purpose_requests

Process all the requests in the block.

Parameters

block_env : The execution environment for the Block. block_output : The block output for the current block.

def process_general_purpose_requests(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​block_output: ethereum.forks.bogota.vm.BlockOutput​) -> None:
876
    <snip>
887
    # Requests are to be in ascending order of request type
888
    deposit_requests = parse_deposit_requests(block_output)
889
    requests_from_execution = block_output.requests
890
    if len(deposit_requests) > 0:
891
        requests_from_execution.append(DEPOSIT_REQUEST_TYPE + deposit_requests)
892
893
    system_withdrawal_tx_output = process_checked_system_transaction(
894
        block_env=block_env,
895
        target_address=WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
896
        data=b"",
897
    )
898
899
    if len(system_withdrawal_tx_output.return_data) > 0:
900
        requests_from_execution.append(
901
            WITHDRAWAL_REQUEST_TYPE + system_withdrawal_tx_output.return_data
902
        )
903
904
    system_consolidation_tx_output = process_checked_system_transaction(
905
        block_env=block_env,
906
        target_address=CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS,
907
        data=b"",
908
    )
909
910
    if len(system_consolidation_tx_output.return_data) > 0:
911
        requests_from_execution.append(
912
            CONSOLIDATION_REQUEST_TYPE
913
            + system_consolidation_tx_output.return_data
914
        )
915
916
    system_builder_deposit_tx_output = process_checked_system_transaction(
917
        block_env=block_env,
918
        target_address=BUILDER_DEPOSIT_CONTRACT_ADDRESS,
919
        data=b"",
920
    )
921
922
    if len(system_builder_deposit_tx_output.return_data) > 0:
923
        requests_from_execution.append(
924
            BUILDER_DEPOSIT_REQUEST_TYPE
925
            + system_builder_deposit_tx_output.return_data
926
        )
927
928
    system_builder_exit_tx_output = process_checked_system_transaction(
929
        block_env=block_env,
930
        target_address=BUILDER_EXIT_CONTRACT_ADDRESS,
931
        data=b"",
932
    )
933
934
    if len(system_builder_exit_tx_output.return_data) > 0:
935
        requests_from_execution.append(
936
            BUILDER_EXIT_REQUEST_TYPE
937
            + system_builder_exit_tx_output.return_data
938
        )

update_sender_state

Debit the sender for the transaction's maximum possible gas fee.

Increment the sender's nonce and deduct the largest fee the transaction could incur -- its gas limit priced at the effective gas price, plus the blob fee resolved at inclusion -- up front. Execution later refunds whatever execution gas was not spent.

Parameters

block_env : The block's execution environment. tx_env : The transaction's execution environment. tx : The transaction being charged.

def update_sender_state(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​tx_env: ethereum.forks.bogota.vm.TransactionEnvironment, ​​tx: Transaction​) -> None:
946
    <snip>
964
    tx_state = tx_env.state
965
    sender = tx_env.origin
966
    sender_account = get_account(tx_state, sender)
967
968
    effective_gas_fee = tx_env.gas_limit * tx_env.effective_gas_price
969
    if isinstance(tx, BlobTransaction):
970
        blob_gas_fee = calculate_data_fee(block_env.excess_blob_gas, tx)
971
    else:
972
        blob_gas_fee = Uint(0)
973
974
    increment_nonce(tx_state, sender)
975
976
    sender_balance_after_gas_fee = (
977
        Uint(sender_account.balance) - effective_gas_fee - blob_gas_fee
978
    )
979
    set_account_balance(tx_state, sender, U256(sender_balance_after_gas_fee))

disburse_gas_fees

Refund the payer's unspent gas and pay the priority fee.

Return the gas the transaction did not use to the payer that fronted the maximum fee at inclusion, priced at the effective gas price, and credit the coinbase with the priority fee on the gas that was used.

Parameters

block_env : The block scoped environment. tx_env : The transaction's execution environment. settlement : The settled gas amounts. payer : The account that fronted the maximum gas fee and receives the refund.

def disburse_gas_fees(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​tx_env: ethereum.forks.bogota.vm.TransactionEnvironment, ​​settlement: TransactionGasSettlement, ​​payer: Address​) -> None:
988
    <snip>
1009
    tx_state = tx_env.state
1010
    gas_refund_amount = settlement.gas_left * tx_env.effective_gas_price
1011
1012
    priority_fee_per_gas = (
1013
        tx_env.effective_gas_price - block_env.base_fee_per_gas
1014
    )
1015
    transaction_fee = settlement.gas_used * priority_fee_per_gas
1016
1017
    create_ether(tx_state, payer, U256(gas_refund_amount))
1018
    create_ether(tx_state, block_env.coinbase, U256(transaction_fee))

process_transaction

Execute a transaction against the provided environment.

This function processes the actions needed to execute a transaction. It decrements the sender's account balance 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.

Parameters

block_env : Environment for the Ethereum Virtual Machine. block_output : The block output for the current block. tx : Transaction to execute. index: Index of the transaction in the block.

def process_transaction(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​block_output: ethereum.forks.bogota.vm.BlockOutput, ​​tx: Transaction, ​​index: Uint​) -> None:
1027
    <snip>
1051
    block_env.block_access_list_builder.block_access_index = BlockAccessIndex(
1052
        index + Uint(1)
1053
    )
1054
1055
    trie_set(
1056
        block_output.transactions_trie,
1057
        rlp.encode(index),
1058
        encode_transaction(tx),
1059
    )
1060
1061
    tx_chain_id = chain_id(tx)
1062
    if tx_chain_id is not None and tx_chain_id != block_env.chain_id:
1063
        raise WrongChainIdError(
1064
            expected=block_env.chain_id,
1065
            actual=tx_chain_id,
1066
        )
1067
1068
    if isinstance(tx, FrameTransaction):
1069
        return process_frame_transaction(block_env, block_output, tx, index)
1070
1071
    tx_env = check_transaction(block_env, block_output, tx, index)
1072
1073
    update_sender_state(block_env, tx_env, tx)
1074
1075
    tx_output = process_top_level(block_env, tx_env)
1076
1077
    settlement = settle_transaction_gas(
1078
        tx_env.gas_limit,
1079
        tx_env.calldata_floor,
1080
        tx_output.gas_left,
1081
        tx_output.state_gas_left,
1082
        tx_output.refund_counter,
1083
        tx_output.state_gas_used,
1084
    )
1085
1086
    disburse_gas_fees(block_env, tx_env, settlement, tx_env.origin)
1087
1088
    block_output.block_gas_used += settlement.execution_gas_used
1089
    block_output.block_state_gas_used += settlement.state_gas_used
1090
    block_output.blob_gas_used += calculate_total_blob_gas(tx)
1091
1092
    block_output.cumulative_gas_used += settlement.gas_used
1093
    receipt = make_receipt(
1094
        tx, tx_output.error, block_output.cumulative_gas_used, tx_output.logs
1095
    )
1096
1097
    receipt_key = rlp.encode(Uint(index))
1098
    block_output.receipt_keys += (receipt_key,)
1099
1100
    trie_set(
1101
        block_output.receipts_trie,
1102
        receipt_key,
1103
        receipt,
1104
    )
1105
1106
    block_output.block_logs += tx_output.logs
1107
1108
    for address in tx_output.accounts_to_delete:
1109
        clear_account_preserving_balance(tx_env.state, address)
1110
1111
    incorporate_tx_into_block(
1112
        tx_env.state, block_env.block_access_list_builder
1113
    )

process_withdrawals

Increase the balance of the withdrawing account.

def process_withdrawals(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​block_output: ethereum.forks.bogota.vm.BlockOutput, ​​withdrawals: Tuple[Withdrawal, ...]​) -> None:
1121
    <snip>
1124
    wd_state = TransactionState(parent=block_env.state)
1125
1126
    for i, wd in enumerate(withdrawals):
1127
        trie_set(
1128
            block_output.withdrawals_trie,
1129
            rlp.encode(Uint(i)),
1130
            rlp.encode(wd),
1131
        )
1132
1133
        create_ether(wd_state, wd.address, U256(wd.amount) * GWEI_TO_WEI)
1134
1135
    incorporate_tx_into_block(wd_state, block_env.block_access_list_builder)

check_gas_limit

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 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 less than the predefined 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.

Parameters

gas_limit : Gas limit to validate.

parent_gas_limit : Gas limit of the parent block.

Returns

check : bool True if gas limit constraints are satisfied, False otherwise.

def check_gas_limit(​gas_limit: Uint, ​​parent_gas_limit: Uint​) -> bool:
1139
    <snip>
1167
    max_adjustment_delta = parent_gas_limit // GasCosts.LIMIT_ADJUSTMENT_FACTOR
1168
    if gas_limit >= parent_gas_limit + max_adjustment_delta:
1169
        return False
1170
    if gas_limit <= parent_gas_limit - max_adjustment_delta:
1171
        return False
1172
    if gas_limit < GasCosts.LIMIT_MINIMUM:
1173
        return False
1174
1175
    return True