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

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

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

43
STANDARD_CALLDATA_TOKEN_COST = Uint(4)

TX_CREATE_COST

Additional gas cost for creating a new contract.

51
TX_CREATE_COST = Uint(32000)

TX_ACCESS_LIST_ADDRESS_COST

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

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

61
TX_ACCESS_LIST_STORAGE_KEY_COST = Uint(1900)

TX_MAX_GAS_LIMIT

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

69
@slotted_freezable
70
@dataclass
class LegacyTransaction:

nonce

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

83
    nonce: U256

gas_price

The price of gas for this transaction, in wei.

88
    gas_price: Uint

gas

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

93
    gas: Uint

to

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

98
    to: Bytes0 | Address

value

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

104
    value: U256

data

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

109
    data: Bytes

v

The recovery id of the signature.

115
    v: U256

r

The first part of the signature.

120
    r: U256

s

The second part of the signature.

125
    s: U256

Access

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

131
@slotted_freezable
132
@dataclass
class Access:

account

The address of the account that is accessed.

139
    account: Address

slots

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

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

150
@slotted_freezable
151
@dataclass
class AccessListTransaction:

chain_id

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

163
    chain_id: U64

nonce

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

168
    nonce: U256

gas_price

The price of gas for this transaction.

173
    gas_price: Uint

gas

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

178
    gas: Uint

to

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

183
    to: Bytes0 | Address

value

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

189
    value: U256

data

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

194
    data: Bytes

access_list

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

200
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

206
    y_parity: U256

r

The first part of the signature.

211
    r: U256

s

The second part of the signature.

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

222
@slotted_freezable
223
@dataclass
class FeeMarketTransaction:

chain_id

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

234
    chain_id: U64

nonce

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

239
    nonce: U256

max_priority_fee_per_gas

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

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

249
    max_fee_per_gas: Uint

gas

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

255
    gas: Uint

to

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

260
    to: Bytes0 | Address

value

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

266
    value: U256

data

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

271
    data: Bytes

access_list

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

277
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

283
    y_parity: U256

r

The first part of the signature.

288
    r: U256

s

The second part of the signature.

293
    s: U256

BlobTransaction

The transaction type added in EIP-4844.

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

299
@slotted_freezable
300
@dataclass
class BlobTransaction:

chain_id

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

311
    chain_id: U64

nonce

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

316
    nonce: U256

max_priority_fee_per_gas

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

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

326
    max_fee_per_gas: Uint

gas

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

332
    gas: Uint

to

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

337
    to: Address

value

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

343
    value: U256

data

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

348
    data: Bytes

access_list

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

354
    access_list: Tuple[Access, ...]

max_fee_per_blob_gas

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

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

365
    blob_versioned_hashes: Tuple[VersionedHash, ...]

y_parity

The recovery id of the signature.

371
    y_parity: U256

r

The first part of the signature.

376
    r: U256

s

The second part of the signature.

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

387
@slotted_freezable
388
@dataclass
class SetCodeTransaction:

chain_id

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

399
    chain_id: U64

nonce

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

404
    nonce: U64

max_priority_fee_per_gas

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

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

414
    max_fee_per_gas: Uint

gas

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

420
    gas: Uint

to

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

425
    to: Address

value

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

431
    value: U256

data

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

436
    data: Bytes

access_list

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

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

448
    authorizations: Tuple[Authorization, ...]

y_parity

The recovery id of the signature.

454
    y_parity: U256

r

The first part of the signature.

459
    r: U256

s

The second part of the signature.

464
    s: U256

Transaction

Union type representing any valid transaction type.

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

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

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

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

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

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

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

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

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