Skip to content

Commit

Permalink
change transaction value fields from u128 to U256 to support chains l…
Browse files Browse the repository at this point in the history
…ike OP where this value might take on the full range
  • Loading branch information
roberto-bayardo authored and Roberto Bayardo committed Sep 13, 2023
1 parent a3952f1 commit 4220ae9
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 63 deletions.
2 changes: 1 addition & 1 deletion crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ mod tests {
gas_price: 0x28f000fff,
gas_limit: 10,
to: TransactionKind::Call(Address::default()),
value: 3,
value: U256::from(3),
input: Bytes::from(vec![1, 2]),
access_list: Default::default(),
});
Expand Down
6 changes: 3 additions & 3 deletions crates/interfaces/src/test_utils/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn random_tx<R: Rng>(rng: &mut R) -> Transaction {
gas_price: rng.gen::<u16>().into(),
gas_limit: rng.gen::<u16>().into(),
to: TransactionKind::Call(Address::random()),
value: rng.gen::<u16>().into(),
value: U256::from(rng.gen::<u16>()),
input: Bytes::default(),
})
}
Expand Down Expand Up @@ -395,7 +395,7 @@ mod test {
nonce: 0x42,
gas_limit: 44386,
to: TransactionKind::Call(hex!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").into()),
value: 0_u128,
value: U256::default(),
input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(),
max_fee_per_gas: 0x4a817c800,
max_priority_fee_per_gas: 0x3b9aca00,
Expand Down Expand Up @@ -427,7 +427,7 @@ mod test {
gas_price: 20 * 10_u128.pow(9),
gas_limit: 21000,
to: TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()),
value: 10_u128.pow(18),
value: U256::from(10_u128.pow(18)),
input: Bytes::default(),
});

Expand Down
8 changes: 4 additions & 4 deletions crates/net/eth-wire/src/types/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ mod test {
gas_limit: 0x2e248u64,
to:
TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()),
value: 0x200u64.into(),
value: U256::from(0x200u64),
input: Default::default(),
}),
Signature {
Expand All @@ -370,7 +370,7 @@ mod test {
gas_limit: 0x33450u64,
to:
TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()),
value: 0x2d9u64.into(),
value: U256::from(0x2d9u64),
input: Default::default(),
}), Signature {
odd_y_parity: false,
Expand Down Expand Up @@ -438,7 +438,7 @@ mod test {
gas_limit: 0x2e248u64,
to:
TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()),
value: 0x200u64.into(),
value: U256::from(0x200u64),
input: Default::default(),
}),
Signature {
Expand All @@ -456,7 +456,7 @@ mod test {
gas_limit: 0x33450u64,
to:
TransactionKind::Call(hex!("3535353535353535353535353535353535353535").into()),
value: 0x2d9u64.into(),
value: U256::from(0x2d9u64),
input: Default::default(),
}),
Signature {
Expand Down
28 changes: 14 additions & 14 deletions crates/net/eth-wire/src/types/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod test {
to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(),
),
value: 0x200u64.into(),
value: U256::from(0x200u64),
input: Default::default(),
}),
Signature {
Expand All @@ -129,7 +129,7 @@ mod test {
to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(),
),
value: 0x2d9u64.into(),
value: U256::from(0x2d9u64),
input: Default::default(),
}),
Signature {
Expand Down Expand Up @@ -167,7 +167,7 @@ mod test {
to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(),
),
value: 0x200u64.into(),
value: U256::from(0x200u64),
input: Default::default(),
}),
Signature {
Expand All @@ -191,7 +191,7 @@ mod test {
to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(),
),
value: 0x2d9u64.into(),
value: U256::from(0x2d9u64),
input: Default::default(),
}),
Signature {
Expand Down Expand Up @@ -232,7 +232,7 @@ mod test {
to: TransactionKind::Call(
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
),
value: 1234u64.into(),
value: U256::from(1234u64),
input: Default::default(),
}),
Signature {
Expand All @@ -257,7 +257,7 @@ mod test {
to: TransactionKind::Call(
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
),
value: 3000000000000000000u64.into(),
value: U256::from(3000000000000000000u64),
input: Default::default(),
access_list: Default::default(),
}),
Expand All @@ -282,7 +282,7 @@ mod test {
to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
),
value: 1000000000000000u64.into(),
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
Expand All @@ -306,7 +306,7 @@ mod test {
to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
),
value: 693361000000000u64.into(),
value: U256::from(693361000000000u64),
input: Default::default(),
}),
Signature {
Expand All @@ -330,7 +330,7 @@ mod test {
to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
),
value: 1000000000000000u64.into(),
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
Expand Down Expand Up @@ -375,7 +375,7 @@ mod test {
to: TransactionKind::Call(
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
),
value: 1234u64.into(),
value: U256::from(1234u64),
input: Default::default(),
}),
Signature {
Expand All @@ -400,7 +400,7 @@ mod test {
to: TransactionKind::Call(
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
),
value: 3000000000000000000u64.into(),
value: U256::from(3000000000000000000u64),
input: Default::default(),
access_list: Default::default(),
}),
Expand All @@ -425,7 +425,7 @@ mod test {
to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
),
value: 1000000000000000u64.into(),
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
Expand All @@ -449,7 +449,7 @@ mod test {
to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
),
value: 693361000000000u64.into(),
value: U256::from(693361000000000u64),
input: Default::default(),
}),
Signature {
Expand All @@ -473,7 +473,7 @@ mod test {
to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
),
value: 1000000000000000u64.into(),
value: U256::from(1000000000000000u64),
input: Default::default(),
}),
Signature {
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/tests/it/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn rng_transaction(rng: &mut impl rand::RngCore) -> TransactionSigned {
gas_price: rng.gen(),
gas_limit: rng.gen(),
to: TransactionKind::Create,
value: rng.gen(),
value: U256::from(rng.gen::<u128>()),
input: Bytes::from(vec![1, 2]),
access_list: Default::default(),
});
Expand Down
12 changes: 4 additions & 8 deletions crates/primitives/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::access_list::AccessList;
use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, H256};
use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, H256, U256};
use bytes::BytesMut;
use reth_codecs::{main_codec, Compact};
use reth_rlp::{length_of_length, Decodable, DecodeError, Encodable, Header};
Expand Down Expand Up @@ -46,11 +46,7 @@ pub struct TxEip1559 {
/// be transferred to the message call’s recipient or,
/// in the case of contract creation, as an endowment
/// to the newly created account; formally Tv.
///
/// As ethereum circulation is around 120mil eth as of 2022 that is around
/// 120000000000000000000000000 wei we are safe to use u128 as its max number is:
/// 340282366920938463463374607431768211455
pub value: u128,
pub value: U256,
/// The accessList specifies a list of addresses and storage keys;
/// these addresses and storage keys are added into the `accessed_addresses`
/// and `accessed_storage_keys` global sets (introduced in EIP-2929).
Expand Down Expand Up @@ -185,7 +181,7 @@ impl TxEip1559 {
mem::size_of::<u128>() + // max_fee_per_gas
mem::size_of::<u128>() + // max_priority_fee_per_gas
self.to.size() + // to
mem::size_of::<u128>() + // value
mem::size_of::<U256>() + // value
self.access_list.size() + // access_list
self.input.len() // input
}
Expand Down Expand Up @@ -235,7 +231,7 @@ mod tests {
nonce: 0x42,
gas_limit: 44386,
to: TransactionKind::Call( hex!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").into()),
value: 0,
value: U256::default(),
input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(),
max_fee_per_gas: 0x4a817c800,
max_priority_fee_per_gas: 0x3b9aca00,
Expand Down
14 changes: 5 additions & 9 deletions crates/primitives/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::access_list::AccessList;
use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, H256};
use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, H256, U256};
use bytes::BytesMut;
use reth_codecs::{main_codec, Compact};
use reth_rlp::{length_of_length, Decodable, DecodeError, Encodable, Header};
Expand Down Expand Up @@ -34,11 +34,7 @@ pub struct TxEip2930 {
/// be transferred to the message call’s recipient or,
/// in the case of contract creation, as an endowment
/// to the newly created account; formally Tv.
///
/// As ethereum circulation is around 120mil eth as of 2022 that is around
/// 120000000000000000000000000 wei we are safe to use u128 as its max number is:
/// 340282366920938463463374607431768211455
pub value: u128,
pub value: U256,
/// The accessList specifies a list of addresses and storage keys;
/// these addresses and storage keys are added into the `accessed_addresses`
/// and `accessed_storage_keys` global sets (introduced in EIP-2929).
Expand All @@ -62,7 +58,7 @@ impl TxEip2930 {
mem::size_of::<u128>() + // gas_price
mem::size_of::<u64>() + // gas_limit
self.to.size() + // to
mem::size_of::<u128>() + // value
mem::size_of::<U256>() + // value
self.access_list.size() + // access_list
self.input.len() // input
}
Expand Down Expand Up @@ -197,7 +193,7 @@ mod tests {
gas_price: 1,
gas_limit: 2,
to: TransactionKind::Create,
value: 3,
value: U256::from(3),
input: Bytes::from(vec![1, 2]),
access_list: Default::default(),
});
Expand All @@ -220,7 +216,7 @@ mod tests {
gas_price: 1,
gas_limit: 2,
to: TransactionKind::Call(Address::default()),
value: 3,
value: U256::from(3),
input: Bytes::from(vec![1, 2]),
access_list: Default::default(),
});
Expand Down
6 changes: 3 additions & 3 deletions crates/primitives/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
BYTES_PER_COMMITMENT, BYTES_PER_PROOF,
},
kzg_to_versioned_hash, Bytes, ChainId, Signature, Transaction, TransactionKind,
TransactionSigned, TxHash, TxType, EIP4844_TX_TYPE_ID, H256,
TransactionSigned, TxHash, TxType, EIP4844_TX_TYPE_ID, H256, U256,
};
use bytes::BytesMut;
use reth_codecs::{main_codec, Compact};
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct TxEip4844 {
/// As ethereum circulation is around 120mil eth as of 2022 that is around
/// 120000000000000000000000000 wei we are safe to use u128 as its max number is:
/// 340282366920938463463374607431768211455
pub value: u128,
pub value: U256,
/// The accessList specifies a list of addresses and storage keys;
/// these addresses and storage keys are added into the `accessed_addresses`
/// and `accessed_storage_keys` global sets (introduced in EIP-2929).
Expand Down Expand Up @@ -247,7 +247,7 @@ impl TxEip4844 {
mem::size_of::<u128>() + // max_fee_per_gas
mem::size_of::<u128>() + // max_priority_fee_per_gas
self.to.size() + // to
mem::size_of::<u128>() + // value
mem::size_of::<U256>() + // value
self.access_list.size() + // access_list
self.input.len() + // input
self.blob_versioned_hashes.capacity() * mem::size_of::<H256>() + // blob hashes size
Expand Down
12 changes: 4 additions & 8 deletions crates/primitives/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, H256};
use crate::{keccak256, Bytes, ChainId, Signature, TransactionKind, TxType, H256, U256};
use bytes::BytesMut;
use reth_codecs::{main_codec, Compact};
use reth_rlp::{length_of_length, Encodable, Header};
Expand Down Expand Up @@ -33,11 +33,7 @@ pub struct TxLegacy {
/// be transferred to the message call’s recipient or,
/// in the case of contract creation, as an endowment
/// to the newly created account; formally Tv.
///
/// As ethereum circulation is around 120mil eth as of 2022 that is around
/// 120000000000000000000000000 wei we are safe to use u128 as its max number is:
/// 340282366920938463463374607431768211455
pub value: u128,
pub value: U256,
/// Input has two uses depending if transaction is Create or Call (if `to` field is None or
/// Some). pub init: An unlimited size byte array specifying the
/// EVM-code for the account initialisation procedure CREATE,
Expand All @@ -55,7 +51,7 @@ impl TxLegacy {
mem::size_of::<u128>() + // gas_price
mem::size_of::<u64>() + // gas_limit
self.to.size() + // to
mem::size_of::<u128>() + // value
mem::size_of::<U256>() + // value
self.input.len() // input
}

Expand Down Expand Up @@ -183,7 +179,7 @@ mod tests {
gas_price: 0xfa56ea00,
gas_limit: 119902,
to: TransactionKind::Call( hex!("06012c8cf97bead5deae237070f9587f8e7a266d").into()),
value: 0x1c6bf526340000u64.into(),
value: U256::from(0x1c6bf526340000u64),
input: hex!("f7d8c88300000000000000000000000000000000000000000000000000000000000cee6100000000000000000000000000000000000000000000000000000000000ac3e1").into(),
});

Expand Down
Loading

0 comments on commit 4220ae9

Please sign in to comment.