@@ -61,14 +61,15 @@ def encode_receipt(receipt: TxReceipt) -> bytes:
6161 RLP encode a transaction receipt with proper type handling.
6262
6363 Handles both legacy (type 0) and typed transactions (EIP-2718).
64+ Supports OP Stack deposit transactions (type 0x7e) with Canyon upgrade.
6465
6566 Args:
6667 receipt: Transaction receipt to encode
6768
6869 Returns:
6970 RLP encoded receipt with type prefix if needed
7071 """
71- # Get transaction type (0 for legacy, 2 for EIP-1559, etc. )
72+ # Get transaction type (0 for legacy, 2 for EIP-1559, 0x7e for OP deposit )
7273 tx_type = int (receipt .get ("type" , 0 ))
7374
7475 # Encode receipt fields
@@ -86,8 +87,34 @@ def encode_receipt(receipt: TxReceipt) -> bytes:
8687 ]
8788 encoded_logs .append (encoded_log )
8889
89- # Create receipt tuple
90+ # Create base receipt tuple
9091 receipt_data = [status , cumulative_gas , logs_bloom , encoded_logs ]
92+
93+ # Handle OP Stack deposit transactions (type 0x7e/126)
94+ # After Canyon upgrade, deposit receipts include additional fields:
95+ # RLP([status, cumulativeGasUsed, logsBloom, logs, depositNonce, depositReceiptVersion])
96+ # See: https://specs.optimism.io/protocol/deposits.html
97+ if tx_type == 126 : # 0x7e - OP Stack deposit transaction
98+ deposit_receipt_version = receipt .get ("depositReceiptVersion" )
99+ if deposit_receipt_version is not None :
100+ # Canyon+ deposit receipt: append depositNonce and depositReceiptVersion
101+ deposit_nonce = receipt .get ("depositNonce" )
102+ if deposit_nonce is not None :
103+ # Convert from hex string to int if needed (web3.py may return hex strings)
104+ if isinstance (deposit_nonce , str ):
105+ deposit_nonce = int (deposit_nonce , 16 )
106+ if isinstance (deposit_receipt_version , str ):
107+ deposit_receipt_version = int (deposit_receipt_version , 16 )
108+ receipt_data .append (deposit_nonce )
109+ receipt_data .append (deposit_receipt_version )
110+ logger .debug (
111+ f"Encoding Canyon deposit receipt with nonce={ deposit_nonce } , version={ deposit_receipt_version } "
112+ )
113+ else :
114+ logger .warning (
115+ f"depositReceiptVersion={ deposit_receipt_version } but depositNonce missing"
116+ )
117+
91118 encoded = rlp .encode (receipt_data )
92119
93120 # Add transaction type prefix for typed transactions
0 commit comments