ethereum.forks.bogota.frame_processing

Frame transaction processing.

The block-level flow for EIP-8141 frame transactions, separate from the regular flow in fork.py from admission onwards: a frame transaction has no single top-level call to dispatch — it executes a list of frames — and no upfront sender payment: the sender's nonce increment and the collection of the transaction's maximum cost are effects of the APPROVE instruction, during execution.

check_frame_transaction

Admit a raw frame transaction and build its execution environment.

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.

Unlike the regular flow, the sender needs no recovery — it is an explicit field, authenticated by the signature entries during static validation — and no balance or EOA check: payment is collected from the payer during execution, when a frame APPROVEs it.

Parameters

block_env : The block scoped environment. block_output : The block output for the current block. tx : The frame 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 a signature entry is cryptographically invalid. InvalidFrameError : If the frames or signature entries violate a structural constraint. TransactionGasLimitExceededError : If the derived gas limit exceeds the maximum allowed for a transaction. 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. InsufficientMaxFeeError : If the maximum fee does not cover the transaction's worst-case base fee charge. BlobGasLimitExceededError : If the blob gas used by the transaction exceeds the block's blob gas limit.

def check_frame_transaction(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​block_output: ethereum.forks.bogota.vm.BlockOutput, ​​tx: FrameTransaction, ​​index: Uint​) -> ethereum.forks.bogota.vm.TransactionEnvironment:
59
    <snip>
112
    validation = validate_frame_transaction(tx)
113
    tx_state = TransactionState(parent=block_env.state)
114
115
    # The frames' total gas budget in each dimension. The execution
116
    # total becomes the grant the frames draw from; frame transactions
117
    # declare their state gas budgets explicitly per frame, so the
118
    # reservoir model of the regular flow does not apply and the
119
    # reservoir is empty.
120
    execution_gas_grant = Uint(0)
121
    state_reservation = Uint(0)
122
    for frame in tx.frames:
123
        execution_gas_grant += Uint(frame.gas_limits.execution)
124
        state_reservation += Uint(frame.gas_limits.state)
125
126
    # Explicit budgets make the block reservations exact per
127
    # dimension; the execution reservation carries the calldata floor,
128
    # which binds the execution dimension.
129
    execution_reservation = max(
130
        Uint(validation.intrinsic.execution) + execution_gas_grant,
131
        Uint(validation.intrinsic.calldata_floor),
132
    )
133
134
    check_block_gas_capacity(
135
        block_env,
136
        block_output,
137
        execution_reservation,
138
        state_reservation,
139
        calculate_total_blob_gas(tx),
140
    )
141
142
    sender_account = get_account(tx_state, tx.sender)
143
144
    max_cost, effective_gas_price = calculate_frame_transaction_fees(
145
        tx, validation.max_gas, block_env
146
    )
147
148
    check_nonce(tx, sender_account.nonce)
149
150
    return vm.TransactionEnvironment(
151
        origin=tx.sender,
152
        gas_limit=validation.max_gas,
153
        effective_gas_price=effective_gas_price,
154
        execution_gas_grant=ExecutionGas(execution_gas_grant),
155
        state_gas_reservoir=StateGas(Uint(0)),
156
        calldata_floor=validation.intrinsic.calldata_floor,
157
        access_list_addresses=set(),
158
        access_list_storage_keys=set(),
159
        accounts_with_paid_writes={tx.sender},
160
        state=tx_state,
161
        blob_versioned_hashes=tx.blob_versioned_hashes,
162
        authorizations=(),
163
        index_in_block=index,
164
        tx_hash=get_transaction_hash(encode_transaction(tx)),
165
        top_level_context=None,
166
        frame_context=vm.FrameContext(
167
            tx=tx,
168
            signature_hash=validation.signature_hash,
169
            resolved_signers=validation.resolved_signers,
170
            standard_gas_limit=validation.standard_gas_limit,
171
            max_cost=max_cost,
172
            current_frame_index=Uint(0),
173
            frame_receipts=[],
174
            payer=None,
175
            sender_approved=False,
176
            state_gas_left=StateGas(Uint(0)),
177
            outstanding_charge_owners={},
178
        ),
179
    )

calculate_frame_transaction_fees

Check a frame transaction's fee budget against the block's base fees and derive what the payer escrows.

The max_fee budget covers the execution, state, and blob gas together. It must cover the worst case at the block's base fees, max_gas at the base fee plus the blob gas at the blob base fee, or an InsufficientMaxFeeError is raised. The payer escrows that worst case plus the largest tip the rest of the budget allows.

Return the escrow, max_cost, and the price per gas that GASPRICE reports: the base fee plus the tip per gas, capped by what the rest of the budget can pay for every unit of max_gas. The payer pays at least this price per unit of gas used, since unused gas can back a larger tip at settlement.

def calculate_frame_transaction_fees(​tx: FrameTransaction, ​​max_gas: Uint, ​​block_env: ethereum.forks.bogota.vm.BlockEnvironment​) -> Tuple[Uint, Uint]:
187
    <snip>
203
    blob_fee = Uint(calculate_total_blob_gas(tx)) * calculate_blob_gas_price(
204
        block_env.excess_blob_gas
205
    )
206
    required_max_fee = max_gas * block_env.base_fee_per_gas + blob_fee
207
    if tx.fees.max_fee < required_max_fee:
208
        raise InsufficientMaxFeeError(
209
            f"max fee {tx.fees.max_fee} below the required {required_max_fee}"
210
        )
211
212
    budget_left = tx.fees.max_fee - required_max_fee
213
    max_priority_fee = min(
214
        tx.fees.max_priority_fee_per_gas * max_gas, budget_left
215
    )
216
    max_cost = required_max_fee + max_priority_fee
217
    gas_price = block_env.base_fee_per_gas + max_priority_fee // max_gas
218
    return max_cost, gas_price

disburse_frame_gas_fees

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

At APPROVE the payer escrowed the transaction's max_cost. The gas used at the base fee, plus the blob gas at the blob base fee, is burned. The coinbase receives the priority fee per gas on the gas used, capped by what the escrow holds after the burn, and the payer gets back the rest.

def disburse_frame_gas_fees(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​tx_env: ethereum.forks.bogota.vm.TransactionEnvironment, ​​gas_used: Uint​) -> None:
226
    <snip>
235
    frame_context = tx_env.frame_context
236
    assert frame_context is not None
237
    # `process_frames` invalidates the transaction unless a frame
238
    # approved payment.
239
    payer = frame_context.payer
240
    assert payer is not None
241
242
    tx = frame_context.tx
243
    blob_fee = Uint(calculate_total_blob_gas(tx)) * calculate_blob_gas_price(
244
        block_env.excess_blob_gas
245
    )
246
    base_fee_paid = gas_used * block_env.base_fee_per_gas + blob_fee
247
    priority_fee_paid = min(
248
        tx.fees.max_priority_fee_per_gas * gas_used,
249
        frame_context.max_cost - base_fee_paid,
250
    )
251
    payer_refund = frame_context.max_cost - base_fee_paid - priority_fee_paid
252
253
    create_ether(tx_env.state, payer, U256(payer_refund))
254
    create_ether(tx_env.state, block_env.coinbase, U256(priority_fee_paid))

make_frame_receipt

Make the receipt for a frame transaction that was executed.

Unlike a regular receipt there is no transaction-level status and no bloom filter: outcomes are reported per frame, and the frames' logs reach the block's log bloom through the block accumulator.

def make_frame_receipt(​tx: FrameTransaction, ​​payer: Address, ​​cumulative_gas_used: Uint, ​​frame_receipts: Tuple[FrameReceipt, ...]​) -> Bytes | Receipt:
263
    <snip>
270
    receipt = FrameTransactionReceipt(
271
        cumulative_gas_used=cumulative_gas_used,
272
        payer=payer,
273
        frame_receipts=frame_receipts,
274
    )
275
276
    return encode_receipt(tx, receipt)

process_frame_transaction

Execute a frame transaction against the provided environment.

Admit the transaction, execute its frames in order, settle the gas, disburse the fees, and write the frame transaction receipt.

def process_frame_transaction(​block_env: ethereum.forks.bogota.vm.BlockEnvironment, ​​block_output: ethereum.forks.bogota.vm.BlockOutput, ​​tx: FrameTransaction, ​​index: Uint​) -> None:
285
    <snip>
291
    tx_env = check_frame_transaction(block_env, block_output, tx, index)
292
293
    tx_output = process_frames(block_env, tx_env)
294
295
    frame_context = tx_env.frame_context
296
    assert frame_context is not None
297
    # `process_frames` invalidates the transaction unless a frame
298
    # approved payment.
299
    payer = frame_context.payer
300
    assert payer is not None
301
302
    tx_unused_gas = Uint(tx_output.gas_left) + Uint(tx_output.state_gas_left)
303
    settlement = settle_frame_transaction_gas(
304
        frame_context.standard_gas_limit,
305
        tx_env.calldata_floor,
306
        tx_unused_gas,
307
        tx_output.refund_counter,
308
        StateGas(Uint(tx_output.state_gas_used)),
309
    )
310
311
    disburse_frame_gas_fees(block_env, tx_env, settlement.gas_used)
312
313
    block_output.block_gas_used += settlement.execution_gas_used
314
    block_output.block_state_gas_used += settlement.state_gas_used
315
    block_output.blob_gas_used += calculate_total_blob_gas(tx)
316
317
    block_output.cumulative_gas_used += settlement.gas_used
318
    receipt = make_frame_receipt(
319
        tx,
320
        payer,
321
        block_output.cumulative_gas_used,
322
        tuple(frame_context.frame_receipts),
323
    )
324
325
    receipt_key = rlp.encode(Uint(index))
326
    block_output.receipt_keys += (receipt_key,)
327
328
    trie_set(
329
        block_output.receipts_trie,
330
        receipt_key,
331
        receipt,
332
    )
333
334
    block_output.block_logs += tx_output.logs
335
336
    for address in tx_output.accounts_to_delete:
337
        clear_account_preserving_balance(tx_env.state, address)
338
339
    incorporate_tx_into_block(
340
        tx_env.state, block_env.block_access_list_builder
341
    )