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

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

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

40
STANDARD_CALLDATA_TOKEN_COST = Uint(4)

TX_CREATE_COST

Additional gas cost for creating a new contract.

48
TX_CREATE_COST = Uint(32000)

TX_ACCESS_LIST_ADDRESS_COST

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

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

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

64
@slotted_freezable
65
@dataclass
class LegacyTransaction:

nonce

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

78
    nonce: U256

gas_price

The price of gas for this transaction, in wei.

83
    gas_price: Uint

gas

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

88
    gas: Uint

to

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

93
    to: Bytes0 | Address

value

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

99
    value: U256

data

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

104
    data: Bytes

v

The recovery id of the signature.

110
    v: U256

r

The first part of the signature.

115
    r: U256

s

The second part of the signature.

120
    s: U256

Access

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

126
@slotted_freezable
127
@dataclass
class Access:

account

The address of the account that is accessed.

134
    account: Address

slots

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

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

145
@slotted_freezable
146
@dataclass
class AccessListTransaction:

chain_id

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

158
    chain_id: U64

nonce

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

163
    nonce: U256

gas_price

The price of gas for this transaction.

168
    gas_price: Uint

gas

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

173
    gas: Uint

to

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

178
    to: Bytes0 | Address

value

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

184
    value: U256

data

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

189
    data: Bytes

access_list

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

195
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

201
    y_parity: U256

r

The first part of the signature.

206
    r: U256

s

The second part of the signature.

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

217
@slotted_freezable
218
@dataclass
class FeeMarketTransaction:

chain_id

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

229
    chain_id: U64

nonce

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

234
    nonce: U256

max_priority_fee_per_gas

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

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

244
    max_fee_per_gas: Uint

gas

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

250
    gas: Uint

to

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

255
    to: Bytes0 | Address

value

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

261
    value: U256

data

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

266
    data: Bytes

access_list

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

272
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

278
    y_parity: U256

r

The first part of the signature.

283
    r: U256

s

The second part of the signature.

288
    s: U256

BlobTransaction

The transaction type added in EIP-4844.

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

294
@slotted_freezable
295
@dataclass
class BlobTransaction:

chain_id

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

306
    chain_id: U64

nonce

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

311
    nonce: U256

max_priority_fee_per_gas

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

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

321
    max_fee_per_gas: Uint

gas

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

327
    gas: Uint

to

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

332
    to: Address

value

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

338
    value: U256

data

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

343
    data: Bytes

access_list

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

349
    access_list: Tuple[Access, ...]

max_fee_per_blob_gas

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

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

360
    blob_versioned_hashes: Tuple[VersionedHash, ...]

y_parity

The recovery id of the signature.

366
    y_parity: U256

r

The first part of the signature.

371
    r: U256

s

The second part of the signature.

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

382
@slotted_freezable
383
@dataclass
class SetCodeTransaction:

chain_id

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

394
    chain_id: U64

nonce

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

399
    nonce: U64

max_priority_fee_per_gas

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

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

409
    max_fee_per_gas: Uint

gas

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

415
    gas: Uint

to

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

420
    to: Address

value

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

426
    value: U256

data

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

431
    data: Bytes

access_list

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

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

443
    authorizations: Tuple[Authorization, ...]

y_parity

The recovery id of the signature.

449
    y_parity: U256

r

The first part of the signature.

454
    r: U256

s

The second part of the signature.

459
    s: U256

Transaction

Union type representing any valid transaction type.

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

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:
478
    """
479
    Encode a transaction into its RLP or typed transaction format.
480
    Needed because non-legacy transactions aren't RLP.
481
482
    Legacy transactions are returned as-is, while other transaction types
483
    are prefixed with their type identifier and RLP encoded.
484
    """
485
    if isinstance(tx, LegacyTransaction):
486
        return tx
487
    elif isinstance(tx, AccessListTransaction):
488
        return b"\x01" + rlp.encode(tx)
489
    elif isinstance(tx, FeeMarketTransaction):
490
        return b"\x02" + rlp.encode(tx)
491
    elif isinstance(tx, BlobTransaction):
492
        return b"\x03" + rlp.encode(tx)
493
    elif isinstance(tx, SetCodeTransaction):
494
        return b"\x04" + rlp.encode(tx)
495
    else:
496
        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:
500
    """
501
    Decode a transaction from its RLP or typed transaction format.
502
    Needed because non-legacy transactions aren't RLP.
503
504
    Legacy transactions are returned as-is, while other transaction types
505
    are decoded based on their type identifier prefix.
506
    """
507
    if isinstance(tx, Bytes):
508
        if tx[0] == 1:
509
            return rlp.decode_to(AccessListTransaction, tx[1:])
510
        elif tx[0] == 2:
511
            return rlp.decode_to(FeeMarketTransaction, tx[1:])
512
        elif tx[0] == 3:
513
            return rlp.decode_to(BlobTransaction, tx[1:])
514
        elif tx[0] == 4:
515
            return rlp.decode_to(SetCodeTransaction, tx[1:])
516
        else:
517
            raise TransactionTypeError(tx[0])
518
    else:
519
        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]:
523
    """
524
    Verifies a transaction.
525
526
    The gas in a transaction gets used to pay for the intrinsic cost of
527
    operations, therefore if there is insufficient gas then it would not
528
    be possible to execute a transaction and it will be declared invalid.
529
530
    Additionally, the nonce of a transaction must not equal or exceed the
531
    limit defined in [EIP-2681].
532
    In practice, defining the limit as ``2**64-1`` has no impact because
533
    sending ``2**64-1`` transactions is improbable. It's not strictly
534
    impossible though, ``2**64-1`` transactions is the entire capacity of the
535
    Ethereum blockchain at 2022 gas limits for a little over 22 years.
536
537
    Also, the code size of a contract creation transaction must be within
538
    limits of the protocol.
539
540
    This function takes a transaction as a parameter and returns the intrinsic
541
    gas cost and the minimum calldata gas cost for the transaction after
542
    validation. It throws an `InsufficientTransactionGasError` exception if
543
    the transaction does not provide enough gas to cover the intrinsic cost,
544
    and a `NonceOverflowError` exception if the nonce is greater than
545
    `2**64 - 2`. It also raises an `InitCodeTooLargeError` if the code size of
546
    a contract creation transaction exceeds the maximum allowed size.
547
548
    [EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
549
    [EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623
550
    """
551
    from .vm.interpreter import MAX_INIT_CODE_SIZE
552
553
    intrinsic_gas, calldata_floor_gas_cost = calculate_intrinsic_cost(tx)
554
    if max(intrinsic_gas, calldata_floor_gas_cost) > tx.gas:
555
        raise InsufficientTransactionGasError("Insufficient gas")
556
    if U256(tx.nonce) >= U256(U64.MAX_VALUE):
557
        raise NonceOverflowError("Nonce too high")
558
    if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
559
        raise InitCodeTooLargeError("Code size too large")
560
561
    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]:
565
    """
566
    Calculates the gas that is charged before execution is started.
567
568
    The intrinsic cost of the transaction is charged before execution has
569
    begun. Functions/operations in the EVM cost money to execute so this
570
    intrinsic cost is for the operations that need to be paid for as part of
571
    the transaction. Data transfer, for example, is part of this intrinsic
572
    cost. It costs ether to send data over the wire and that ether is
573
    accounted for in the intrinsic cost calculated in this function. This
574
    intrinsic cost must be calculated and paid for before execution in order
575
    for all operations to be implemented.
576
577
    The intrinsic cost includes:
578
    1. Base cost (`TX_BASE_COST`)
579
    2. Cost for data (zero and non-zero bytes)
580
    3. Cost for contract creation (if applicable)
581
    4. Cost for access list entries (if applicable)
582
    5. Cost for authorizations (if applicable)
583
584
585
    This function takes a transaction as a parameter and returns the intrinsic
586
    gas cost of the transaction and the minimum gas cost used by the
587
    transaction based on the calldata size.
588
    """
589
    from .vm.eoa_delegation import PER_EMPTY_ACCOUNT_COST
590
    from .vm.gas import init_code_cost
591
592
    zero_bytes = 0
593
    for byte in tx.data:
594
        if byte == 0:
595
            zero_bytes += 1
596
597
    tokens_in_calldata = Uint(zero_bytes + (len(tx.data) - zero_bytes) * 4)
598
    # EIP-7623 floor price (note: no EVM costs)
599
    calldata_floor_gas_cost = (
600
        tokens_in_calldata * FLOOR_CALLDATA_COST + TX_BASE_COST
601
    )
602
603
    data_cost = tokens_in_calldata * STANDARD_CALLDATA_TOKEN_COST
604
605
    if tx.to == Bytes0(b""):
606
        create_cost = TX_CREATE_COST + init_code_cost(ulen(tx.data))
607
    else:
608
        create_cost = Uint(0)
609
610
    access_list_cost = Uint(0)
611
    if isinstance(
612
        tx,
613
        (
614
            AccessListTransaction,
615
            FeeMarketTransaction,
616
            BlobTransaction,
617
            SetCodeTransaction,
618
        ),
619
    ):
620
        for access in tx.access_list:
621
            access_list_cost += TX_ACCESS_LIST_ADDRESS_COST
622
            access_list_cost += (
623
                ulen(access.slots) * TX_ACCESS_LIST_STORAGE_KEY_COST
624
            )
625
626
    auth_cost = Uint(0)
627
    if isinstance(tx, SetCodeTransaction):
628
        auth_cost += Uint(PER_EMPTY_ACCOUNT_COST * len(tx.authorizations))
629
630
    return (
631
        Uint(
632
            TX_BASE_COST
633
            + data_cost
634
            + create_cost
635
            + access_list_cost
636
            + auth_cost
637
        ),
638
        calldata_floor_gas_cost,
639
    )

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

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

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

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

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

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

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