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

TX_BASE_COST

Base cost of a transaction in gas units. This is the minimum amount of gas required to execute a transaction.

25
TX_BASE_COST = Uint(21000)

FLOOR_CALLDATA_COST

Minimum gas cost per byte of calldata as per EIP-7623. Used to calculate the minimum gas cost for transactions that include calldata.

31
FLOOR_CALLDATA_COST = Uint(10)

STANDARD_CALLDATA_TOKEN_COST

Gas cost per byte of calldata as per EIP-7623. Used to calculate the gas cost for transactions that include calldata.

39
STANDARD_CALLDATA_TOKEN_COST = Uint(4)

TX_CREATE_COST

Additional gas cost for creating a new contract.

47
TX_CREATE_COST = Uint(32000)

TX_ACCESS_LIST_ADDRESS_COST

Gas cost for including an address in the access list of a transaction.

52
TX_ACCESS_LIST_ADDRESS_COST = Uint(2400)

TX_ACCESS_LIST_STORAGE_KEY_COST

Gas cost for including a storage key in the access list of a transaction.

57
TX_ACCESS_LIST_STORAGE_KEY_COST = Uint(1900)

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.

63
@slotted_freezable
64
@dataclass
class LegacyTransaction:

nonce

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

77
    nonce: U256

gas_price

The price of gas for this transaction, in wei.

82
    gas_price: Uint

gas

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

87
    gas: Uint

to

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

92
    to: Bytes0 | Address

value

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

98
    value: U256

data

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

103
    data: Bytes

v

The recovery id of the signature.

109
    v: U256

r

The first part of the signature.

114
    r: U256

s

The second part of the signature.

119
    s: U256

Access

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

125
@slotted_freezable
126
@dataclass
class Access:

account

The address of the account that is accessed.

133
    account: Address

slots

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

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

144
@slotted_freezable
145
@dataclass
class AccessListTransaction:

chain_id

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

157
    chain_id: U64

nonce

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

162
    nonce: U256

gas_price

The price of gas for this transaction.

167
    gas_price: Uint

gas

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

172
    gas: Uint

to

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

177
    to: Bytes0 | Address

value

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

183
    value: U256

data

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

188
    data: Bytes

access_list

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

194
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

200
    y_parity: U256

r

The first part of the signature.

205
    r: U256

s

The second part of the signature.

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

216
@slotted_freezable
217
@dataclass
class FeeMarketTransaction:

chain_id

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

228
    chain_id: U64

nonce

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

233
    nonce: U256

max_priority_fee_per_gas

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

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

243
    max_fee_per_gas: Uint

gas

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

249
    gas: Uint

to

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

254
    to: Bytes0 | Address

value

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

260
    value: U256

data

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

265
    data: Bytes

access_list

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

271
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

277
    y_parity: U256

r

The first part of the signature.

282
    r: U256

s

The second part of the signature.

287
    s: U256

BlobTransaction

The transaction type added in EIP-4844.

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

293
@slotted_freezable
294
@dataclass
class BlobTransaction:

chain_id

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

305
    chain_id: U64

nonce

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

310
    nonce: U256

max_priority_fee_per_gas

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

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

320
    max_fee_per_gas: Uint

gas

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

326
    gas: Uint

to

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

331
    to: Address

value

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

337
    value: U256

data

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

342
    data: Bytes

access_list

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

348
    access_list: Tuple[Access, ...]

max_fee_per_blob_gas

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

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

359
    blob_versioned_hashes: Tuple[VersionedHash, ...]

y_parity

The recovery id of the signature.

365
    y_parity: U256

r

The first part of the signature.

370
    r: U256

s

The second part of the signature.

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

381
@slotted_freezable
382
@dataclass
class SetCodeTransaction:

chain_id

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

393
    chain_id: U64

nonce

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

398
    nonce: U64

max_priority_fee_per_gas

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

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

408
    max_fee_per_gas: Uint

gas

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

414
    gas: Uint

to

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

419
    to: Address

value

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

425
    value: U256

data

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

430
    data: Bytes

access_list

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

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

442
    authorizations: Tuple[Authorization, ...]

y_parity

The recovery id of the signature.

448
    y_parity: U256

r

The first part of the signature.

453
    r: U256

s

The second part of the signature.

458
    s: U256

Transaction

Union type representing any valid transaction type.

464
Transaction = (
465
    LegacyTransaction
466
    | AccessListTransaction
467
    | FeeMarketTransaction
468
    | BlobTransaction
469
    | SetCodeTransaction
470
)

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:
477
    """
478
    Encode a transaction into its RLP or typed transaction format.
479
    Needed because non-legacy transactions aren't RLP.
480
481
    Legacy transactions are returned as-is, while other transaction types
482
    are prefixed with their type identifier and RLP encoded.
483
    """
484
    if isinstance(tx, LegacyTransaction):
485
        return tx
486
    elif isinstance(tx, AccessListTransaction):
487
        return b"\x01" + rlp.encode(tx)
488
    elif isinstance(tx, FeeMarketTransaction):
489
        return b"\x02" + rlp.encode(tx)
490
    elif isinstance(tx, BlobTransaction):
491
        return b"\x03" + rlp.encode(tx)
492
    elif isinstance(tx, SetCodeTransaction):
493
        return b"\x04" + rlp.encode(tx)
494
    else:
495
        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 types are decoded based on their type identifier prefix.

def decode_transaction(tx: LegacyTransaction | Bytes) -> Transaction:
499
    """
500
    Decode a transaction from its RLP or typed transaction format.
501
    Needed because non-legacy transactions aren't RLP.
502
503
    Legacy transactions are returned as-is, while other transaction types
504
    are decoded based on their type identifier prefix.
505
    """
506
    if isinstance(tx, Bytes):
507
        if tx[0] == 1:
508
            return rlp.decode_to(AccessListTransaction, tx[1:])
509
        elif tx[0] == 2:
510
            return rlp.decode_to(FeeMarketTransaction, tx[1:])
511
        elif tx[0] == 3:
512
            return rlp.decode_to(BlobTransaction, tx[1:])
513
        elif tx[0] == 4:
514
            return rlp.decode_to(SetCodeTransaction, tx[1:])
515
        else:
516
            raise TransactionTypeError(tx[0])
517
    else:
518
        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 intrinsic gas cost and the minimum calldata gas cost 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 is greater than 2**64 - 2. It also raises an InitCodeTooLargeError if the code size of a contract creation transaction exceeds the maximum allowed size.

def validate_transaction(tx: Transaction) -> Tuple[Uint, Uint]:
522
    """
523
    Verifies a transaction.
524
525
    The gas in a transaction gets used to pay for the intrinsic cost of
526
    operations, therefore if there is insufficient gas then it would not
527
    be possible to execute a transaction and it will be declared invalid.
528
529
    Additionally, the nonce of a transaction must not equal or exceed the
530
    limit defined in [EIP-2681].
531
    In practice, defining the limit as ``2**64-1`` has no impact because
532
    sending ``2**64-1`` transactions is improbable. It's not strictly
533
    impossible though, ``2**64-1`` transactions is the entire capacity of the
534
    Ethereum blockchain at 2022 gas limits for a little over 22 years.
535
536
    Also, the code size of a contract creation transaction must be within
537
    limits of the protocol.
538
539
    This function takes a transaction as a parameter and returns the intrinsic
540
    gas cost and the minimum calldata gas cost for the transaction after
541
    validation. It throws an `InsufficientTransactionGasError` exception if
542
    the transaction does not provide enough gas to cover the intrinsic cost,
543
    and a `NonceOverflowError` exception if the nonce is greater than
544
    `2**64 - 2`. It also raises an `InitCodeTooLargeError` if the code size of
545
    a contract creation transaction exceeds the maximum allowed size.
546
547
    [EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
548
    [EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623
549
    """
550
    from .vm.interpreter import MAX_INIT_CODE_SIZE
551
552
    intrinsic_gas, calldata_floor_gas_cost = calculate_intrinsic_cost(tx)
553
    if max(intrinsic_gas, calldata_floor_gas_cost) > tx.gas:
554
        raise InsufficientTransactionGasError("Insufficient gas")
555
    if U256(tx.nonce) >= U256(U64.MAX_VALUE):
556
        raise NonceOverflowError("Nonce too high")
557
    if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
558
        raise InitCodeTooLargeError("Code size too large")
559
560
    return intrinsic_gas, calldata_floor_gas_cost

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_COST)

  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 intrinsic gas cost of the transaction and the minimum gas cost used by the transaction based on the calldata size.

def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
564
    """
565
    Calculates the gas that is charged before execution is started.
566
567
    The intrinsic cost of the transaction is charged before execution has
568
    begun. Functions/operations in the EVM cost money to execute so this
569
    intrinsic cost is for the operations that need to be paid for as part of
570
    the transaction. Data transfer, for example, is part of this intrinsic
571
    cost. It costs ether to send data over the wire and that ether is
572
    accounted for in the intrinsic cost calculated in this function. This
573
    intrinsic cost must be calculated and paid for before execution in order
574
    for all operations to be implemented.
575
576
    The intrinsic cost includes:
577
    1. Base cost (`TX_BASE_COST`)
578
    2. Cost for data (zero and non-zero bytes)
579
    3. Cost for contract creation (if applicable)
580
    4. Cost for access list entries (if applicable)
581
    5. Cost for authorizations (if applicable)
582
583
584
    This function takes a transaction as a parameter and returns the intrinsic
585
    gas cost of the transaction and the minimum gas cost used by the
586
    transaction based on the calldata size.
587
    """
588
    from .vm.eoa_delegation import PER_EMPTY_ACCOUNT_COST
589
    from .vm.gas import init_code_cost
590
591
    zero_bytes = 0
592
    for byte in tx.data:
593
        if byte == 0:
594
            zero_bytes += 1
595
596
    tokens_in_calldata = Uint(zero_bytes + (len(tx.data) - zero_bytes) * 4)
597
    # EIP-7623 floor price (note: no EVM costs)
598
    calldata_floor_gas_cost = (
599
        tokens_in_calldata * FLOOR_CALLDATA_COST + TX_BASE_COST
600
    )
601
602
    data_cost = tokens_in_calldata * STANDARD_CALLDATA_TOKEN_COST
603
604
    if tx.to == Bytes0(b""):
605
        create_cost = TX_CREATE_COST + init_code_cost(ulen(tx.data))
606
    else:
607
        create_cost = Uint(0)
608
609
    access_list_cost = Uint(0)
610
    if isinstance(
611
        tx,
612
        (
613
            AccessListTransaction,
614
            FeeMarketTransaction,
615
            BlobTransaction,
616
            SetCodeTransaction,
617
        ),
618
    ):
619
        for access in tx.access_list:
620
            access_list_cost += TX_ACCESS_LIST_ADDRESS_COST
621
            access_list_cost += (
622
                ulen(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST
623
            )
624
625
    auth_cost = Uint(0)
626
    if isinstance(tx, SetCodeTransaction):
627
        auth_cost += Uint(PER_EMPTY_ACCOUNT_COST * len(tx.authorizations))
628
629
    return (
630
        Uint(
631
            TX_BASE_COST
632
            + data_cost
633
            + create_cost
634
            + access_list_cost
635
            + auth_cost
636
        ),
637
        calldata_floor_gas_cost,
638
    )

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(chain_id: U64, ​​tx: Transaction) -> Address:
642
    """
643
    Extracts the sender address from a transaction.
644
645
    The v, r, and s values are the three parts that make up the signature
646
    of a transaction. In order to recover the sender of a transaction the two
647
    components needed are the signature (``v``, ``r``, and ``s``) and the
648
    signing hash of the transaction. The sender's public key can be obtained
649
    with these two values and therefore the sender address can be retrieved.
650
651
    This function takes chain_id and a transaction as parameters and returns
652
    the address of the sender of the transaction. It raises an
653
    `InvalidSignatureError` if the signature values (r, s, v) are invalid.
654
    """
655
    r, s = tx.r, tx.s
656
    if U256(0) >= r or r >= SECP256K1N:
657
        raise InvalidSignatureError("bad r")
658
    if U256(0) >= s or s > SECP256K1N // U256(2):
659
        raise InvalidSignatureError("bad s")
660
661
    if isinstance(tx, LegacyTransaction):
662
        v = tx.v
663
        if v == 27 or v == 28:
664
            public_key = secp256k1_recover(
665
                r, s, v - U256(27), signing_hash_pre155(tx)
666
            )
667
        else:
668
            chain_id_x2 = U256(chain_id) * U256(2)
669
            if v != U256(35) + chain_id_x2 and v != U256(36) + chain_id_x2:
670
                raise InvalidSignatureError("bad v")
671
            public_key = secp256k1_recover(
672
                r,
673
                s,
674
                v - U256(35) - chain_id_x2,
675
                signing_hash_155(tx, chain_id),
676
            )
677
    elif isinstance(tx, AccessListTransaction):
678
        if tx.y_parity not in (U256(0), U256(1)):
679
            raise InvalidSignatureError("bad y_parity")
680
        public_key = secp256k1_recover(
681
            r, s, tx.y_parity, signing_hash_2930(tx)
682
        )
683
    elif isinstance(tx, FeeMarketTransaction):
684
        if tx.y_parity not in (U256(0), U256(1)):
685
            raise InvalidSignatureError("bad y_parity")
686
        public_key = secp256k1_recover(
687
            r, s, tx.y_parity, signing_hash_1559(tx)
688
        )
689
    elif isinstance(tx, BlobTransaction):
690
        if tx.y_parity not in (U256(0), U256(1)):
691
            raise InvalidSignatureError("bad y_parity")
692
        public_key = secp256k1_recover(
693
            r, s, tx.y_parity, signing_hash_4844(tx)
694
        )
695
    elif isinstance(tx, SetCodeTransaction):
696
        if tx.y_parity not in (U256(0), U256(1)):
697
            raise InvalidSignatureError("bad y_parity")
698
        public_key = secp256k1_recover(
699
            r, s, tx.y_parity, signing_hash_7702(tx)
700
        )
701
702
    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:
706
    """
707
    Compute the hash of a transaction used in a legacy (pre [EIP-155])
708
    signature.
709
710
    This function takes a legacy transaction as a parameter and returns the
711
    signing hash of the transaction.
712
713
    [EIP-155]: https://eips.ethereum.org/EIPS/eip-155
714
    """
715
    return keccak256(
716
        rlp.encode(
717
            (
718
                tx.nonce,
719
                tx.gas_price,
720
                tx.gas,
721
                tx.to,
722
                tx.value,
723
                tx.data,
724
            )
725
        )
726
    )

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:
730
    """
731
    Compute the hash of a transaction used in a [EIP-155] signature.
732
733
    This function takes a legacy transaction and a chain ID as parameters
734
    and returns the hash of the transaction used in an [EIP-155] signature.
735
736
    [EIP-155]: https://eips.ethereum.org/EIPS/eip-155
737
    """
738
    return keccak256(
739
        rlp.encode(
740
            (
741
                tx.nonce,
742
                tx.gas_price,
743
                tx.gas,
744
                tx.to,
745
                tx.value,
746
                tx.data,
747
                chain_id,
748
                Uint(0),
749
                Uint(0),
750
            )
751
        )
752
    )

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:
756
    """
757
    Compute the hash of a transaction used in a [EIP-2930] signature.
758
759
    This function takes an access list transaction as a parameter
760
    and returns the hash of the transaction used in an [EIP-2930] signature.
761
762
    [EIP-2930]: https://eips.ethereum.org/EIPS/eip-2930
763
    """
764
    return keccak256(
765
        b"\x01"
766
        + rlp.encode(
767
            (
768
                tx.chain_id,
769
                tx.nonce,
770
                tx.gas_price,
771
                tx.gas,
772
                tx.to,
773
                tx.value,
774
                tx.data,
775
                tx.access_list,
776
            )
777
        )
778
    )

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:
782
    """
783
    Compute the hash of a transaction used in an [EIP-1559] signature.
784
785
    This function takes a fee market transaction as a parameter
786
    and returns the hash of the transaction used in an [EIP-1559] signature.
787
788
    [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
789
    """
790
    return keccak256(
791
        b"\x02"
792
        + rlp.encode(
793
            (
794
                tx.chain_id,
795
                tx.nonce,
796
                tx.max_priority_fee_per_gas,
797
                tx.max_fee_per_gas,
798
                tx.gas,
799
                tx.to,
800
                tx.value,
801
                tx.data,
802
                tx.access_list,
803
            )
804
        )
805
    )

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:
809
    """
810
    Compute the hash of a transaction used in an [EIP-4844] signature.
811
812
    This function takes a transaction as a parameter and returns the
813
    signing hash of the transaction used in an [EIP-4844] signature.
814
815
    [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
816
    """
817
    return keccak256(
818
        b"\x03"
819
        + rlp.encode(
820
            (
821
                tx.chain_id,
822
                tx.nonce,
823
                tx.max_priority_fee_per_gas,
824
                tx.max_fee_per_gas,
825
                tx.gas,
826
                tx.to,
827
                tx.value,
828
                tx.data,
829
                tx.access_list,
830
                tx.max_fee_per_blob_gas,
831
                tx.blob_versioned_hashes,
832
            )
833
        )
834
    )

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:
838
    """
839
    Compute the hash of a transaction used in a [EIP-7702] signature.
840
841
    This function takes a transaction as a parameter and returns the
842
    signing hash of the transaction used in a [EIP-7702] signature.
843
844
    [EIP-7702]: https://eips.ethereum.org/EIPS/eip-7702
845
    """
846
    return keccak256(
847
        b"\x04"
848
        + rlp.encode(
849
            (
850
                tx.chain_id,
851
                tx.nonce,
852
                tx.max_priority_fee_per_gas,
853
                tx.max_fee_per_gas,
854
                tx.gas,
855
                tx.to,
856
                tx.value,
857
                tx.data,
858
                tx.access_list,
859
                tx.authorizations,
860
            )
861
        )
862
    )

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:
866
    """
867
    Compute the hash of a transaction.
868
869
    This function takes a transaction as a parameter and returns the
870
    keccak256 hash of the transaction. It can handle both legacy transactions
871
    and typed transactions (`AccessListTransaction`, `FeeMarketTransaction`,
872
    etc.).
873
    """
874
    assert isinstance(tx, (LegacyTransaction, Bytes))
875
    if isinstance(tx, LegacyTransaction):
876
        return keccak256(rlp.encode(tx))
877
    else:
878
        return keccak256(tx)