Skip to content

Commit 43a984d

Browse files
authored
fix: scale withdrawals amount to gwei (#371)
1 parent 8d5f15b commit 43a984d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

trace_decoder/src/decoding.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
OtherBlockData, TrieRootHash, TxnIdx, EMPTY_ACCOUNT_BYTES_RLPED,
3131
ZERO_STORAGE_SLOT_VAL_RLPED,
3232
},
33-
utils::{hash, optional_field, optional_field_hex, update_val_if_some},
33+
utils::{eth_to_gwei, hash, optional_field, optional_field_hex, update_val_if_some},
3434
};
3535

3636
/// Stores the result of parsing tries. Returns a [TraceParsingError] upon
@@ -563,8 +563,13 @@ impl ProcessedBlockTrace {
563563
fn add_withdrawals_to_txns(
564564
txn_ir: &mut [GenerationInputs],
565565
final_trie_state: &mut PartialTrieState,
566-
withdrawals: Vec<(Address, U256)>,
566+
mut withdrawals: Vec<(Address, U256)>,
567567
) -> TraceParsingResult<()> {
568+
// Scale withdrawals amounts.
569+
for (_addr, amt) in withdrawals.iter_mut() {
570+
*amt = eth_to_gwei(*amt)
571+
}
572+
568573
let withdrawals_with_hashed_addrs_iter = || {
569574
withdrawals
570575
.iter()

trace_decoder/src/utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ethereum_types::H256;
1+
use ethereum_types::{H256, U256};
22
use keccak_hash::keccak;
33
use log::trace;
44
use mpt_trie::{
@@ -8,6 +8,11 @@ use mpt_trie::{
88

99
use crate::types::HashedStorageAddr;
1010

11+
pub(crate) fn eth_to_gwei(eth: U256) -> U256 {
12+
// 1 ether = 10^9 gwei.
13+
eth * U256::from(10).pow(9.into())
14+
}
15+
1116
pub(crate) fn hash(bytes: &[u8]) -> H256 {
1217
H256::from(keccak(bytes).0)
1318
}

0 commit comments

Comments
 (0)