ethereum.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.

36
@final
37
@dataclass
class IntrinsicGasCost:

regular

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

41
    regular: RegularGas

state

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

44
    state: StateGas

calldata_floor

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

52
    calldata_floor: RegularGas

TX_MAX_GAS_LIMIT

60
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.

62
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.

70
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.

79
@final
80
@slotted_freezable
81
@dataclass
class LegacyTransaction:

nonce

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

94
    nonce: U256

gas_price

The price of gas for this transaction, in wei.

99
    gas_price: Uint

gas

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

104
    gas: Uint

to

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

109
    to: Bytes0 | Address

value

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

115
    value: U256

data

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

120
    data: Bytes

v

The recovery id of the signature.

126
    v: U256

r

The first part of the signature.

131
    r: U256

s

The second part of the signature.

136
    s: U256

Access

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

142
@final
143
@slotted_freezable
144
@dataclass
class Access:

account

The address of the account that is accessed.

151
    account: Address

slots

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

156
    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.

162
@final
163
@slotted_freezable
164
@dataclass
class AccessListTransaction:

chain_id

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

176
    chain_id: U64

nonce

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

181
    nonce: U256

gas_price

The price of gas for this transaction.

186
    gas_price: Uint

gas

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

191
    gas: Uint

to

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

196
    to: Bytes0 | Address

value

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

202
    value: U256

data

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

207
    data: Bytes

access_list

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

213
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

219
    y_parity: U256

r

The first part of the signature.

224
    r: U256

s

The second part of the signature.

229
    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.

235
@final
236
@slotted_freezable
237
@dataclass
class FeeMarketTransaction:

chain_id

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

248
    chain_id: U64

nonce

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

253
    nonce: U256

max_priority_fee_per_gas

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

258
    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.

263
    max_fee_per_gas: Uint

gas

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

269
    gas: Uint

to

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

274
    to: Bytes0 | Address

value

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

280
    value: U256

data

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

285
    data: Bytes

access_list

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

291
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

297
    y_parity: U256

r

The first part of the signature.

302
    r: U256

s

The second part of the signature.

307
    s: U256

BlobTransaction

The transaction type added in EIP-4844.

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

313
@final
314
@slotted_freezable
315
@dataclass
class BlobTransaction:

chain_id

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

326
    chain_id: U64

nonce

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

331
    nonce: U256

max_priority_fee_per_gas

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

336
    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.

341
    max_fee_per_gas: Uint

gas

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

347
    gas: Uint

to

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

352
    to: Address

value

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

358
    value: U256

data

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

363
    data: Bytes

access_list

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

369
    access_list: Tuple[Access, ...]

max_fee_per_blob_gas

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

375
    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.

380
    blob_versioned_hashes: Tuple[VersionedHash, ...]

y_parity

The recovery id of the signature.

386
    y_parity: U256

r

The first part of the signature.

391
    r: U256

s

The second part of the signature.

396
    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.

402
@final
403
@slotted_freezable
404
@dataclass
class SetCodeTransaction:

chain_id

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

415
    chain_id: U64

nonce

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

420
    nonce: U64

max_priority_fee_per_gas

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

425
    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.

430
    max_fee_per_gas: Uint

gas

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

436
    gas: Uint

to

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

441
    to: Address

value

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

447
    value: U256

data

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

452
    data: Bytes

access_list

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

458
    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.

464
    authorizations: Tuple[Authorization, ...]

y_parity

The recovery id of the signature.

470
    y_parity: U256

r

The first part of the signature.

475
    r: U256

s

The second part of the signature.

480
    s: U256

Transaction

Union type representing any valid transaction type.

486
Transaction = (
487
    LegacyTransaction
488
    | AccessListTransaction
489
    | FeeMarketTransaction
490
    | BlobTransaction
491
    | SetCodeTransaction
492
)

AccessListCapableTransaction

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

See has_access_list and Access for more details.

498
AccessListCapableTransaction = (
499
    AccessListTransaction
500
    | FeeMarketTransaction
501
    | BlobTransaction
502
    | SetCodeTransaction
503
)

FeeMarketCapableTransaction

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

See FeeMarketTransaction for more details.

515
FeeMarketCapableTransaction = (
516
    FeeMarketTransaction | BlobTransaction | SetCodeTransaction
517
)

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:
529
    <snip>
536
    if isinstance(tx, LegacyTransaction):
537
        return tx
538
    elif isinstance(tx, AccessListTransaction):
539
        return b"\x01" + rlp.encode(tx)
540
    elif isinstance(tx, FeeMarketTransaction):
541
        return b"\x02" + rlp.encode(tx)
542
    elif isinstance(tx, BlobTransaction):
543
        return b"\x03" + rlp.encode(tx)
544
    elif isinstance(tx, SetCodeTransaction):
545
        return b"\x04" + rlp.encode(tx)
546
    else:
547
        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.

Accept a LegacyTransaction object (returned as-is) or raw 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:
551
    <snip>
562
    if isinstance(tx, Bytes):
563
        if tx[0] == 1:
564
            return rlp.decode_to(AccessListTransaction, tx[1:])
565
        elif tx[0] == 2:
566
            return rlp.decode_to(FeeMarketTransaction, tx[1:])
567
        elif tx[0] == 3:
568
            return rlp.decode_to(BlobTransaction, tx[1:])
569
        elif tx[0] == 4:
570
            return rlp.decode_to(SetCodeTransaction, tx[1:])
571
        elif tx[0] >= 0xC0:
572
            assert tx[0] <= 0xFE
573
            return rlp.decode_to(LegacyTransaction, tx)
574
        else:
575
            raise TransactionTypeError(tx[0])
576
    else:
577
        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 and gas_limit as parameters and returns the intrinsic gas costs for the transaction after validation. It throws an InsufficientTransactionGasError exception if the transaction does not provide enough gas to cover the intrinsic cost, and a NonceOverflowError exception if the nonce overflows. It also raises an InitCodeTooLargeError if the code size of a contract creation transaction exceeds the maximum allowed size.

def validate_transaction(tx: Transaction, ​​sender: Address) -> IntrinsicGasCost:
581
    <snip>
610
    from .vm.interpreter import MAX_INIT_CODE_SIZE
611
612
    intrinsic = calculate_intrinsic_cost(tx, sender)
613
    intrinsic_gas = Uint(intrinsic.regular) + Uint(intrinsic.state)
614
    if intrinsic_gas > tx.gas:
615
        raise InsufficientTransactionGasError("Insufficient intrinsic gas")
616
    if intrinsic.calldata_floor > tx.gas:
617
        raise InsufficientTransactionGasError("Insufficient calldata floor")
618
    if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
619
        raise InitCodeTooLargeError("Code size too large")
620
    if intrinsic.regular > TX_MAX_GAS_LIMIT:
621
        raise InsufficientTransactionGasError(
622
            "Intrinsic regular gas exceeds TX_MAX_GAS_LIMIT"
623
        )
624
    if intrinsic.calldata_floor > TX_MAX_GAS_LIMIT:
625
        raise InsufficientTransactionGasError(
626
            "Intrinsic calldata floor exceeds TX_MAX_GAS_LIMIT"
627
        )
628
    if U256(tx.nonce) >= U256(U64.MAX_VALUE):
629
        raise NonceOverflowError("Nonce too high")
630
631
    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. Sender cost (TX_BASE).

  2. Recipient cost (COLD_ACCOUNT_ACCESS for a non-self-transfer call, or CREATE_ACCESS plus NEW_ACCOUNT state gas for a contract creation).

  3. Value cost (TRANSFER_LOG_COST, plus TX_VALUE_COST for a non-self-transfer call) when tx.value > 0.

  4. Calldata cost (zero and non-zero bytes).

  5. Access list entries (if applicable).

  6. Authorizations (if applicable).

Self-transfers (sender == tx.to) skip the recipient and value charges.

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

def calculate_intrinsic_cost(tx: Transaction, ​​sender: Address) -> IntrinsicGasCost:
637
    <snip>
667
    from .vm.gas import (
668
        GasCosts,
669
        StateGasCosts,
670
        init_code_cost,
671
    )
672
673
    tokens_in_calldata = count_tokens_in_data(tx.data)
674
675
    data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD
676
677
    is_create = tx.to == Bytes0(b"")
678
    is_self_transfer = tx.to == sender
679
680
    recipient_regular_gas = Uint(0)
681
    recipient_state_gas = Uint(0)
682
    if is_create:
683
        recipient_regular_gas = GasCosts.CREATE_ACCESS + init_code_cost(
684
            ulen(tx.data)
685
        )
686
        recipient_state_gas = StateGasCosts.NEW_ACCOUNT
687
        if tx.value > U256(0):
688
            recipient_regular_gas += GasCosts.TRANSFER_LOG_COST
689
    elif not is_self_transfer:
690
        recipient_regular_gas = GasCosts.COLD_ACCOUNT_ACCESS
691
        if tx.value > U256(0):
692
            recipient_regular_gas += (
693
                GasCosts.TRANSFER_LOG_COST + GasCosts.TX_VALUE_COST
694
            )
695
696
    access_list_cost = Uint(0)
697
    tokens_in_access_list = Uint(0)
698
    if has_access_list(tx):
699
        for access in tx.access_list:
700
            access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS
701
            access_list_cost += (
702
                ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY
703
            )
704
            tokens_in_access_list += ACCESS_LIST_ADDRESS_FLOOR_TOKENS
705
            tokens_in_access_list += (
706
                ulen(access.slots) * ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS
707
            )
708
709
    # Data token floor cost for access list bytes.
710
    access_list_cost += tokens_in_access_list * GasCosts.TX_DATA_TOKEN_FLOOR
711
712
    auth_regular_gas = Uint(0)
713
    auth_state_gas = Uint(0)
714
    if isinstance(tx, SetCodeTransaction):
715
        auth_regular_gas = (
716
            GasCosts.ACCOUNT_WRITE + GasCosts.REGULAR_PER_AUTH_BASE_COST
717
        ) * ulen(tx.authorizations)
718
        auth_state_gas = (
719
            StateGasCosts.NEW_ACCOUNT + StateGasCosts.AUTH_BASE
720
        ) * ulen(tx.authorizations)
721
722
    # EIP-7976 floor tokens: all calldata bytes count uniformly.
723
    floor_tokens_in_calldata = ulen(tx.data) * GasCosts.TX_DATA_TOKEN_STANDARD
724
725
    # Total floor tokens.
726
    total_floor_tokens = floor_tokens_in_calldata + tokens_in_access_list
727
728
    # Floor gas cost (EIP-7623: minimum gas for data-heavy transactions).
729
    data_floor_gas_cost = (
730
        total_floor_tokens * GasCosts.TX_DATA_TOKEN_FLOOR + GasCosts.TX_BASE
731
    )
732
733
    intrinsic_regular_gas = (
734
        GasCosts.TX_BASE
735
        + data_cost
736
        + recipient_regular_gas
737
        + access_list_cost
738
        + auth_regular_gas
739
    )
740
741
    intrinsic_state_gas = recipient_state_gas + auth_state_gas
742
743
    return IntrinsicGasCost(
744
        regular=RegularGas(intrinsic_regular_gas),
745
        state=StateGas(intrinsic_state_gas),
746
        calldata_floor=RegularGas(data_floor_gas_cost),
747
    )

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:
751
    <snip>
756
    num_zeros = Uint(data.count(0))
757
    num_non_zeros = ulen(data) - num_zeros
758
759
    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:
763
    <snip>
768
    if isinstance(tx, LegacyTransaction):
769
        if tx.v == 27 or tx.v == 28:
770
            return None
771
772
        if tx.v < U256(35):
773
            raise InvalidSignatureError("bad v")
774
775
        return U64((tx.v - U256(35)) >> U256(1))
776
    else:
777
        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:
781
    <snip>
794
    r, s = tx.r, tx.s
795
    if U256(0) >= r or r >= SECP256K1N:
796
        raise InvalidSignatureError("bad r")
797
    if U256(0) >= s or s > SECP256K1N // U256(2):
798
        raise InvalidSignatureError("bad s")
799
800
    if isinstance(tx, LegacyTransaction):
801
        v = tx.v
802
        if v == 27 or v == 28:
803
            public_key = secp256k1_recover(
804
                r, s, v - U256(27), signing_hash_pre155(tx)
805
            )
806
        else:
807
            assert v >= U256(35), "call chain_id before recover_sender"
808
            tx_chain_id = U64((v - U256(35)) >> U256(1))
809
            v = (v - U256(35)) & U256(1)
810
            public_key = secp256k1_recover(
811
                r,
812
                s,
813
                v,
814
                signing_hash_155(tx, tx_chain_id),
815
            )
816
    elif isinstance(tx, AccessListTransaction):
817
        if tx.y_parity not in (U256(0), U256(1)):
818
            raise InvalidSignatureError("bad y_parity")
819
        public_key = secp256k1_recover(
820
            r, s, tx.y_parity, signing_hash_2930(tx)
821
        )
822
    elif isinstance(tx, FeeMarketTransaction):
823
        if tx.y_parity not in (U256(0), U256(1)):
824
            raise InvalidSignatureError("bad y_parity")
825
        public_key = secp256k1_recover(
826
            r, s, tx.y_parity, signing_hash_1559(tx)
827
        )
828
    elif isinstance(tx, BlobTransaction):
829
        if tx.y_parity not in (U256(0), U256(1)):
830
            raise InvalidSignatureError("bad y_parity")
831
        public_key = secp256k1_recover(
832
            r, s, tx.y_parity, signing_hash_4844(tx)
833
        )
834
    elif isinstance(tx, SetCodeTransaction):
835
        if tx.y_parity not in (U256(0), U256(1)):
836
            raise InvalidSignatureError("bad y_parity")
837
        public_key = secp256k1_recover(
838
            r, s, tx.y_parity, signing_hash_7702(tx)
839
        )
840
841
    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:
845
    <snip>
854
    return keccak256(
855
        rlp.encode(
856
            (
857
                tx.nonce,
858
                tx.gas_price,
859
                tx.gas,
860
                tx.to,
861
                tx.value,
862
                tx.data,
863
            )
864
        )
865
    )

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:
869
    <snip>
877
    return keccak256(
878
        rlp.encode(
879
            (
880
                tx.nonce,
881
                tx.gas_price,
882
                tx.gas,
883
                tx.to,
884
                tx.value,
885
                tx.data,
886
                chain_id,
887
                Uint(0),
888
                Uint(0),
889
            )
890
        )
891
    )

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:
895
    <snip>
903
    return keccak256(
904
        b"\x01"
905
        + rlp.encode(
906
            (
907
                tx.chain_id,
908
                tx.nonce,
909
                tx.gas_price,
910
                tx.gas,
911
                tx.to,
912
                tx.value,
913
                tx.data,
914
                tx.access_list,
915
            )
916
        )
917
    )

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:
921
    <snip>
929
    return keccak256(
930
        b"\x02"
931
        + rlp.encode(
932
            (
933
                tx.chain_id,
934
                tx.nonce,
935
                tx.max_priority_fee_per_gas,
936
                tx.max_fee_per_gas,
937
                tx.gas,
938
                tx.to,
939
                tx.value,
940
                tx.data,
941
                tx.access_list,
942
            )
943
        )
944
    )

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:
948
    <snip>
956
    return keccak256(
957
        b"\x03"
958
        + rlp.encode(
959
            (
960
                tx.chain_id,
961
                tx.nonce,
962
                tx.max_priority_fee_per_gas,
963
                tx.max_fee_per_gas,
964
                tx.gas,
965
                tx.to,
966
                tx.value,
967
                tx.data,
968
                tx.access_list,
969
                tx.max_fee_per_blob_gas,
970
                tx.blob_versioned_hashes,
971
            )
972
        )
973
    )

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:
977
    <snip>
985
    return keccak256(
986
        b"\x04"
987
        + rlp.encode(
988
            (
989
                tx.chain_id,
990
                tx.nonce,
991
                tx.max_priority_fee_per_gas,
992
                tx.max_fee_per_gas,
993
                tx.gas,
994
                tx.to,
995
                tx.value,
996
                tx.data,
997
                tx.access_list,
998
                tx.authorizations,
999
            )
1000
        )
1001
    )

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:
1005
    <snip>
1013
    assert isinstance(tx, (LegacyTransaction, Bytes))
1014
    if isinstance(tx, LegacyTransaction):
1015
        return keccak256(rlp.encode(tx))
1016
    else:
1017
        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]:
1023
    <snip>
1028
    return isinstance(
1029
        tx,
1030
        AccessListCapableTransaction,
1031
    )