Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

increase precision of deposit tx value field to U256 to avoid overflow #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ impl Transaction {

/// Gets the transaction's value field.
pub fn value(&self) -> u128 {
*match self {
Transaction::Legacy(TxLegacy { value, .. }) => value,
Transaction::Eip2930(TxEip2930 { value, .. }) => value,
Transaction::Eip1559(TxEip1559 { value, .. }) => value,
Transaction::Eip4844(TxEip4844 { value, .. }) => value,
match self {
Transaction::Legacy(TxLegacy { value, .. }) => *value,
Transaction::Eip2930(TxEip2930 { value, .. }) => *value,
Transaction::Eip1559(TxEip1559 { value, .. }) => *value,
Transaction::Eip4844(TxEip4844 { value, .. }) => *value,
#[cfg(feature = "optimism")]
Transaction::Deposit(TxDeposit { value, .. }) => value,
Transaction::Deposit(TxDeposit { value, .. }) => value.saturating_to(),
}
}

Expand Down Expand Up @@ -451,7 +451,7 @@ impl Transaction {
Transaction::Eip1559(tx) => tx.value = value,
Transaction::Eip4844(tx) => tx.value = value,
#[cfg(feature = "optimism")]
Transaction::Deposit(tx) => tx.value = value,
Transaction::Deposit(tx) => tx.value = U256::from(value),
}
}

Expand Down
9 changes: 5 additions & 4 deletions crates/primitives/src/transaction/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Address, Bytes, TransactionKind, TxType, H256};
use crate::{Address, Bytes, TransactionKind, TxType, U256, H256};
use bytes::Buf;
use reth_codecs::{main_codec, Compact};
use reth_rlp::{length_of_length, Decodable, DecodeError, Encodable, Header, EMPTY_STRING_CODE};
Expand All @@ -17,8 +17,9 @@ pub struct TxDeposit {
pub to: TransactionKind,
/// The ETH value to mint on L2.
pub mint: Option<u128>,
/// The ETH value to send to the recipient account.
pub value: u128,
/// The ETH value to send to the recipient account. This value must have full u256 precision
/// since a forced tx can set arbitrary values.
pub value: U256,
/// The gas limit for the L2 transaction.
pub gas_limit: u64,
/// Field indicating if this transaction is exempt from the L2 gas limit.
Expand All @@ -36,7 +37,7 @@ impl TxDeposit {
mem::size_of::<Address>() + // from
self.to.size() + // to
mem::size_of::<Option<u128>>() + // mint
mem::size_of::<u128>() + // value
mem::size_of::<U256>() + // value
mem::size_of::<u64>() + // gas_limit
mem::size_of::<bool>() + // is_system_transaction
self.input.len() // input
Expand Down
Loading