From 21891fad813d3a8582394fc7c9bd40e02177c5b1 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:40:00 -0400 Subject: [PATCH 1/5] feat(op): use RollupCostData instead of full encoding --- crates/revm/src/optimism.rs | 2 ++ crates/revm/src/optimism/l1block.rs | 28 +++++++++--------- crates/revm/src/optimism/rollup_cost.rs | 39 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 crates/revm/src/optimism/rollup_cost.rs diff --git a/crates/revm/src/optimism.rs b/crates/revm/src/optimism.rs index 12f3db9969..4a868e2727 100644 --- a/crates/revm/src/optimism.rs +++ b/crates/revm/src/optimism.rs @@ -3,9 +3,11 @@ mod fast_lz; mod handler_register; mod l1block; +mod rollup_cost; pub use handler_register::{ deduct_caller, end, last_frame_return, load_accounts, load_precompiles, optimism_handle_register, output, reward_beneficiary, validate_env, validate_tx_against_state, }; pub use l1block::{L1BlockInfo, BASE_FEE_RECIPIENT, L1_BLOCK_CONTRACT, L1_FEE_RECIPIENT}; +pub use rollup_cost::RollupCostData; diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index 2dab41a4e4..853be23561 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -1,4 +1,4 @@ -use crate::optimism::fast_lz::flz_compress_len; +use crate::optimism::rollup_cost::RollupCostData; use crate::primitives::{address, db::Database, Address, SpecId, U256}; use core::ops::Mul; @@ -125,21 +125,18 @@ impl L1BlockInfo { /// Prior to regolith, an extra 68 non-zero bytes were included in the rollup data costs to /// account for the empty signature. pub fn data_gas(&self, input: &[u8], spec_id: SpecId) -> U256 { + let cost_data = RollupCostData::from_bytes(input); if spec_id.is_enabled_in(SpecId::FJORD) { - let estimated_size = self.tx_estimated_size_fjord(input); + let estimated_size = self.tx_estimated_size_fjord(cost_data); return estimated_size .saturating_mul(U256::from(NON_ZERO_BYTE_COST)) .wrapping_div(U256::from(1_000_000)); }; - let mut rollup_data_gas_cost = U256::from(input.iter().fold(0, |acc, byte| { - acc + if *byte == 0x00 { - ZERO_BYTE_COST - } else { - NON_ZERO_BYTE_COST - } - })); + let mut rollup_data_gas_cost = U256::from(cost_data.ones) + .saturating_mul(U256::from(NON_ZERO_BYTE_COST)) + .saturating_add(U256::from(cost_data.zeroes).saturating_mul(U256::from(ZERO_BYTE_COST))); // Prior to regolith, an extra 68 non zero bytes were included in the rollup data costs. if !spec_id.is_enabled_in(SpecId::REGOLITH) { @@ -152,8 +149,8 @@ impl L1BlockInfo { // Calculate the estimated compressed transaction size in bytes, scaled by 1e6. // This value is computed based on the following formula: // max(minTransactionSize, intercept + fastlzCoef*fastlzSize) - fn tx_estimated_size_fjord(&self, input: &[u8]) -> U256 { - let fastlz_size = U256::from(flz_compress_len(input)); + fn tx_estimated_size_fjord(&self, cost_data: RollupCostData) -> U256 { + let fastlz_size = U256::from(cost_data.fastlz_size); fastlz_size .saturating_mul(U256::from(836_500)) @@ -168,8 +165,11 @@ impl L1BlockInfo { return U256::ZERO; } + // let's create a `RollupCostData` to make the computation easier + let cost_data = RollupCostData::from_bytes(input); + if spec_id.is_enabled_in(SpecId::FJORD) { - self.calculate_tx_l1_cost_fjord(input) + self.calculate_tx_l1_cost_fjord(cost_data) } else if spec_id.is_enabled_in(SpecId::ECOTONE) { self.calculate_tx_l1_cost_ecotone(input, spec_id) } else { @@ -217,9 +217,9 @@ impl L1BlockInfo { /// /// [SpecId::FJORD] L1 cost function: /// `estimatedSize*(baseFeeScalar*l1BaseFee*16 + blobFeeScalar*l1BlobBaseFee)/1e12` - fn calculate_tx_l1_cost_fjord(&self, input: &[u8]) -> U256 { + fn calculate_tx_l1_cost_fjord(&self, cost_data: RollupCostData) -> U256 { let l1_fee_scaled = self.calculate_l1_fee_scaled_ecotone(); - let estimated_size = self.tx_estimated_size_fjord(input); + let estimated_size = self.tx_estimated_size_fjord(cost_data); estimated_size .saturating_mul(l1_fee_scaled) diff --git a/crates/revm/src/optimism/rollup_cost.rs b/crates/revm/src/optimism/rollup_cost.rs new file mode 100644 index 0000000000..6f08523b94 --- /dev/null +++ b/crates/revm/src/optimism/rollup_cost.rs @@ -0,0 +1,39 @@ +//! This contains a struct, [`RollupCostData`], that is used to compute the data availability costs +//! for a transaction. + +use crate::optimism::fast_lz::flz_compress_len; + +/// RollupCostData contains three fields, which are used depending on the current optimism fork. +/// +/// The `zeroes` and `ones` fields are used to compute the data availability costs for a +/// transaction pre-fjord. +/// +/// The `fastlz_size` field is used to compute the data availability costs for a transaction +/// post-fjord. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct RollupCostData { + /// The number of zeroes in the transaction. + pub(crate) zeroes: u64, + /// The number of ones in the transaction. + pub(crate) ones: u64, + /// The size of the transaction after fastLZ compression. + pub(crate) fastlz_size: u32, +} + +impl RollupCostData { + /// This takes bytes as input, creating a [`RollupCostData`] struct based on the encoded data. + pub fn from_bytes(bytes: &[u8]) -> Self { + let mut data = RollupCostData::default(); + let mut i = 0; + while i < bytes.len() { + if bytes[i] == 0 { + data.zeroes += 1; + } else { + data.ones += 1; + } + i += 1; + } + data.fastlz_size = flz_compress_len(bytes); + data + } +} From 8fb242be35cbb24aa8541a57805327141a082a86 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:46:22 -0400 Subject: [PATCH 2/5] cargo fmt --- crates/revm/src/optimism/l1block.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index 853be23561..0caf8b7460 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -136,7 +136,9 @@ impl L1BlockInfo { let mut rollup_data_gas_cost = U256::from(cost_data.ones) .saturating_mul(U256::from(NON_ZERO_BYTE_COST)) - .saturating_add(U256::from(cost_data.zeroes).saturating_mul(U256::from(ZERO_BYTE_COST))); + .saturating_add( + U256::from(cost_data.zeroes).saturating_mul(U256::from(ZERO_BYTE_COST)), + ); // Prior to regolith, an extra 68 non zero bytes were included in the rollup data costs. if !spec_id.is_enabled_in(SpecId::REGOLITH) { From f2b9285eaf84daf301664accf166b6b851e30e7f Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:44:17 -0400 Subject: [PATCH 3/5] use nonzero for zeroes/ones, make reusable count fn --- crates/interpreter/src/gas/calc.rs | 12 ++++++++++-- crates/revm/src/optimism/l1block.rs | 4 ++-- crates/revm/src/optimism/rollup_cost.rs | 24 ++++++++++-------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/crates/interpreter/src/gas/calc.rs b/crates/interpreter/src/gas/calc.rs index dd434fcd27..349c973416 100644 --- a/crates/interpreter/src/gas/calc.rs +++ b/crates/interpreter/src/gas/calc.rs @@ -351,6 +351,15 @@ pub const fn memory_gas(num_words: u64) -> u64 { .saturating_add(num_words.saturating_mul(num_words) / 512) } +/// This counts the number of zero, and non-zero bytes in the input data. +/// +/// Returns a tuple of (zero_bytes, non_zero_bytes). +pub fn count_zero_bytes(data: &[u8]) -> (u64, u64) { + let zero_data_len = data.iter().filter(|v| **v == 0).count() as u64; + let non_zero_data_len = data.len() as u64 - zero_data_len; + (zero_data_len, non_zero_data_len) +} + /// Initial gas that is deducted for transaction to be included. /// Initial gas contains initial stipend gas, gas for access list and input data. pub fn validate_initial_tx_gas( @@ -360,8 +369,7 @@ pub fn validate_initial_tx_gas( access_list: &[(Address, Vec)], ) -> u64 { let mut initial_gas = 0; - let zero_data_len = input.iter().filter(|v| **v == 0).count() as u64; - let non_zero_data_len = input.len() as u64 - zero_data_len; + let (zero_data_len, non_zero_data_len) = count_zero_bytes(input); // initdate stipend initial_gas += zero_data_len * TRANSACTION_ZERO_DATA; diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index 0caf8b7460..0904b746e6 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -134,10 +134,10 @@ impl L1BlockInfo { .wrapping_div(U256::from(1_000_000)); }; - let mut rollup_data_gas_cost = U256::from(cost_data.ones) + let mut rollup_data_gas_cost = U256::from(cost_data.ones.get()) .saturating_mul(U256::from(NON_ZERO_BYTE_COST)) .saturating_add( - U256::from(cost_data.zeroes).saturating_mul(U256::from(ZERO_BYTE_COST)), + U256::from(cost_data.zeroes.get()).saturating_mul(U256::from(ZERO_BYTE_COST)), ); // Prior to regolith, an extra 68 non zero bytes were included in the rollup data costs. diff --git a/crates/revm/src/optimism/rollup_cost.rs b/crates/revm/src/optimism/rollup_cost.rs index 6f08523b94..1fe90c438e 100644 --- a/crates/revm/src/optimism/rollup_cost.rs +++ b/crates/revm/src/optimism/rollup_cost.rs @@ -2,6 +2,8 @@ //! for a transaction. use crate::optimism::fast_lz::flz_compress_len; +use core::num::NonZeroU64; +use revm_interpreter::gas::count_zero_bytes; /// RollupCostData contains three fields, which are used depending on the current optimism fork. /// @@ -10,12 +12,12 @@ use crate::optimism::fast_lz::flz_compress_len; /// /// The `fastlz_size` field is used to compute the data availability costs for a transaction /// post-fjord. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct RollupCostData { /// The number of zeroes in the transaction. - pub(crate) zeroes: u64, + pub(crate) zeroes: NonZeroU64, /// The number of ones in the transaction. - pub(crate) ones: u64, + pub(crate) ones: NonZeroU64, /// The size of the transaction after fastLZ compression. pub(crate) fastlz_size: u32, } @@ -23,17 +25,11 @@ pub struct RollupCostData { impl RollupCostData { /// This takes bytes as input, creating a [`RollupCostData`] struct based on the encoded data. pub fn from_bytes(bytes: &[u8]) -> Self { - let mut data = RollupCostData::default(); - let mut i = 0; - while i < bytes.len() { - if bytes[i] == 0 { - data.zeroes += 1; - } else { - data.ones += 1; - } - i += 1; + let (zeroes, ones) = count_zero_bytes(bytes); + Self { + zeroes: NonZeroU64::new(zeroes).unwrap(), + ones: NonZeroU64::new(ones).unwrap(), + fastlz_size: flz_compress_len(bytes), } - data.fastlz_size = flz_compress_len(bytes); - data } } From e2b498bb3bb08c843be5ee94798c4fb2f309c67a Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 7 Jun 2024 15:11:29 -0400 Subject: [PATCH 4/5] make some more things not U256 --- crates/revm/Cargo.toml | 4 +- crates/revm/src/optimism/l1block.rs | 78 ++++++++++++++--------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 4655f27a33..a4067e3e5f 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -71,7 +71,9 @@ alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d" } [features] -default = ["std", "c-kzg", "secp256k1", "portable", "blst"] +# default = ["std", "c-kzg", "secp256k1", "portable", "blst"] +# for developing in editor w op +default = ["std", "c-kzg", "secp256k1", "portable", "blst", "optimism"] std = [ "serde?/std", "serde_json?/std", diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index 0904b746e6..9cb77fb7b8 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -1,6 +1,5 @@ use crate::optimism::rollup_cost::RollupCostData; use crate::primitives::{address, db::Database, Address, SpecId, U256}; -use core::ops::Mul; const ZERO_BYTE_COST: u64 = 4; const NON_ZERO_BYTE_COST: u64 = 16; @@ -124,25 +123,24 @@ impl L1BlockInfo { /// /// Prior to regolith, an extra 68 non-zero bytes were included in the rollup data costs to /// account for the empty signature. - pub fn data_gas(&self, input: &[u8], spec_id: SpecId) -> U256 { - let cost_data = RollupCostData::from_bytes(input); + pub fn data_gas(&self, cost_data: RollupCostData, spec_id: SpecId) -> u64 { if spec_id.is_enabled_in(SpecId::FJORD) { let estimated_size = self.tx_estimated_size_fjord(cost_data); - return estimated_size - .saturating_mul(U256::from(NON_ZERO_BYTE_COST)) - .wrapping_div(U256::from(1_000_000)); + return (estimated_size as u64) + .saturating_mul(NON_ZERO_BYTE_COST) + .wrapping_div(1_000_000); }; - let mut rollup_data_gas_cost = U256::from(cost_data.ones.get()) - .saturating_mul(U256::from(NON_ZERO_BYTE_COST)) + let mut rollup_data_gas_cost = cost_data.ones.get() + .saturating_mul(NON_ZERO_BYTE_COST) .saturating_add( - U256::from(cost_data.zeroes.get()).saturating_mul(U256::from(ZERO_BYTE_COST)), + cost_data.zeroes.get().saturating_mul(ZERO_BYTE_COST), ); // Prior to regolith, an extra 68 non zero bytes were included in the rollup data costs. if !spec_id.is_enabled_in(SpecId::REGOLITH) { - rollup_data_gas_cost += U256::from(NON_ZERO_BYTE_COST).mul(U256::from(68)); + rollup_data_gas_cost += NON_ZERO_BYTE_COST * 68; } rollup_data_gas_cost @@ -151,13 +149,11 @@ impl L1BlockInfo { // Calculate the estimated compressed transaction size in bytes, scaled by 1e6. // This value is computed based on the following formula: // max(minTransactionSize, intercept + fastlzCoef*fastlzSize) - fn tx_estimated_size_fjord(&self, cost_data: RollupCostData) -> U256 { - let fastlz_size = U256::from(cost_data.fastlz_size); - - fastlz_size - .saturating_mul(U256::from(836_500)) - .saturating_sub(U256::from(42_585_600)) - .max(U256::from(100_000_000)) + fn tx_estimated_size_fjord(&self, cost_data: RollupCostData) -> u32 { + cost_data.fastlz_size + .saturating_mul(836_500) + .saturating_sub(42_585_600) + .max(100_000_000) } /// Calculate the gas cost of a transaction based on L1 block data posted on L2, depending on the [SpecId] passed. @@ -173,16 +169,16 @@ impl L1BlockInfo { if spec_id.is_enabled_in(SpecId::FJORD) { self.calculate_tx_l1_cost_fjord(cost_data) } else if spec_id.is_enabled_in(SpecId::ECOTONE) { - self.calculate_tx_l1_cost_ecotone(input, spec_id) + self.calculate_tx_l1_cost_ecotone(cost_data, spec_id) } else { - self.calculate_tx_l1_cost_bedrock(input, spec_id) + self.calculate_tx_l1_cost_bedrock(cost_data, spec_id) } } /// Calculate the gas cost of a transaction based on L1 block data posted on L2, pre-Ecotone. - fn calculate_tx_l1_cost_bedrock(&self, input: &[u8], spec_id: SpecId) -> U256 { - let rollup_data_gas_cost = self.data_gas(input, spec_id); - rollup_data_gas_cost + fn calculate_tx_l1_cost_bedrock(&self, cost_data: RollupCostData, spec_id: SpecId) -> U256 { + let rollup_data_gas_cost = self.data_gas(cost_data, spec_id); + U256::from(rollup_data_gas_cost) .saturating_add(self.l1_fee_overhead.unwrap_or_default()) .saturating_mul(self.l1_base_fee) .saturating_mul(self.l1_base_fee_scalar) @@ -199,19 +195,19 @@ impl L1BlockInfo { /// /// Function is actually computed as follows for better precision under integer arithmetic: /// `calldataGas*(l1BaseFee*16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar)/16e6` - fn calculate_tx_l1_cost_ecotone(&self, input: &[u8], spec_id: SpecId) -> U256 { + fn calculate_tx_l1_cost_ecotone(&self, cost_data: RollupCostData, spec_id: SpecId) -> U256 { // There is an edgecase where, for the very first Ecotone block (unless it is activated at Genesis), we must // use the Bedrock cost function. To determine if this is the case, we can check if the Ecotone parameters are // unset. if self.empty_scalars { - return self.calculate_tx_l1_cost_bedrock(input, spec_id); + return self.calculate_tx_l1_cost_bedrock(cost_data, spec_id); } - let rollup_data_gas_cost = self.data_gas(input, spec_id); + let rollup_data_gas_cost = self.data_gas(cost_data, spec_id); let l1_fee_scaled = self.calculate_l1_fee_scaled_ecotone(); - l1_fee_scaled - .saturating_mul(rollup_data_gas_cost) + U256::from(l1_fee_scaled) + .saturating_mul(U256::from(rollup_data_gas_cost)) .wrapping_div(U256::from(1_000_000 * NON_ZERO_BYTE_COST)) } @@ -223,7 +219,7 @@ impl L1BlockInfo { let l1_fee_scaled = self.calculate_l1_fee_scaled_ecotone(); let estimated_size = self.tx_estimated_size_fjord(cost_data); - estimated_size + U256::from(estimated_size) .saturating_mul(l1_fee_scaled) .wrapping_div(U256::from(1e12)) } @@ -264,18 +260,19 @@ mod tests { // gas cost = 3 non-zero bytes * NON_ZERO_BYTE_COST + NON_ZERO_BYTE_COST * 68 // gas cost = 3 * 16 + 68 * 16 = 1136 let input = bytes!("FACADE"); - let bedrock_data_gas = l1_block_info.data_gas(&input, SpecId::BEDROCK); - assert_eq!(bedrock_data_gas, U256::from(1136)); + let cost_data = RollupCostData::from_bytes(&input); + let bedrock_data_gas = l1_block_info.data_gas(cost_data, SpecId::BEDROCK); + assert_eq!(bedrock_data_gas, 1136); // Regolith has no added 68 non zero bytes // gas cost = 3 * 16 = 48 - let regolith_data_gas = l1_block_info.data_gas(&input, SpecId::REGOLITH); - assert_eq!(regolith_data_gas, U256::from(48)); + let regolith_data_gas = l1_block_info.data_gas(cost_data, SpecId::REGOLITH); + assert_eq!(regolith_data_gas, 48); // Fjord has a minimum compressed size of 100 bytes // gas cost = 100 * 16 = 1600 - let fjord_data_gas = l1_block_info.data_gas(&input, SpecId::FJORD); - assert_eq!(fjord_data_gas, U256::from(1600)); + let fjord_data_gas = l1_block_info.data_gas(cost_data, SpecId::FJORD); + assert_eq!(fjord_data_gas, 1600); } #[test] @@ -294,18 +291,19 @@ mod tests { // gas cost = 3 non-zero * NON_ZERO_BYTE_COST + 2 * ZERO_BYTE_COST + NON_ZERO_BYTE_COST * 68 // gas cost = 3 * 16 + 2 * 4 + 68 * 16 = 1144 let input = bytes!("FA00CA00DE"); - let bedrock_data_gas = l1_block_info.data_gas(&input, SpecId::BEDROCK); - assert_eq!(bedrock_data_gas, U256::from(1144)); + let cost_data = RollupCostData::from_bytes(&input); + let bedrock_data_gas = l1_block_info.data_gas(cost_data, SpecId::BEDROCK); + assert_eq!(bedrock_data_gas, 1144); // Regolith has no added 68 non zero bytes // gas cost = 3 * 16 + 2 * 4 = 56 - let regolith_data_gas = l1_block_info.data_gas(&input, SpecId::REGOLITH); - assert_eq!(regolith_data_gas, U256::from(56)); + let regolith_data_gas = l1_block_info.data_gas(cost_data, SpecId::REGOLITH); + assert_eq!(regolith_data_gas, 56); // Fjord has a minimum compressed size of 100 bytes // gas cost = 100 * 16 = 1600 - let fjord_data_gas = l1_block_info.data_gas(&input, SpecId::FJORD); - assert_eq!(fjord_data_gas, U256::from(1600)); + let fjord_data_gas = l1_block_info.data_gas(cost_data, SpecId::FJORD); + assert_eq!(fjord_data_gas, 1600); } #[test] From 16ae23f1af47a24e21b088992c6c68d5eec673bc Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 28 Jun 2024 20:51:45 -0400 Subject: [PATCH 5/5] fix: don't use nonzerou64 for zeros,ones --- crates/revm/src/optimism/l1block.rs | 10 +++++----- crates/revm/src/optimism/rollup_cost.rs | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index 9cb77fb7b8..8c45f91cf6 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -132,11 +132,10 @@ impl L1BlockInfo { .wrapping_div(1_000_000); }; - let mut rollup_data_gas_cost = cost_data.ones.get() + let mut rollup_data_gas_cost = cost_data + .ones .saturating_mul(NON_ZERO_BYTE_COST) - .saturating_add( - cost_data.zeroes.get().saturating_mul(ZERO_BYTE_COST), - ); + .saturating_add(cost_data.zeroes.saturating_mul(ZERO_BYTE_COST)); // Prior to regolith, an extra 68 non zero bytes were included in the rollup data costs. if !spec_id.is_enabled_in(SpecId::REGOLITH) { @@ -150,7 +149,8 @@ impl L1BlockInfo { // This value is computed based on the following formula: // max(minTransactionSize, intercept + fastlzCoef*fastlzSize) fn tx_estimated_size_fjord(&self, cost_data: RollupCostData) -> u32 { - cost_data.fastlz_size + cost_data + .fastlz_size .saturating_mul(836_500) .saturating_sub(42_585_600) .max(100_000_000) diff --git a/crates/revm/src/optimism/rollup_cost.rs b/crates/revm/src/optimism/rollup_cost.rs index 1fe90c438e..4ea810a2a9 100644 --- a/crates/revm/src/optimism/rollup_cost.rs +++ b/crates/revm/src/optimism/rollup_cost.rs @@ -2,7 +2,6 @@ //! for a transaction. use crate::optimism::fast_lz::flz_compress_len; -use core::num::NonZeroU64; use revm_interpreter::gas::count_zero_bytes; /// RollupCostData contains three fields, which are used depending on the current optimism fork. @@ -15,9 +14,9 @@ use revm_interpreter::gas::count_zero_bytes; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct RollupCostData { /// The number of zeroes in the transaction. - pub(crate) zeroes: NonZeroU64, + pub(crate) zeroes: u64, /// The number of ones in the transaction. - pub(crate) ones: NonZeroU64, + pub(crate) ones: u64, /// The size of the transaction after fastLZ compression. pub(crate) fastlz_size: u32, } @@ -27,8 +26,8 @@ impl RollupCostData { pub fn from_bytes(bytes: &[u8]) -> Self { let (zeroes, ones) = count_zero_bytes(bytes); Self { - zeroes: NonZeroU64::new(zeroes).unwrap(), - ones: NonZeroU64::new(ones).unwrap(), + zeroes, + ones, fastlz_size: flz_compress_len(bytes), } }