From 2aafff70907da234f51f700db361c7141ed6c344 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Mon, 10 Feb 2025 08:37:26 +0100 Subject: [PATCH] EVM Node: `input`, `s` and `r` are not hashes --- .../lib_dev/encodings/ethereum_types.ml | 18 +++++++++--------- .../lib_dev/encodings/ethereum_types.mli | 6 +++--- .../bin_node/lib_dev/encodings/transaction.ml | 6 +++--- .../lib_dev/encodings/transaction_info.ml | 12 ++++++------ .../lib_dev/encodings/transaction_info.mli | 6 +++--- .../bin_node/lib_dev/transaction_object.ml | 14 ++++++-------- etherlink/bin_node/lib_dev/tx_pool.ml | 2 +- 7 files changed, 31 insertions(+), 33 deletions(-) diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml index e8c40ab05549..954b6cb1fcd6 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.ml @@ -386,15 +386,15 @@ type legacy_transaction_object = { gas : quantity; gasPrice : quantity; hash : hash; - input : hash; + input : hex; nonce : quantity; to_ : address option; transactionIndex : quantity option; (* It can be null if it's in a pending block. *) value : quantity; v : quantity; - r : hash; - s : hash; + r : hex; + s : hex; } let legacy_transaction_object_from_rlp_item block_hash rlp_item = @@ -427,7 +427,7 @@ let legacy_transaction_object_from_rlp_item block_hash rlp_item = let gas = decode_number_le gas_used in let gas_price = decode_number_le gas_price in let hash = decode_hash hash in - let input = decode_hash input in + let input = decode_hex input in let nonce = decode_number_le nonce in let to_ = if to_ = Bytes.empty then None else Some (decode_address to_) in let index = decode_optional_number_be index in @@ -435,8 +435,8 @@ let legacy_transaction_object_from_rlp_item block_hash rlp_item = (* The signature is taken from the raw transaction, that is encoded in big endian. *) let v = decode_number_be v in - let r = decode_hash r in - let s = decode_hash s in + let r = decode_hex r in + let s = decode_hex s in { blockHash = block_hash; blockNumber = block_number; @@ -525,15 +525,15 @@ let legacy_transaction_object_encoding = (req "gas" quantity_encoding) (req "gasPrice" quantity_encoding) (req "hash" hash_encoding) - (req "input" hash_encoding) + (req "input" hex_encoding) (req "nonce" quantity_encoding) (req "to" (option address_encoding)) (req "transactionIndex" (option quantity_encoding))) (obj4 (req "value" quantity_encoding) (req "v" quantity_encoding) - (req "r" hash_encoding) - (req "s" hash_encoding))) + (req "r" hex_encoding) + (req "s" hex_encoding))) type 'transaction_object block_transactions = | TxHash of hash list diff --git a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli index 887610972d2a..f690345060c4 100644 --- a/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli +++ b/etherlink/bin_node/lib_dev/encodings/ethereum_types.mli @@ -158,14 +158,14 @@ type legacy_transaction_object = { gas : quantity; gasPrice : quantity; hash : hash; - input : hash; + input : hex; nonce : quantity; to_ : address option; transactionIndex : quantity option; value : quantity; v : quantity; - r : hash; - s : hash; + r : hex; + s : hex; } val legacy_transaction_object_encoding : diff --git a/etherlink/bin_node/lib_dev/encodings/transaction.ml b/etherlink/bin_node/lib_dev/encodings/transaction.ml index 9f0e31020729..d89fa9d95bd1 100644 --- a/etherlink/bin_node/lib_dev/encodings/transaction.ml +++ b/etherlink/bin_node/lib_dev/encodings/transaction.ml @@ -438,12 +438,12 @@ let to_transaction_object : gas = Qty gas_limit; gasPrice = Qty max_fee_per_gas; hash; - input = decode_hash data; + input = decode_hex data; nonce = Qty nonce; to_; transactionIndex = None; value = Qty value; v = Qty v; - r = decode_hash r; - s = decode_hash s; + r = decode_hex r; + s = decode_hex s; } diff --git a/etherlink/bin_node/lib_dev/encodings/transaction_info.ml b/etherlink/bin_node/lib_dev/encodings/transaction_info.ml index daa669b05553..5f74374a557b 100644 --- a/etherlink/bin_node/lib_dev/encodings/transaction_info.ml +++ b/etherlink/bin_node/lib_dev/encodings/transaction_info.ml @@ -21,12 +21,12 @@ type receipt_fields = { type object_fields = { gas : quantity; gas_price : quantity; - input : hash; + input : hex; nonce : quantity; value : quantity; v : quantity; - r : hash; - s : hash; + r : hex; + s : hex; } type t = { @@ -158,9 +158,9 @@ let object_fields_encoding = (obj8 (req "gas" quantity_encoding) (req "gas_price" quantity_encoding) - (req "input" hash_encoding) + (req "input" hex_encoding) (req "nonce" quantity_encoding) (req "value" quantity_encoding) (req "v" quantity_encoding) - (req "r" hash_encoding) - (req "s" hash_encoding)) + (req "r" hex_encoding) + (req "s" hex_encoding)) diff --git a/etherlink/bin_node/lib_dev/encodings/transaction_info.mli b/etherlink/bin_node/lib_dev/encodings/transaction_info.mli index 506b69b033bc..d554268bf28a 100644 --- a/etherlink/bin_node/lib_dev/encodings/transaction_info.mli +++ b/etherlink/bin_node/lib_dev/encodings/transaction_info.mli @@ -21,12 +21,12 @@ type receipt_fields = { type object_fields = { gas : quantity; gas_price : quantity; - input : hash; + input : hex; nonce : quantity; value : quantity; v : quantity; - r : hash; - s : hash; + r : hex; + s : hex; } (** This is the merge of a {!Transaction_receipt.t} and diff --git a/etherlink/bin_node/lib_dev/transaction_object.ml b/etherlink/bin_node/lib_dev/transaction_object.ml index 6b54bcc6d5c0..d08365b87ce3 100644 --- a/etherlink/bin_node/lib_dev/transaction_object.ml +++ b/etherlink/bin_node/lib_dev/transaction_object.ml @@ -246,8 +246,6 @@ type t = | EIP_2930 of EIP_2930.t | EIP_1559 of EIP_1559.t -let unhash (Hash h) = h - let from_store_transaction_object (obj : legacy_transaction_object) = Kernel obj let block_from_legacy block = @@ -309,10 +307,10 @@ let reconstruct_from_eip_2930_transaction (obj : legacy_transaction_object) gas = obj.gas; gas_price = obj.gasPrice; access_list; - input = unhash obj.input; + input = obj.input; v = obj.v; - r = unhash obj.r; - s = unhash obj.s; + r = obj.r; + s = obj.s; } | _ -> error_with "failed to decode EIP-2930 transaction" @@ -358,10 +356,10 @@ let reconstruct_from_eip_1559_transaction (obj : legacy_transaction_object) max_fee_per_gas; max_priority_fee_per_gas; access_list; - input = unhash obj.input; + input = obj.input; v = obj.v; - r = unhash obj.r; - s = unhash obj.s; + r = obj.r; + s = obj.s; } | _ -> (* This should not happen, but we cannot decode the transaction *) diff --git a/etherlink/bin_node/lib_dev/tx_pool.ml b/etherlink/bin_node/lib_dev/tx_pool.ml index ed85f0b4eb46..75e6a11c0184 100644 --- a/etherlink/bin_node/lib_dev/tx_pool.ml +++ b/etherlink/bin_node/lib_dev/tx_pool.ml @@ -452,7 +452,7 @@ let insert_valid_transaction state tx_raw state in let tx_data = - transaction_object.input |> Ethereum_types.hash_to_bytes |> Bytes.of_string + transaction_object.input |> Ethereum_types.hex_to_bytes |> Bytes.of_string in if tx_data_size_limit_reached ~max_number_of_chunks ~tx_data then let*! () = Tx_pool_events.tx_data_size_limit_reached () in -- GitLab