From c5c9958be8317d438aa3633b59500f3a5bb10d15 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Tue, 9 Jul 2024 14:40:39 -0400 Subject: [PATCH 1/2] fix: scale withdrawals amount to gwei --- trace_decoder/src/decoding.rs | 4 ++-- trace_decoder/src/utils.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index 97170fbf1..c436e2ca1 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -30,7 +30,7 @@ use crate::{ OtherBlockData, TrieRootHash, TxnIdx, EMPTY_ACCOUNT_BYTES_RLPED, ZERO_STORAGE_SLOT_VAL_RLPED, }, - utils::{hash, optional_field, optional_field_hex, update_val_if_some}, + utils::{eth_to_gwei, hash, optional_field, optional_field_hex, update_val_if_some}, }; /// Stores the result of parsing tries. Returns a [TraceParsingError] upon @@ -617,7 +617,7 @@ impl ProcessedBlockTrace { })?; let mut acc_data = account_from_rlped_bytes(acc_bytes)?; - acc_data.balance += amt; + acc_data.balance += eth_to_gwei(amt); state .insert(h_addr_nibs, rlp::encode(&acc_data).to_vec()) diff --git a/trace_decoder/src/utils.rs b/trace_decoder/src/utils.rs index 7abfe00df..2995ca68d 100644 --- a/trace_decoder/src/utils.rs +++ b/trace_decoder/src/utils.rs @@ -1,4 +1,4 @@ -use ethereum_types::H256; +use ethereum_types::{H256, U256}; use keccak_hash::keccak; use log::trace; use mpt_trie::{ @@ -8,6 +8,11 @@ use mpt_trie::{ use crate::types::HashedStorageAddr; +pub(crate) fn eth_to_gwei(eth: U256) -> U256 { + // 1 ether = 10^9 gwei. + eth * U256::from(10).pow(9.into()) +} + pub(crate) fn hash(bytes: &[u8]) -> H256 { H256::from(keccak(bytes).0) } From 30d243936064ab751bd11fd4732a478d7f351313 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Tue, 9 Jul 2024 15:04:58 -0400 Subject: [PATCH 2/2] scale prior processing --- trace_decoder/src/decoding.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/trace_decoder/src/decoding.rs b/trace_decoder/src/decoding.rs index c436e2ca1..c409e84bb 100644 --- a/trace_decoder/src/decoding.rs +++ b/trace_decoder/src/decoding.rs @@ -563,8 +563,13 @@ impl ProcessedBlockTrace { fn add_withdrawals_to_txns( txn_ir: &mut [GenerationInputs], final_trie_state: &mut PartialTrieState, - withdrawals: Vec<(Address, U256)>, + mut withdrawals: Vec<(Address, U256)>, ) -> TraceParsingResult<()> { + // Scale withdrawals amounts. + for (_addr, amt) in withdrawals.iter_mut() { + *amt = eth_to_gwei(*amt) + } + let withdrawals_with_hashed_addrs_iter = || { withdrawals .iter() @@ -617,7 +622,7 @@ impl ProcessedBlockTrace { })?; let mut acc_data = account_from_rlped_bytes(acc_bytes)?; - acc_data.balance += eth_to_gwei(amt); + acc_data.balance += amt; state .insert(h_addr_nibs, rlp::encode(&acc_data).to_vec())