ethereum.forks.prague.transactionsethereum.forks.osaka.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.

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

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

44
STANDARD_CALLDATA_TOKEN_COST = Uint(4)

TX_CREATE_COST

Additional gas cost for creating a new contract.

52
TX_CREATE_COST = Uint(32000)

TX_ACCESS_LIST_ADDRESS_COST

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

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

62
TX_ACCESS_LIST_STORAGE_KEY_COST = Uint(1900)

TX_MAX_GAS_LIMIT

67
TX_MAX_GAS_LIMIT = Uint(16_777_216)

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.

70
@slotted_freezable
71
@dataclass
class LegacyTransaction:

nonce

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

84
    nonce: U256

gas_price

The price of gas for this transaction, in wei.

89
    gas_price: Uint

gas

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

94
    gas: Uint

to

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

99
    to: Bytes0 | Address

value

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

105
    value: U256

data

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

110
    data: Bytes

v

The recovery id of the signature.

116
    v: U256

r

The first part of the signature.

121
    r: U256

s

The second part of the signature.

126
    s: U256

Access

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

132
@slotted_freezable
133
@dataclass
class Access:

account

The address of the account that is accessed.

140
    account: Address

slots

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

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

151
@slotted_freezable
152
@dataclass
class AccessListTransaction:

chain_id

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

164
    chain_id: U64

nonce

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

169
    nonce: U256

gas_price

The price of gas for this transaction.

174
    gas_price: Uint

gas

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

179
    gas: Uint

to

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

184
    to: Bytes0 | Address

value

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

190
    value: U256

data

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

195
    data: Bytes

access_list

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

201
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

207
    y_parity: U256

r

The first part of the signature.

212
    r: U256

s

The second part of the signature.

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

223
@slotted_freezable
224
@dataclass
class FeeMarketTransaction:

chain_id

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

235
    chain_id: U64

nonce

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

240
    nonce: U256

max_priority_fee_per_gas

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

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

250
    max_fee_per_gas: Uint

gas

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

256
    gas: Uint

to

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

261
    to: Bytes0 | Address

value

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

267
    value: U256

data

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

272
    data: Bytes

access_list

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

278
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

284
    y_parity: U256

r

The first part of the signature.

289
    r: U256

s

The second part of the signature.

294
    s: U256

BlobTransaction

The transaction type added in EIP-4844.

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

300
@slotted_freezable
301
@dataclass
class BlobTransaction:

chain_id

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

312
    chain_id: U64

nonce

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

317
    nonce: U256

max_priority_fee_per_gas

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

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

327
    max_fee_per_gas: Uint

gas

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

333
    gas: Uint

to

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

338
    to: Address

value

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

344
    value: U256

data

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

349
    data: Bytes

access_list

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

355
    access_list: Tuple[Access, ...]

max_fee_per_blob_gas

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

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

366
    blob_versioned_hashes: Tuple[VersionedHash, ...]

y_parity

The recovery id of the signature.

372
    y_parity: U256

r

The first part of the signature.

377
    r: U256

s

The second part of the signature.

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

388
@slotted_freezable
389
@dataclass
class SetCodeTransaction:

chain_id

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

400
    chain_id: U64

nonce

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

405
    nonce: U64

max_priority_fee_per_gas

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

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

415
    max_fee_per_gas: Uint

gas

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

421
    gas: Uint

to

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

426
    to: Address

value

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

432
    value: U256

data

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

437
    data: Bytes

access_list

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

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

449
    authorizations: Tuple[Authorization, ...]

y_parity

The recovery id of the signature.

455
    y_parity: U256

r

The first part of the signature.

460
    r: U256

s

The second part of the signature.

465
    s: U256

Transaction

Union type representing any valid transaction type.

471
Transaction = (
472
    LegacyTransaction
473
    | AccessListTransaction
474
    | FeeMarketTransaction
475
    | BlobTransaction
476
    | SetCodeTransaction
477
)

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

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

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

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

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

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

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

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:
875
    """
876
    Compute the hash of a transaction.
877
878
    This function takes a transaction as a parameter and returns the
879
    keccak256 hash of the transaction. It can handle both legacy transactions
880
    and typed transactions (`AccessListTransaction`, `FeeMarketTransaction`,
881
    etc.).
882
    """
883
    assert isinstance(tx, (LegacyTransaction, Bytes))
884
    if isinstance(tx, LegacyTransaction):
885
        return keccak256(rlp.encode(tx))
886
    else:
887
        return keccak256(tx)