From d1884c9de1a5972dc3cea6efabd5891e9d8c4505 Mon Sep 17 00:00:00 2001 From: Cody Wang Date: Tue, 1 Oct 2024 16:51:36 -0400 Subject: [PATCH] fix fmt and clippy --- crates/protocol/src/fee.rs | 23 ++++++++++++----------- crates/protocol/src/lib.rs | 2 +- crates/protocol/src/utils.rs | 7 +++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/protocol/src/fee.rs b/crates/protocol/src/fee.rs index 1c208417..c321e1f9 100644 --- a/crates/protocol/src/fee.rs +++ b/crates/protocol/src/fee.rs @@ -1,5 +1,5 @@ //! This module contains the L1 block fee calculation function. -use alloy_primitives::{bytes, U256}; +use alloy_primitives::U256; use crate::utils::flz_compress_len; use core::ops::Mul; @@ -11,7 +11,8 @@ const NON_ZERO_BYTE_COST: u64 = 16; /// Calculate the data gas for posting the transaction on L1. /// /// In bedrock, calldata costs 16 gas per non-zero byte and 4 gas per zero byte, with -/// an extra 68 non-zero bytes were included in the rollup data costs to account for the empty signature. +/// an extra 68 non-zero bytes were included in the rollup data costs to account for the empty +/// signature. pub fn data_gas_bedrock(input: &[u8]) -> U256 { data_gas_regolith(input) + U256::from(NON_ZERO_BYTE_COST).mul(U256::from(68)) } @@ -92,8 +93,8 @@ pub fn calculate_tx_l1_cost_regolith( /// L1 cost function: /// `(calldataGas/16)*(l1BaseFee*16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar)/1e6` /// -/// We divide "calldataGas" by 16 to change from units of calldata gas to "estimated # of bytes when compressed". -/// Known as "compressedTxSize" in the spec. +/// We divide "calldataGas" by 16 to change from units of calldata gas to "estimated # of bytes when +/// compressed". Known as "compressedTxSize" in the spec. /// /// Function is actually computed as follows for better precision under integer arithmetic: /// `calldataGas*(l1BaseFee*16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar)/16e6` @@ -164,7 +165,7 @@ fn calculate_l1_fee_scaled_ecotone( #[cfg(test)] mod tests { use super::*; - use alloy_primitives::hex; + use alloy_primitives::{bytes, hex}; #[test] fn test_data_gas_bedrock() { @@ -238,8 +239,8 @@ mod tests { let l1_fee_overhead = U256::from(1_000); let l1_fee_scalar = U256::from(1_000); - // calldataGas * (l1BaseFee * 16 * l1BaseFeeScalar + l1BlobBaseFee * l1BlobBaseFeeScalar) / (16 * 1e6) - // = (16 * 3 + 16 * 68 + 1000) * 1000 * 1000 / (1_000_000) + // calldataGas * (l1BaseFee * 16 * l1BaseFeeScalar + l1BlobBaseFee * l1BlobBaseFeeScalar) / + // (16 * 1e6) = (16 * 3 + 16 * 68 + 1000) * 1000 * 1000 / (1_000_000) // = 2136 let input = bytes!("FACADE"); let gas_cost = @@ -266,8 +267,8 @@ mod tests { let l1_fee_overhead = U256::from(1_000); let l1_fee_scalar = U256::from(1_000); - // calldataGas * (l1BaseFee * 16 * l1BaseFeeScalar + l1BlobBaseFee * l1BlobBaseFeeScalar) / (16 * 1e6) - // = (16 * 3 + 1000) * 1000 * 1000 / (1_000_000) + // calldataGas * (l1BaseFee * 16 * l1BaseFeeScalar + l1BlobBaseFee * l1BlobBaseFeeScalar) / + // (16 * 1e6) = (16 * 3 + 1000) * 1000 * 1000 / (1_000_000) // = 1048 let input = bytes!("FACADE"); let gas_cost = @@ -294,8 +295,8 @@ mod tests { let blob_base_fee_scalar = U256::from(1_000); let base_fee_scalar = U256::from(1_000); - // calldataGas * (l1BaseFee * 16 * l1BaseFeeScalar + l1BlobBaseFee * l1BlobBaseFeeScalar) / (16 * 1e6) - // = (16 * 3) * (1000 * 16 * 1000 + 1000 * 1000) / (16 * 1e6) + // calldataGas * (l1BaseFee * 16 * l1BaseFeeScalar + l1BlobBaseFee * l1BlobBaseFeeScalar) / + // (16 * 1e6) = (16 * 3) * (1000 * 16 * 1000 + 1000 * 1000) / (16 * 1e6) // = 51 let input = bytes!("FACADE"); let gas_cost = calculate_tx_l1_cost_ecotone( diff --git a/crates/protocol/src/lib.rs b/crates/protocol/src/lib.rs index a9d68e70..47081df5 100644 --- a/crates/protocol/src/lib.rs +++ b/crates/protocol/src/lib.rs @@ -46,5 +46,5 @@ pub use block_info::{L1BlockInfoBedrock, L1BlockInfoEcotone, L1BlockInfoTx}; pub mod fee; pub use fee::{ calculate_tx_l1_cost_bedrock, calculate_tx_l1_cost_ecotone, calculate_tx_l1_cost_fjord, - calculate_tx_l1_cost_regolith, data_gas_bedrock, data_gas_regolith, data_gas_fjord, + calculate_tx_l1_cost_regolith, data_gas_bedrock, data_gas_fjord, data_gas_regolith, }; diff --git a/crates/protocol/src/utils.rs b/crates/protocol/src/utils.rs index 9aea0109..7b7aa5f6 100644 --- a/crates/protocol/src/utils.rs +++ b/crates/protocol/src/utils.rs @@ -208,8 +208,7 @@ fn u24(input: &[u8], idx: u32) -> u32 { #[cfg(test)] mod tests { use super::*; - use alloy_sol_types::sol; - use alloy_sol_types::SolCall; + use alloy_sol_types::{sol, SolCall}; use revm::{ db::BenchmarkDB, primitives::{address, bytes, Bytecode, Bytes, TxKind, U256}, @@ -252,8 +251,8 @@ mod tests { #[case::base_0x6905051352691641888d0c427fb137c5b95afb5870d5169ff014eff1d0952195(bytes!("b87202f86f8221058303dc6c8310db1f84068fa8d7838954409436af2ff952a7355c8045fcd5e88bc9f6c8257f7b8080c001a0b89e7ff3d7694109e73e7f4244e032581670313c36e48e485c9c94b853bd81d2a038ffaf8f10859ce21d1f7f7046c3d08027fb8aa15b69038f6102be97aaa1179a"))] #[case::base_0x6a38e9a26d7202a2268de69d2d47531c1a9829867579a483fb48d78e9e0b080d(bytes!("b9049b02f904978221058201618506fc23ac008506fc23ac008306ddd0943fc91a3afd70395cd496c647d5a6cc9d4b2b7fad80b904243593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000006641d67b00000000000000000000000000000000000000000000000000000000000000030a000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000088487bd8c3222d64d1d0b3fa7098dcf9d94d79e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000006669635d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad000000000000000000000000000000000000000000000000000000006641d78900000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000418661369ca026f92ff88347bd0e3625a7b5ed65071b366368c68ad7c55aed136c18659b34f9246e30a784227a53dd374fbd3d2124696808c678cd987c4e954a681b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000549e5c020c764dbfffff00000000000000000000000000000000000000000000000002e5a629c093a2b600000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002b088487bd8c3222d64d1d0b3fa7098dcf9d94d79e0027104200000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000c001a014a3acef764ff6d3bb9bd81e420bfa94171a5734ab997dfbc9b41b653ce018a4a01ff5fccb01ef5c60ba3aef67d4e74f3f47312dd78bfbbff9e5090fbf2d3d62bb"))] fn test_flz_native_evm_parity(#[case] input: Bytes) { - // This bytecode and ABI is for a contract, which wraps the LibZip library for easier fuzz testing. - // The source of this contract is here: https://github.com/danyalprout/fastlz/blob/main/src/FastLz.sol#L6-L10 + // This bytecode and ABI is for a contract, which wraps the LibZip library for easier fuzz + // testing. The source of this contract is here: https://github.com/danyalprout/fastlz/blob/main/src/FastLz.sol#L6-L10 sol! { interface FastLz { function fastLz(bytes input) external view returns (uint256);