Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use U256 instead fo u128 for mint #286

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions crates/consensus/src/hardforks/ecotone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl super::Hardforks {
source_hash: Self::deploy_l1_block_source(),
from: L1_BLOCK_DEPLOYER,
to: TxKind::Create,
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 375_000,
is_system_transaction: false,
Expand All @@ -108,7 +108,7 @@ impl super::Hardforks {
source_hash: Self::deploy_gas_price_oracle_source(),
from: GAS_PRICE_ORACLE_DEPLOYER,
to: TxKind::Create,
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 1_000_000,
is_system_transaction: false,
Expand All @@ -126,7 +126,7 @@ impl super::Hardforks {
source_hash: Self::update_l1_block_source(),
from: Address::default(),
to: TxKind::Call(L1_BLOCK_DEPLOYER),
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 50_000,
is_system_transaction: false,
Expand All @@ -144,7 +144,7 @@ impl super::Hardforks {
source_hash: Self::update_gas_price_oracle_source(),
from: Address::default(),
to: TxKind::Call(GAS_PRICE_ORACLE_DEPLOYER),
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 50_000,
is_system_transaction: false,
Expand All @@ -162,7 +162,7 @@ impl super::Hardforks {
source_hash: Self::enable_ecotone_source(),
from: L1_BLOCK_DEPLOYER,
to: TxKind::Call(GAS_PRICE_ORACLE),
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 80_000,
is_system_transaction: false,
Expand All @@ -180,7 +180,7 @@ impl super::Hardforks {
source_hash: Self::beacon_roots_source(),
from: EIP4788_FROM,
to: TxKind::Create,
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 250_000,
is_system_transaction: false,
Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/src/hardforks/fjord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl super::Hardforks {
source_hash: Self::deploy_fjord_gas_price_oracle_source(),
from: GAS_PRICE_ORACLE_FJORD_DEPLOYER,
to: TxKind::Create,
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 1_450_000,
is_system_transaction: false,
Expand All @@ -75,7 +75,7 @@ impl super::Hardforks {
source_hash: Self::update_fjord_gas_price_oracle_source(),
from: Address::ZERO,
to: TxKind::Call(GAS_PRICE_ORACLE),
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 50_000,
is_system_transaction: false,
Expand All @@ -93,7 +93,7 @@ impl super::Hardforks {
source_hash: Self::enable_fjord_source(),
from: L1_INFO_DEPOSITER,
to: TxKind::Call(GAS_PRICE_ORACLE),
mint: 0.into(),
mint: Some(U256::ZERO),
value: U256::ZERO,
gas_limit: 90_000,
is_system_transaction: false,
Expand Down
25 changes: 12 additions & 13 deletions crates/consensus/src/transaction/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ pub struct TxDeposit {
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "TxKind::is_create"))]
pub to: TxKind,
/// The ETH value to mint on L2.
#[cfg_attr(feature = "serde", serde(default, with = "alloy_serde::quantity::opt"))]
pub mint: Option<u128>,
pub mint: Option<U256>,
/// The ETH value to send to the recipient account.
pub value: U256,
/// The gas limit for the L2 transaction.
Expand All @@ -56,7 +55,7 @@ impl DepositTransaction for TxDeposit {
Some(self.source_hash)
}

fn mint(&self) -> Option<u128> {
fn mint(&self) -> Option<U256> {
self.mint
}

Expand Down Expand Up @@ -358,15 +357,15 @@ mod tests {
source_hash: B256::with_last_byte(42),
from: Address::default(),
to: TxKind::default(),
mint: Some(100),
mint: Some(U256::from(100)),
value: U256::from(1000),
gas_limit: 50000,
is_system_transaction: true,
input: Bytes::default(),
};

assert_eq!(tx.source_hash(), Some(B256::with_last_byte(42)));
assert_eq!(tx.mint(), Some(100));
assert_eq!(tx.mint(), Some(U256::from(100)),);
assert!(tx.is_system_transaction());
assert!(tx.is_deposit());
}
Expand Down Expand Up @@ -397,15 +396,15 @@ mod tests {
source_hash: B256::default(),
from: Address::default(),
to: TxKind::Call(contract_address),
mint: Some(200),
mint: Some(U256::from(200)),
value: U256::from(500),
gas_limit: 100000,
is_system_transaction: false,
input: Bytes::from_static(&[1, 2, 3]),
};

assert_eq!(tx.source_hash(), Some(B256::default()));
assert_eq!(tx.mint(), Some(200));
assert_eq!(tx.mint(), Some(U256::from(200)),);
assert!(!tx.is_system_transaction());
assert!(tx.is_deposit());
assert_eq!(tx.kind(), TxKind::Call(contract_address));
Expand All @@ -426,7 +425,7 @@ mod tests {
source_hash: B256::default(),
from: Address::default(),
to: TxKind::default(),
mint: Some(100),
mint: Some(U256::from(100)),
value: U256::default(),
gas_limit: 50000,
is_system_transaction: true,
Expand All @@ -446,7 +445,7 @@ mod tests {
source_hash: B256::default(),
from: Address::default(),
to: TxKind::default(),
mint: Some(100),
mint: Some(U256::from(100)),
value: U256::default(),
gas_limit: 50000,
is_system_transaction: true,
Expand All @@ -468,7 +467,7 @@ mod tests {
source_hash: B256::default(),
from: Address::default(),
to: TxKind::default(),
mint: Some(100),
mint: Some(U256::from(100)),
value: U256::default(),
gas_limit: 50000,
is_system_transaction: true,
Expand All @@ -484,7 +483,7 @@ mod tests {
source_hash: B256::default(),
from: Address::default(),
to: TxKind::default(),
mint: Some(100),
mint: Some(U256::from(100)),
value: U256::default(),
gas_limit: 50000,
is_system_transaction: true,
Expand All @@ -506,7 +505,7 @@ mod tests {
source_hash: B256::default(),
from: Address::default(),
to: TxKind::default(),
mint: Some(100),
mint: Some(U256::from(100)),
value: U256::default(),
gas_limit: 50000,
is_system_transaction: true,
Expand Down Expand Up @@ -550,7 +549,7 @@ pub(super) mod serde_bincode_compat {
#[serde(default)]
to: TxKind,
#[serde(default)]
mint: Option<u128>,
mint: Option<U256>,
value: U256,
gas_limit: u64,
is_system_transaction: bool,
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ mod tests {
let tx = TxDeposit {
source_hash: B256::left_padding_from(&[0xde, 0xad]),
from: Address::left_padding_from(&[0xbe, 0xef]),
mint: Some(1),
mint: Some(U256::from(1)),
gas_limit: 2,
to: TxKind::Call(Address::left_padding_from(&[3])),
value: U256::from(4_u64),
Expand All @@ -558,7 +558,7 @@ mod tests {
input: Bytes::new(),
source_hash: U256::MAX.into(),
from: Address::random(),
mint: Some(u128::MAX),
mint: Some(U256::MAX),
is_system_transaction: false,
};
let tx_envelope = OpTxEnvelope::Deposit(tx.seal_slow());
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(super) mod serde_bincode_compat {
pub use super::deposit::serde_bincode_compat::TxDeposit;
}

use alloy_primitives::B256;
use alloy_primitives::{B256, U256};

/// A trait representing a deposit transaction with specific attributes.
pub trait DepositTransaction {
Expand All @@ -41,7 +41,7 @@ pub trait DepositTransaction {
///
/// # Returns
/// An `Option<u128>` representing the ETH value to mint on L2, if any.
fn mint(&self) -> Option<u128>;
fn mint(&self) -> Option<U256>;

/// Indicates whether the transaction is exempt from the L2 gas limit.
///
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spin = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, features = ["fmt"], optional = true }

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["arbitrary"] }
brotli = { workspace = true, features = ["std"] }
revm.workspace = true
spin.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/protocol/src/deposits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ pub(crate) fn unmarshal_deposit_version0(
let raw_mint: [u8; 16] = data[offset + 16..offset + 32].try_into().map_err(|_| {
DepositError::MintDecode(Bytes::copy_from_slice(&data[offset + 16..offset + 32]))
})?;
let mint = u128::from_be_bytes(raw_mint);
let mint = U256::from_be_bytes(raw_mint);

// 0 mint is represented as nil to skip minting code
if mint == 0 {
if mint == U256::ZERO {
tx.mint = None;
} else {
tx.mint = Some(mint);
Expand Down Expand Up @@ -617,7 +617,7 @@ mod test {
to: TxKind::Call(address!("2222222222222222222222222222222222222222")),
value: U256::from(100),
gas_limit: 1000,
mint: Some(10),
mint: Some(U256::from(10)),
..Default::default()
};
let to = address!("5555555555555555555555555555555555555555");
Expand Down
3 changes: 1 addition & 2 deletions crates/rpc-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ impl alloy_network_primitives::TransactionResponse for Transaction {
#[serde(rename_all = "camelCase")]
pub struct OpTransactionFields {
/// The ETH value to mint on L2
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub mint: Option<u128>,
pub mint: Option<U256>,
/// Hash that uniquely identifies the source of the deposit.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_hash: Option<B256>,
Expand Down