ethereum.forks.bogota.transactions.frame_transaction

Frame transactions, the transaction type introduced in EIP-8141.

A frame transaction expresses validity conditions, gas payment, and execution as an explicit list of Frames, each a unit of execution with its own mode, target, and gas limit. Signatures are carried alongside the frames in a list of FrameSignature entries that the protocol validates before any frame executes.

MAX_FRAMES_PER_TX

48
MAX_FRAMES_PER_TX: Final[Uint] = Uint(64)

EXPIRY_VERIFIER

56
EXPIRY_VERIFIER: Final[Address] = Address(
57
    bytes.fromhex("81413f0cf12e9b6a49b1d0439e081c577d57ffff")
58
)

EXPIRY_DATA_LENGTH

80
EXPIRY_DATA_LENGTH: Final[int] = 8

FrameMode

Indicates the purpose of a Frame.

The members below are the only valid modes. The strict boundary rejects any other value as the enum is constructed — notably while decoding a transaction — so a frame with an undefined mode never decodes and no separate validity check is required. An EIP that extends frame transactions with a new mode adds a member here; it does not change how the existing members are checked.

87
@final
class FrameMode:

DEFAULT

Execute frame as FRAME_ENTRY_POINT.

102
    DEFAULT = Uint(0)

VERIFY

Identify frame as transaction validation.

109
    VERIFY = Uint(1)

SENDER

Execute frame as sender.

114
    SENDER = Uint(2)

FrameFlag

Frame or mode features.

Each member represents a single bit, and any combination of the bits defined here is a valid set of flags. The strict boundary rejects values with any other bit set as the flag is constructed — notably while decoding a transaction — so a frame carrying a reserved flag bit never decodes and no separate validity check is required.

122
@final
class FrameFlag:

APPROVE_PAYMENT

Frame has permission to approve payment.

134
    APPROVE_PAYMENT = Uint(1)

APPROVE_EXECUTION

Frame has permission to approve execution.

141
    APPROVE_EXECUTION = Uint(2)

ATOMIC_BATCH

Frame belongs to an atomic batch.

All frames within an atomic batch either all succeed or are all reverted.

148
    ATOMIC_BATCH = Uint(4)

APPROVE_SCOPE_MASK

158
APPROVE_SCOPE_MASK: Final[FrameFlag] = (
159
    FrameFlag.APPROVE_PAYMENT | FrameFlag.APPROVE_EXECUTION
160
)

FrameStatus

Outcome of a completed frame, as reported in the frame transaction's receipt and exposed by the FRAMEPARAM opcode.

Statuses exist only for completed frames — reading the status of the current or a future frame is an exceptional halt — so there is no pending member. A frame that executed inside a later-unrolled atomic batch keeps its execution status; SKIPPED marks only frames that never ran.

166
@final
class FrameStatus:

FAILURE

The frame executed and reverted or exceptionally halted.

179
    FAILURE = Uint(0)

SUCCESS

The frame executed and completed successfully.

184
    SUCCESS = Uint(1)

SKIPPED

The frame never executed because an earlier frame of its atomic batch failed.

189
    SKIPPED = Uint(2)

GasLimits

The gas budgets of a Frame, one per gas dimension.

The two budgets are independent: neither dimension can fund charges of the other, and unused gas in one is not available to the other.

Corresponds to the limits list of the frame object in EIP-8141.

196
@final
197
@slotted_freezable
198
@dataclass
class GasLimits:

execution

Maximum execution gas that can be expended in pursuit of the frame.

212
    execution: U64

state

Maximum state gas that can be expended in pursuit of the frame.

217
    state: U64

Frame

Unit of execution defined in a FrameTransaction.

223
@final
224
@slotted_freezable
225
@dataclass
class Frame:

mode

Purpose of this frame.

Specifies the specific execution semantics this frame will execute with.

233
    mode: FrameMode

flags

Enable optional frame or mode features.

240
    flags: FrameFlag

to

Destination or target account for the frame.

245
    to: Bytes0 | Address

gas_limits

The frame's gas budgets, one per gas dimension.

250
    gas_limits: GasLimits

value

Amount of ether (in wei) to transfer from the sender as part of the frame execution.

255
    value: U256

data

The data payload of the frame, which can be used to call functions on contracts.

263
    data: Bytes

FrameSignatureScheme

Algorithm used to authenticate FrameSignatures.

The strict boundary rejects values other than the schemes defined here as the enum is constructed — notably while decoding a transaction — so a signature using a reserved scheme never decodes and no separate validity check is required.

270
@final
class FrameSignatureScheme:

ARBITRARY

Arbitrary bytes that the protocol does not cryptographically validate.

283
    ARBITRARY = Uint(0)

SECP256K1

ECDSA signature over the secp256k1 curve, as used by other transaction types.

288
    SECP256K1 = Uint(1)

P256

Signature over the NIST P-256 (secp256r1) curve.

294
    P256 = Uint(2)

FrameSignature

A signature entry available to the transaction's frames.

Entries are validated before any frame executes and may be referenced by VERIFY frames and by ordinary EVM execution, through the signature introspection instructions.

300
@final
301
@slotted_freezable
302
@dataclass
class FrameSignature:

scheme

Algorithm used to construct the signature.

314
    scheme: FrameSignatureScheme

signer

Scheme-dependent signer metadata.

For SECP256K1 and P256, this is a 20-byte address.

319
    signer: Bytes

message

Either empty, indicating the canonical transaction signature hash, or an explicit 32-byte digest.

329
    message: Bytes0 | Bytes32

signature

Raw signature bytes, to be interpreted according to scheme.

335
    signature: Bytes

TransactionFees

The fee parameters of a FrameTransaction.

Corresponds to the fees list of the transaction payload in EIP-8141.

343
@final
344
@slotted_freezable
345
@dataclass
class TransactionFees:

max_fee

The maximum total fee, in wei, that the sender is willing to pay for all of the transaction's execution, state, and blob gas.

357
    max_fee: Uint

max_priority_fee_per_gas

The priority fee per gas that the sender is willing to pay.

363
    max_priority_fee_per_gas: Uint

FrameTransaction

Transaction type constructed from a series of frames, abstractly defining validity conditions and gas payment. Introduced in EIP-8141.

369
@final
370
@slotted_freezable
371
@dataclass
class FrameTransaction:

chain_id

The ID of the chain on which this transaction is executed.

380
    chain_id: U64

nonce

A scalar value equal to the number of transactions sent by the sender.

385
    nonce: U256

sender

Address of the account intended to be the sender of the transaction.

393
    sender: Address

frames

List of frames to execute.

398
    frames: Tuple[Frame, ...]

signatures

Validated signatures available to the transaction.

The signatures list contains signatures that may be referenced by VERIFY frames and by ordinary EVM execution. Every signature in the list must validate successfully before any Frame is executed. If any signature is malformed or invalid, the whole transaction is invalid.

403
    signatures: Tuple[FrameSignature, ...]

fees

The transaction's fee parameters.

416
    fees: TransactionFees

blob_versioned_hashes

A tuple of objects that represent the versioned hashes of the blobs included in the transaction.

421
    blob_versioned_hashes: Tuple[VersionedHash, ...]

resolve_frame_target

Resolve the account a frame executes at: an empty to resolves to the transaction's sender in every mode.

def resolve_frame_target(​tx: FrameTransaction, ​​frame: Frame​) -> Address:
429
    <snip>
433
    if isinstance(frame.to, Bytes0):
434
        return tx.sender
435
    return frame.to

compute_frame_signature_hash

Compute the canonical signature hash of a frame transaction.

The raw signature bytes of every entry with an empty msg are replaced by their length, encoded as an unsigned integer, before hashing. A signature over the canonical hash cannot commit to its own bytes, but committing to their length fixes what the payer is charged for them.

def compute_frame_signature_hash(​tx: FrameTransaction​) -> Hash32:
439
    <snip>
448
    elided_signatures = []
449
    for signature in tx.signatures:
450
        if len(signature.message) == 0:
451
            length = ulen(signature.signature).to_be_bytes()
452
            elided_signatures.append(replace(signature, signature=length))
453
        else:
454
            elided_signatures.append(signature)
455
456
    elided_tx = replace(tx, signatures=tuple(elided_signatures))
457
    return keccak256(b"\x06" + rlp.encode(elided_tx))

validate_signature

Validate a single FrameSignature entry and return the signer it resolved to.

The entry's message selects what the signature authorizes: empty means the canonical signature hash sig_hash (see compute_frame_signature_hash), while a 32-byte value is an explicit digest. The all-zero digest is invalid, reserving the zero stack value as the EVM-visible representation of the canonical-hash case.

An empty signer resolves to sender. For the protocol-validated schemes (SECP256K1 and P256) the raw signature bytes must be canonical — one unique encoding per signature, with low-s — and must authenticate the resolved signer. The protocol does not cryptographically validate ARBITRARY entries and assigns them no resolved signer — None is returned — so their signer must be empty.

def validate_signature(​frame_signature: FrameSignature, ​​sender: Address, ​​sig_hash: Hash32​) -> Optional[Address]:
463
    <snip>  # noqa: E501
488
    signature_scheme = frame_signature.scheme
489
    signer = frame_signature.signer
490
    signature = frame_signature.signature
491
492
    if len(frame_signature.message) == 0:
493
        message = sig_hash
494
    elif len(frame_signature.message) == 32:
495
        if frame_signature.message == b"\0" * 32:
496
            raise InvalidFrameError(
497
                "frame signature message cannot be all zeros"
498
            )
499
        message = Hash32(frame_signature.message)
500
    else:
501
        raise InvalidFrameError("Invalid signature message length")
502
503
    if len(signer) not in [0, Address.LENGTH]:
504
        raise InvalidFrameError("invalid frame signer length")
505
    resolved_signer: Bytes
506
    if len(signer) == 0:
507
        resolved_signer = sender
508
    else:
509
        resolved_signer = signer
510
511
    match signature_scheme:
512
        case FrameSignatureScheme.SECP256K1:
513
            if len(signature) != 65:
514
                raise InvalidSignatureError(
515
                    "SECP256K1 signature must be 65 bytes"
516
                )
517
518
            v = U256(signature[0])
519
            r = U256.from_be_bytes(signature[1:33])
520
            s = U256.from_be_bytes(signature[33:65])
521
            if v not in (U256(0), U256(1)):
522
                raise InvalidSignatureError("bad v in secp256k1 scheme")
523
            if U256(0) >= r or r >= SECP256K1N:
524
                raise InvalidSignatureError("bad r in secp256k1 scheme")
525
            if U256(0) >= s or s > SECP256K1N // U256(2):
526
                raise InvalidSignatureError("bad s in secp256k1 scheme")
527
528
            public_key = secp256k1_recover(r, s, v, message)
529
530
            if resolved_signer != keccak256(public_key)[12:]:
531
                raise InvalidFrameError(
532
                    "signer does not match in secp256k1 scheme"
533
                )
534
535
            return Address(resolved_signer)
536
537
        case FrameSignatureScheme.P256:
538
            if len(signature) != 128:
539
                raise InvalidSignatureError("P256 signature must be 128 bytes")
540
541
            r = U256.from_be_bytes(signature[0:32])
542
            s = U256.from_be_bytes(signature[32:64])
543
            qx = U256.from_be_bytes(signature[64:96])
544
            qy = U256.from_be_bytes(signature[96:128])
545
546
            if U256(0) >= r or r >= SECP256R1N:
547
                raise InvalidSignatureError("bad r in p256 scheme")
548
            if U256(0) >= s or s > SECP256R1N // U256(2):
549
                raise InvalidSignatureError("bad s in p256 scheme")
550
            if resolved_signer != keccak256(signature[64:128])[12:]:
551
                raise InvalidFrameError("signer does not match in p256 scheme")
552
            try:
553
                secp256r1_verify(r, s, qx, qy, message)
554
            except ValueError as e:
555
                raise InvalidSignatureError("invalid p256 public key") from e
556
557
            return Address(resolved_signer)
558
559
        case FrameSignatureScheme.ARBITRARY:
560
            if len(signer) != 0:
561
                raise InvalidFrameError(
562
                    "signer length should be zero for arbitrary schemes"
563
                )
564
            return None
565
        case _ as unreachable:
566
            assert_never(unreachable)

FrameTransactionValidation

Everything the static validation of a frame transaction establishes: its intrinsic gas cost, its two gas anchors, and the signature artifacts retained for execution.

569
@final
570
@dataclass
class FrameTransactionValidation:

intrinsic

The transaction's intrinsic gas cost.

578
    intrinsic: "IntrinsicGasCost"

standard_gas_limit

Settlement anchor: the intrinsic execution gas cost plus the sum of the frames' gas budgets in both dimensions.

583
    standard_gas_limit: Uint

max_gas

Inclusion anchor: the larger of standard_gas_limit and the calldata floor plus the frames' total state gas budget.

589
    max_gas: Uint

signature_hash

The transaction's canonical signature hash.

595
    signature_hash: Hash32

resolved_signers

The signer each signature entry resolved to; None for ARBITRARY entries, to which the protocol assigns no signer.

600
    resolved_signers: Tuple[Optional[Address], ...]

validate_frame_transaction

Check the statically determinable validity constraints of a frame transaction and derive its gas anchors.

Constraints on individual fields — frame modes and flags, signature schemes, and field lengths — are mostly enforced by their types while the transaction is decoded. Checked here instead are the nonce and fee-cap upper bounds, which are tighter than the decoded types enforce, and the constraints that span several fields.

A frame transaction has no gas limit field; its two gas anchors are derived instead. The per-transaction gas cap of EIP-7825 bounds the transaction's execution dimension — the larger of its intrinsic cost plus the frames' execution gas budgets and its calldata floor — while state gas budgets are exempt from the cap.

def validate_frame_transaction(​tx: FrameTransaction​) -> FrameTransactionValidation:
610
    <snip>
628
    from ..vm.gas import GasCosts
629
    from . import BLOB_COUNT_LIMIT, VERSIONED_HASH_VERSION_KZG
630
631
    if tx.nonce >= U256(U64.MAX_VALUE):
632
        raise NonceOverflowError("Nonce too high")
633
634
    if tx.fees.max_fee > Uint(U256.MAX_VALUE):
635
        raise FeeOverflowError("Max fee too high")
636
    if tx.fees.max_priority_fee_per_gas > Uint(U256.MAX_VALUE):
637
        raise FeeOverflowError("Max priority fee per gas too high")
638
639
    blob_count = len(tx.blob_versioned_hashes)
640
    if blob_count > BLOB_COUNT_LIMIT:
641
        raise BlobCountExceededError(
642
            f"Tx has {blob_count} blobs. Max allowed: {BLOB_COUNT_LIMIT}"
643
        )
644
    for blob_versioned_hash in tx.blob_versioned_hashes:
645
        if blob_versioned_hash[0:1] != VERSIONED_HASH_VERSION_KZG:
646
            raise InvalidBlobVersionedHashError("invalid blob versioned hash")
647
648
    frame_count = ulen(tx.frames)
649
    if frame_count < Uint(1) or frame_count > MAX_FRAMES_PER_TX:
650
        raise FrameCountError(actual=frame_count, maximum=MAX_FRAMES_PER_TX)
651
652
    signature_hash = compute_frame_signature_hash(tx)
653
    resolved_signers = tuple(
654
        validate_signature(signature, tx.sender, signature_hash)
655
        for signature in tx.signatures
656
    )
657
658
    has_expiry_verifier_frame = False
659
    total_frame_gas = Uint(0)
660
    total_frame_execution_gas = Uint(0)
661
    total_frame_state_gas = Uint(0)
662
    for index, frame in enumerate(tx.frames):
663
        total_frame_execution_gas += Uint(frame.gas_limits.execution)
664
        total_frame_state_gas += Uint(frame.gas_limits.state)
665
        total_frame_gas += Uint(frame.gas_limits.execution) + Uint(
666
            frame.gas_limits.state
667
        )
668
        if total_frame_gas > Uint(U64.MAX_VALUE):
669
            raise InvalidFrameError("total frame gas overflows")
670
671
        if frame.mode != FrameMode.SENDER and frame.value != U256(0):
672
            raise InvalidFrameError("only sender frames can transfer value")
673
674
        if FrameFlag.APPROVE_EXECUTION in frame.flags:
675
            if isinstance(frame.to, Address) and frame.to != tx.sender:
676
                raise InvalidFrameError(
677
                    "approve execution frame must target sender"
678
                )
679
680
        if FrameFlag.ATOMIC_BATCH in frame.flags:
681
            if frame.mode == FrameMode.VERIFY:
682
                raise InvalidFrameError(
683
                    "atomic batches cannot contain verify frames"
684
                )
685
            if index + 1 >= len(tx.frames):
686
                raise InvalidFrameError("last frame cannot have atomic flag")
687
            if tx.frames[index + 1].mode == FrameMode.VERIFY:
688
                raise InvalidFrameError(
689
                    "atomic batches cannot contain verify frames"
690
                )
691
692
        # Approval scope is disallowed on every frame of an atomic
693
        # batch, including its terminating frame. A frame belongs to a
694
        # batch when it or its predecessor carries the flag. Keeping the
695
        # approval context constant across a batch means unrolling one
696
        # can never withdraw an execution approval that later SENDER
697
        # frames rely on, and whether the transaction sets a payer never
698
        # depends on a batch outcome.
699
        in_batch = FrameFlag.ATOMIC_BATCH in frame.flags or (
700
            index > 0 and FrameFlag.ATOMIC_BATCH in tx.frames[index - 1].flags
701
        )
702
        if in_batch and frame.flags & APPROVE_SCOPE_MASK != FrameFlag(0):
703
            raise InvalidFrameError(
704
                "atomic batch frames cannot carry approval scope"
705
            )
706
707
        if frame.mode == FrameMode.VERIFY and frame.to == EXPIRY_VERIFIER:
708
            if has_expiry_verifier_frame:
709
                raise InvalidFrameError("multiple expiry verifier frames")
710
            has_expiry_verifier_frame = True
711
            if frame.flags != FrameFlag(0):
712
                raise InvalidFrameError("expiry verifier frame with flags")
713
            if frame.value != U256(0):
714
                raise InvalidFrameError("expiry verifier frame with value")
715
            if frame.gas_limits.state != U64(0):
716
                raise InvalidFrameError("expiry verifier frame with state gas")
717
            if len(frame.data) != EXPIRY_DATA_LENGTH:
718
                raise InvalidFrameError(
719
                    "expiry verifier frame data must be an expiry timestamp"
720
                )
721
722
    intrinsic = calculate_frame_transaction_intrinsic_cost(tx)
723
    standard_gas_limit = Uint(intrinsic.execution) + total_frame_gas
724
    max_gas = max(
725
        standard_gas_limit,
726
        Uint(intrinsic.calldata_floor) + total_frame_state_gas,
727
    )
728
729
    # The per-transaction gas cap of EIP-7825 bounds the execution
730
    # dimension alone: the intrinsic cost plus the frames' execution
731
    # budgets, with the calldata floor checked against the same cap.
732
    # State gas is bounded only by the encoding limit and the block's
733
    # state gas capacity.
734
    execution_gas_cap_usage = max(
735
        Uint(intrinsic.execution) + total_frame_execution_gas,
736
        Uint(intrinsic.calldata_floor),
737
    )
738
    if execution_gas_cap_usage > GasCosts.TX_MAX_GAS_LIMIT:
739
        raise TransactionGasLimitExceededError(
740
            "Derived execution gas limit exceeds TX_MAX_GAS_LIMIT"
741
        )
742
743
    return FrameTransactionValidation(
744
        intrinsic=intrinsic,
745
        standard_gas_limit=standard_gas_limit,
746
        max_gas=max_gas,
747
        signature_hash=signature_hash,
748
        resolved_signers=resolved_signers,
749
    )

signature_verification_gas

Return the gas charged for validating a single signature entry.

def signature_verification_gas(​signature: FrameSignature​) -> ExecutionGas:
753
    <snip>
756
    from ..vm.gas import GasCosts
757
758
    match signature.scheme:
759
        case FrameSignatureScheme.SECP256K1:
760
            return GasCosts.FRAME_SIGNATURE_SCHEME_SECP256K1
761
        case FrameSignatureScheme.P256:
762
            return GasCosts.FRAME_SIGNATURE_SCHEME_P256
763
        case FrameSignatureScheme.ARBITRARY:
764
            return GasCosts.FRAME_SIGNATURE_SCHEME_ARBITRARY
765
        case _ as unreachable:
766
            assert_never(unreachable)

calculate_frame_transaction_intrinsic_cost

Calculate the gas that is charged to the payer of a frame transaction before execution is started.

The intrinsic cost is the base cost, the per-frame cost, the calldata cost of the byte fields priced as calldata — the data of each frame and the signer, message, and signature bytes of each signature entry — the signature verification cost, and the value transfer cost of each value-bearing frame with an explicit target other than the sender, covering the recipient balance write and transfer log. The signature bytes of an entry with an empty message are priced as if all non-zero, since the canonical signature hash commits only to their length. Unlike other transaction types, there is no recipient component: target access is paid during frame execution from each frame's own execution gas budget.

The calldata floor of EIP-7976 counts every charged byte uniformly and is anchored on the costs the transaction always pays regardless of execution — the base cost, the per-frame cost, the signature verification cost, and the value transfer cost — so it never undercuts the transaction's own intrinsic base.

def calculate_frame_transaction_intrinsic_cost(​tx: FrameTransaction​) -> "IntrinsicGasCost":
772
    <snip>
797
    from ..vm.gas import GasCosts
798
    from . import IntrinsicGasCost, count_tokens_in_data
799
800
    tokens = Uint(0)
801
    data_length = Uint(0)
802
    value_transfer_gas = Uint(0)
803
    for frame in tx.frames:
804
        tokens += count_tokens_in_data(frame.data)
805
        data_length += ulen(frame.data)
806
        if (
807
            frame.value > U256(0)
808
            and isinstance(frame.to, Address)
809
            and frame.to != tx.sender
810
        ):
811
            value_transfer_gas += GasCosts.TX_VALUE_COST
812
813
    signature_gas = Uint(0)
814
    for signature in tx.signatures:
815
        signature_gas += signature_verification_gas(signature)
816
        for data in (signature.signer, signature.message):
817
            tokens += count_tokens_in_data(data)
818
            data_length += ulen(data)
819
        signature_length = ulen(signature.signature)
820
        if len(signature.message) == 0:
821
            tokens += signature_length * Uint(4)
822
        else:
823
            tokens += count_tokens_in_data(signature.signature)
824
        data_length += signature_length
825
826
    # EIP-7976 floor tokens: all charged bytes count uniformly.
827
    floor_tokens = data_length * Uint(4)
828
829
    base_execution_gas = (
830
        GasCosts.TX_FRAME_INTRINSIC
831
        + ulen(tx.frames) * GasCosts.TX_PER_FRAME
832
        + signature_gas
833
        + value_transfer_gas
834
    )
835
836
    return IntrinsicGasCost(
837
        execution=ExecutionGas(
838
            base_execution_gas + tokens * GasCosts.TX_DATA_TOKEN_STANDARD
839
        ),
840
        calldata_floor=ExecutionGas(
841
            base_execution_gas + floor_tokens * GasCosts.TX_DATA_TOKEN_FLOOR
842
        ),
843
    )