ethereum.forks.bpo5.transactionsethereum.forks.amsterdam.transactions

Transactions are atomic units of work created externally to Ethereum and submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states.

IntrinsicGasCost

Intrinsic gas costs for a transaction, split by gas type.

31
@final
32
@dataclass
class IntrinsicGasCost:

regular

Regular execution gas (calldata, base cost, access list, etc.).

36
    regular: Uint

state

State growth gas (account creation, storage set, authorization) per EIP-8037.

39
    state: Uint

calldata_floor

Minimum gas cost based on calldata size per [EIP-7623].Minimum gas cost based on calldata size per EIP-7623.

47
    calldata_floor: Uint

TX_MAX_GAS_LIMIT

55
TX_MAX_GAS_LIMIT = Uint(16_777_216)

ACCESS_LIST_ADDRESS_FLOOR_TOKENS

Floor data tokens contributed by a single access list address per EIP-7981.

57
ACCESS_LIST_ADDRESS_FLOOR_TOKENS = Uint(80)

ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS

Floor data tokens contributed by a single access list storage key per EIP-7981.

65
ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS = Uint(128)

LegacyTransaction

Atomic operation performed on the block chain. This represents the original transaction format used before EIP-1559, EIP-2930, EIP-4844, and EIP-7702.

74
@final
75
@slotted_freezable
76
@dataclass
class LegacyTransaction:

nonce

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

89
    nonce: U256

gas_price

The price of gas for this transaction, in wei.

94
    gas_price: Uint

gas

The maximum amount of gas that can be used by this transaction.

99
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

104
    to: Bytes0 | Address

value

The amount of ether (in wei) to send with this transaction.

110
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

115
    data: Bytes

v

The recovery id of the signature.

121
    v: U256

r

The first part of the signature.

126
    r: U256

s

The second part of the signature.

131
    s: U256

Access

A mapping from account address to storage slots that are pre-warmed as part of a transaction.

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

account

The address of the account that is accessed.

146
    account: Address

slots

A tuple of storage slots that are accessed in the account.

151
    slots: Tuple[Bytes32, ...]

AccessListTransaction

The transaction type added in EIP-2930 to support access lists.

This transaction type extends the legacy transaction with an access list and chain ID. The access list specifies which addresses and storage slots the transaction will access.

157
@final
158
@slotted_freezable
159
@dataclass
class AccessListTransaction:

chain_id

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

171
    chain_id: U64

nonce

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

176
    nonce: U256

gas_price

The price of gas for this transaction.

181
    gas_price: Uint

gas

The maximum amount of gas that can be used by this transaction.

186
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

191
    to: Bytes0 | Address

value

The amount of ether (in wei) to send with this transaction.

197
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

202
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

208
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

214
    y_parity: U256

r

The first part of the signature.

219
    r: U256

s

The second part of the signature.

224
    s: U256

FeeMarketTransaction

The transaction type added in EIP-1559.

This transaction type introduces a new fee market mechanism with two gas price parameters: max_priority_fee_per_gas and max_fee_per_gas.

230
@final
231
@slotted_freezable
232
@dataclass
class FeeMarketTransaction:

chain_id

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

243
    chain_id: U64

nonce

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

248
    nonce: U256

max_priority_fee_per_gas

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

253
    max_priority_fee_per_gas: Uint

max_fee_per_gas

The maximum fee per gas that the sender is willing to pay, including the base fee and priority fee.

258
    max_fee_per_gas: Uint

gas

The maximum amount of gas that can be used by this transaction.

264
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

269
    to: Bytes0 | Address

value

The amount of ether (in wei) to send with this transaction.

275
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

280
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

286
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

292
    y_parity: U256

r

The first part of the signature.

297
    r: U256

s

The second part of the signature.

302
    s: U256

BlobTransaction

The transaction type added in EIP-4844.

This transaction type extends the fee market transaction to support blob-carrying transactions.

308
@final
309
@slotted_freezable
310
@dataclass
class BlobTransaction:

chain_id

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

321
    chain_id: U64

nonce

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

326
    nonce: U256

max_priority_fee_per_gas

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

331
    max_priority_fee_per_gas: Uint

max_fee_per_gas

The maximum fee per gas that the sender is willing to pay, including the base fee and priority fee.

336
    max_fee_per_gas: Uint

gas

The maximum amount of gas that can be used by this transaction.

342
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

347
    to: Address

value

The amount of ether (in wei) to send with this transaction.

353
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

358
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

364
    access_list: Tuple[Access, ...]

max_fee_per_blob_gas

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

370
    max_fee_per_blob_gas: U256

blob_versioned_hashes

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

375
    blob_versioned_hashes: Tuple[VersionedHash, ...]

y_parity

The recovery id of the signature.

381
    y_parity: U256

r

The first part of the signature.

386
    r: U256

s

The second part of the signature.

391
    s: U256

SetCodeTransaction

The transaction type added in EIP-7702.

This transaction type allows Ethereum Externally Owned Accounts (EOAs) to set code on their account, enabling them to act as smart contracts.

397
@final
398
@slotted_freezable
399
@dataclass
class SetCodeTransaction:

chain_id

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

410
    chain_id: U64

nonce

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

415
    nonce: U64

max_priority_fee_per_gas

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

420
    max_priority_fee_per_gas: Uint

max_fee_per_gas

The maximum fee per gas that the sender is willing to pay, including the base fee and priority fee.

425
    max_fee_per_gas: Uint

gas

The maximum amount of gas that can be used by this transaction.

431
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

436
    to: Address

value

The amount of ether (in wei) to send with this transaction.

442
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

447
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

453
    access_list: Tuple[Access, ...]

authorizations

A tuple of Authorization objects that specify what code the signer desires to execute in the context of their EOA.

459
    authorizations: Tuple[Authorization, ...]

y_parity

The recovery id of the signature.

465
    y_parity: U256

r

The first part of the signature.

470
    r: U256

s

The second part of the signature.

475
    s: U256

Transaction

Union type representing any valid transaction type.

481
Transaction = (
482
    LegacyTransaction
483
    | AccessListTransaction
484
    | FeeMarketTransaction
485
    | BlobTransaction
486
    | SetCodeTransaction
487
)

AccessListCapableTransaction

Transaction types that include an EIP-2930-style access list.

See has_access_list and Access for more details.

493
AccessListCapableTransaction = (
494
    AccessListTransaction
495
    | FeeMarketTransaction
496
    | BlobTransaction
497
    | SetCodeTransaction
498
)

FeeMarketCapableTransaction

Transaction types that include the EIP-1559-style fee structure.

See FeeMarketTransaction for more details.

510
FeeMarketCapableTransaction = (
511
    FeeMarketTransaction | BlobTransaction | SetCodeTransaction
512
)

encode_transaction

Encode a transaction into its RLP or typed transaction format. Needed because non-legacy transactions aren't RLP.

Legacy transactions are returned as-is, while other transaction types are prefixed with their type identifier and RLP encoded.

def encode_transaction(tx: Transaction) -> LegacyTransaction | Bytes:
524
    <snip>
531
    if isinstance(tx, LegacyTransaction):
532
        return tx
533
    elif isinstance(tx, AccessListTransaction):
534
        return b"\x01" + rlp.encode(tx)
535
    elif isinstance(tx, FeeMarketTransaction):
536
        return b"\x02" + rlp.encode(tx)
537
    elif isinstance(tx, BlobTransaction):
538
        return b"\x03" + rlp.encode(tx)
539
    elif isinstance(tx, SetCodeTransaction):
540
        return b"\x04" + rlp.encode(tx)
541
    else:
542
        raise Exception(f"Unable to encode transaction of type {type(tx)}")

decode_transaction

Decode a transaction from its RLP or typed transaction format. Needed because non-legacy transactions aren't RLP.

Legacy transactions are returned as-is, while other transaction typesAccept a LegacyTransaction object (returned as-is) or raw are decoded based on their type identifier prefix.bytes.

EIP-2718 states that the first byte distinguishes the format: [0x00, 0x7f] is a typed transaction, [0xc0, 0xfe] is a legacy transaction (RLP list prefix).

def decode_transaction(tx: LegacyTransaction | Bytes) -> Transaction:
546
    <snip>
557
    if isinstance(tx, Bytes):
558
        if tx[0] == 1:
559
            return rlp.decode_to(AccessListTransaction, tx[1:])
560
        elif tx[0] == 2:
561
            return rlp.decode_to(FeeMarketTransaction, tx[1:])
562
        elif tx[0] == 3:
563
            return rlp.decode_to(BlobTransaction, tx[1:])
564
        elif tx[0] == 4:
565
            return rlp.decode_to(SetCodeTransaction, tx[1:])
535
        else:
536
            raise TransactionTypeError(tx[0])
566
        elif tx[0] >= 0xC0:
567
            assert tx[0] <= 0xFE
568
            return rlp.decode_to(LegacyTransaction, tx)
569
        else:
570
            raise TransactionTypeError(tx[0])
571
    else:
572
        return tx

validate_transaction

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.

Also, the code size of a contract creation transaction must be within limits of the protocol.

This function takes a transaction as a parameter and returns the intrinsicThis function takes a transaction and gas_limit as parameters and gas cost and the minimum calldata gas cost for the transaction afterreturns the intrinsic gas costs for the transaction after validation. validation. It throws an It throws an InsufficientTransactionGasError exception if exception if the the transaction does not provide enough gas to cover the intrinsic cost,transaction does not provide enough gas to cover the intrinsic cost, and a NonceOverflowError exception if the nonce is greater than exception if the nonce overflows. 2**64 - 2. It also raises an It also raises an InitCodeTooLargeError if the code size of if the code a contract creation transaction exceeds the maximum allowed size.size of a contract creation transaction exceeds the maximum allowed size.

def validate_transaction(tx: Transaction) -> IntrinsicGasCost:
576
    <snip>
605
    from .vm.interpreter import MAX_INIT_CODE_SIZE
606
607
    intrinsic = calculate_intrinsic_cost(tx)
573
    if max(intrinsic.regular, intrinsic.calldata_floor) > tx.gas:
574
        raise InsufficientTransactionGasError("Insufficient gas")
608
    intrinsic_gas = intrinsic.regular + intrinsic.state
609
    if intrinsic_gas > tx.gas:
610
        raise InsufficientTransactionGasError("Insufficient intrinsic gas")
611
    if intrinsic.calldata_floor > tx.gas:
612
        raise InsufficientTransactionGasError("Insufficient calldata floor")
613
    if intrinsic.regular > TX_MAX_GAS_LIMIT:
614
        raise InsufficientTransactionGasError(
615
            "Intrinsic regular gas exceeds TX_MAX_GAS_LIMIT"
616
        )
617
    if intrinsic.calldata_floor > TX_MAX_GAS_LIMIT:
618
        raise InsufficientTransactionGasError(
619
            "Intrinsic calldata floor exceeds TX_MAX_GAS_LIMIT"
620
        )
621
    if U256(tx.nonce) >= U256(U64.MAX_VALUE):
622
        raise NonceOverflowError("Nonce too high")
623
    if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
624
        raise InitCodeTooLargeError("Code size too large")
579
    if tx.gas > TX_MAX_GAS_LIMIT:
580
        raise TransactionGasLimitExceededError("Gas limit too high")
625
626
    return intrinsic

calculate_intrinsic_cost

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.

The intrinsic cost includes:

  1. Base cost (TX_BASE)

  2. Cost for data (zero and non-zero bytes)

  3. Cost for contract creation (if applicable)

  4. Cost for access list entries (if applicable)

  5. Cost for authorizations (if applicable)

This function takes a transaction as a parameter and returns the intrinsicThis function takes a transaction and gas_limit as parameters and gas cost of the transaction and the minimum gas cost used by thereturns the intrinsic regular gas cost, intrinsic state gas cost, and the transaction based on the calldata size.minimum gas cost used by the transaction based on the calldata size.

def calculate_intrinsic_cost(tx: Transaction) -> IntrinsicGasCost:
630
    <snip>
610
    from .vm.gas import GasCosts, init_code_cost
654
    from .vm.gas import (
655
        GasCosts,
656
        StateGasCosts,
657
        init_code_cost,
658
    )
659
612
    num_zeros = Uint(tx.data.count(0))
613
    num_non_zeros = ulen(tx.data) - num_zeros
614
615
    tokens_in_calldata = num_zeros + num_non_zeros * Uint(4)
616
    # EIP-7623 floor price (note: no EVM costs)
617
    calldata_floor_gas_cost = (
618
        tokens_in_calldata * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE
619
    )
660
    tokens_in_calldata = count_tokens_in_data(tx.data)
661
662
    data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD
663
664
    create_regular_gas = Uint(0)
665
    create_state_gas = Uint(0)
666
    if tx.to == Bytes0(b""):
624
        create_cost = GasCosts.TX_CREATE + init_code_cost(ulen(tx.data))
625
    else:
626
        create_cost = Uint(0)
667
        create_state_gas = StateGasCosts.NEW_ACCOUNT
668
        create_regular_gas = GasCosts.REGULAR_GAS_CREATE + init_code_cost(
669
            ulen(tx.data)
670
        )
671
672
    access_list_cost = Uint(0)
673
    tokens_in_access_list = Uint(0)
674
    if has_access_list(tx):
675
        for access in tx.access_list:
676
            access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS
677
            access_list_cost += (
678
                ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY
679
            )
680
            tokens_in_access_list += ACCESS_LIST_ADDRESS_FLOOR_TOKENS
681
            tokens_in_access_list += (
682
                ulen(access.slots) * ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS
683
            )
684
636
    auth_cost = Uint(0)
685
    # Data token floor cost for access list bytes.
686
    access_list_cost += tokens_in_access_list * GasCosts.TX_DATA_TOKEN_FLOOR
687
688
    auth_regular_gas = Uint(0)
689
    auth_state_gas = Uint(0)
690
    if isinstance(tx, SetCodeTransaction):
638
        auth_cost += Uint(
639
            GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)
640
        )
691
        auth_regular_gas = GasCosts.PER_AUTH_BASE_COST * ulen(
692
            tx.authorizations
693
        )
694
        auth_state_gas = (
695
            StateGasCosts.NEW_ACCOUNT + StateGasCosts.AUTH_BASE
696
        ) * ulen(tx.authorizations)
697
698
    # EIP-7976 floor tokens: all calldata bytes count uniformly.
699
    floor_tokens_in_calldata = ulen(tx.data) * GasCosts.TX_DATA_TOKEN_STANDARD
700
701
    # Total floor tokens.
702
    total_floor_tokens = floor_tokens_in_calldata + tokens_in_access_list
703
704
    # Floor gas cost (EIP-7623: minimum gas for data-heavy transactions).
705
    data_floor_gas_cost = (
706
        total_floor_tokens * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE
707
    )
708
709
    intrinsic_regular_gas = (
710
        GasCosts.TX_BASE
711
        + data_cost
712
        + create_regular_gas
713
        + access_list_cost
714
        + auth_regular_gas
715
    )
716
717
    intrinsic_state_gas = create_state_gas + auth_state_gas
718
719
    return IntrinsicGasCost(
643
        regular=Uint(
644
            GasCosts.TX_BASE
645
            + data_cost
646
            + create_cost
647
            + access_list_cost
648
            + auth_cost
649
        ),
650
        calldata_floor=calldata_floor_gas_cost,
720
        regular=intrinsic_regular_gas,
721
        state=intrinsic_state_gas,
722
        calldata_floor=data_floor_gas_cost,
723
    )

count_tokens_in_data

Count the data tokens in arbitrary input bytes.

Zero bytes count as 1 token; non-zero bytes count as 4 tokens.

def count_tokens_in_data(data: bytes) -> Uint:
727
    <snip>
732
    num_zeros = Uint(data.count(0))
733
    num_non_zeros = ulen(data) - num_zeros
734
735
    return num_zeros + num_non_zeros * Uint(4)

chain_id

Extract the chain identifier from a transaction. See EIP-155.

def chain_id(tx: Transaction) -> None | U64:
739
    <snip>
744
    if isinstance(tx, LegacyTransaction):
745
        if tx.v == 27 or tx.v == 28:
746
            return None
747
748
        if tx.v < U256(35):
749
            raise InvalidSignatureError("bad v")
750
751
        return U64((tx.v - U256(35)) >> U256(1))
752
    else:
753
        return tx.chain_id

recover_sender

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.

This function takes chain_id and a transaction as parameters and returns the address of the sender of the transaction. It raises an InvalidSignatureError if the signature values (r, s, v) are invalid.

def recover_sender(tx: Transaction) -> Address:
757
    <snip>
770
    r, s = tx.r, tx.s
771
    if U256(0) >= r or r >= SECP256K1N:
772
        raise InvalidSignatureError("bad r")
773
    if U256(0) >= s or s > SECP256K1N // U256(2):
774
        raise InvalidSignatureError("bad s")
775
776
    if isinstance(tx, LegacyTransaction):
777
        v = tx.v
778
        if v == 27 or v == 28:
779
            public_key = secp256k1_recover(
780
                r, s, v - U256(27), signing_hash_pre155(tx)
781
            )
782
        else:
783
            assert v >= U256(35), "call chain_id before recover_sender"
784
            tx_chain_id = U64((v - U256(35)) >> U256(1))
785
            v = (v - U256(35)) & U256(1)
786
            public_key = secp256k1_recover(
787
                r,
788
                s,
789
                v,
790
                signing_hash_155(tx, tx_chain_id),
791
            )
792
    elif isinstance(tx, AccessListTransaction):
793
        if tx.y_parity not in (U256(0), U256(1)):
794
            raise InvalidSignatureError("bad y_parity")
795
        public_key = secp256k1_recover(
796
            r, s, tx.y_parity, signing_hash_2930(tx)
797
        )
798
    elif isinstance(tx, FeeMarketTransaction):
799
        if tx.y_parity not in (U256(0), U256(1)):
800
            raise InvalidSignatureError("bad y_parity")
801
        public_key = secp256k1_recover(
802
            r, s, tx.y_parity, signing_hash_1559(tx)
803
        )
804
    elif isinstance(tx, BlobTransaction):
805
        if tx.y_parity not in (U256(0), U256(1)):
806
            raise InvalidSignatureError("bad y_parity")
807
        public_key = secp256k1_recover(
808
            r, s, tx.y_parity, signing_hash_4844(tx)
809
        )
810
    elif isinstance(tx, SetCodeTransaction):
811
        if tx.y_parity not in (U256(0), U256(1)):
812
            raise InvalidSignatureError("bad y_parity")
813
        public_key = secp256k1_recover(
814
            r, s, tx.y_parity, signing_hash_7702(tx)
815
        )
816
817
    return Address(keccak256(public_key)[12:32])

signing_hash_pre155

Compute the hash of a transaction used in a legacy (pre EIP-155) signature.

This function takes a legacy transaction as a parameter and returns the signing hash of the transaction.

def signing_hash_pre155(tx: LegacyTransaction) -> Hash32:
821
    <snip>
830
    return keccak256(
831
        rlp.encode(
832
            (
833
                tx.nonce,
834
                tx.gas_price,
835
                tx.gas,
836
                tx.to,
837
                tx.value,
838
                tx.data,
839
            )
840
        )
841
    )

signing_hash_155

Compute the hash of a transaction used in a EIP-155 signature.

This function takes a legacy transaction and a chain ID as parameters and returns the hash of the transaction used in an EIP-155 signature.

def signing_hash_155(tx: LegacyTransaction, ​​chain_id: U64) -> Hash32:
845
    <snip>
853
    return keccak256(
854
        rlp.encode(
855
            (
856
                tx.nonce,
857
                tx.gas_price,
858
                tx.gas,
859
                tx.to,
860
                tx.value,
861
                tx.data,
862
                chain_id,
863
                Uint(0),
864
                Uint(0),
865
            )
866
        )
867
    )

signing_hash_2930

Compute the hash of a transaction used in a EIP-2930 signature.

This function takes an access list transaction as a parameter and returns the hash of the transaction used in an EIP-2930 signature.

def signing_hash_2930(tx: AccessListTransaction) -> Hash32:
871
    <snip>
879
    return keccak256(
880
        b"\x01"
881
        + rlp.encode(
882
            (
883
                tx.chain_id,
884
                tx.nonce,
885
                tx.gas_price,
886
                tx.gas,
887
                tx.to,
888
                tx.value,
889
                tx.data,
890
                tx.access_list,
891
            )
892
        )
893
    )

signing_hash_1559

Compute the hash of a transaction used in an EIP-1559 signature.

This function takes a fee market transaction as a parameter and returns the hash of the transaction used in an EIP-1559 signature.

def signing_hash_1559(tx: FeeMarketTransaction) -> Hash32:
897
    <snip>
905
    return keccak256(
906
        b"\x02"
907
        + rlp.encode(
908
            (
909
                tx.chain_id,
910
                tx.nonce,
911
                tx.max_priority_fee_per_gas,
912
                tx.max_fee_per_gas,
913
                tx.gas,
914
                tx.to,
915
                tx.value,
916
                tx.data,
917
                tx.access_list,
918
            )
919
        )
920
    )

signing_hash_4844

Compute the hash of a transaction used in an EIP-4844 signature.

This function takes a transaction as a parameter and returns the signing hash of the transaction used in an EIP-4844 signature.

def signing_hash_4844(tx: BlobTransaction) -> Hash32:
924
    <snip>
932
    return keccak256(
933
        b"\x03"
934
        + rlp.encode(
935
            (
936
                tx.chain_id,
937
                tx.nonce,
938
                tx.max_priority_fee_per_gas,
939
                tx.max_fee_per_gas,
940
                tx.gas,
941
                tx.to,
942
                tx.value,
943
                tx.data,
944
                tx.access_list,
945
                tx.max_fee_per_blob_gas,
946
                tx.blob_versioned_hashes,
947
            )
948
        )
949
    )

signing_hash_7702

Compute the hash of a transaction used in a EIP-7702 signature.

This function takes a transaction as a parameter and returns the signing hash of the transaction used in a EIP-7702 signature.

def signing_hash_7702(tx: SetCodeTransaction) -> Hash32:
953
    <snip>
961
    return keccak256(
962
        b"\x04"
963
        + rlp.encode(
964
            (
965
                tx.chain_id,
966
                tx.nonce,
967
                tx.max_priority_fee_per_gas,
968
                tx.max_fee_per_gas,
969
                tx.gas,
970
                tx.to,
971
                tx.value,
972
                tx.data,
973
                tx.access_list,
974
                tx.authorizations,
975
            )
976
        )
977
    )

get_transaction_hash

Compute the hash of a transaction.

This function takes a transaction as a parameter and returns the keccak256 hash of the transaction. It can handle both legacy transactions and typed transactions (AccessListTransaction, FeeMarketTransaction, etc.).

def get_transaction_hash(tx: Bytes | LegacyTransaction) -> Hash32:
981
    <snip>
989
    assert isinstance(tx, (LegacyTransaction, Bytes))
990
    if isinstance(tx, LegacyTransaction):
991
        return keccak256(rlp.encode(tx))
992
    else:
993
        return keccak256(tx)

has_access_list

Return whether the transaction has an EIP-2930-style access list.

def has_access_list(tx: Transaction) -> TypeGuard[AccessListCapableTransaction]:
999
    <snip>
1004
    return isinstance(
1005
        tx,
1006
        AccessListCapableTransaction,
1007
    )