Skip to content

Commit

Permalink
fix fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-wang-cb committed Oct 1, 2024
1 parent 9d53524 commit d1884c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
23 changes: 12 additions & 11 deletions crates/protocol/src/fee.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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))
}
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 =
Expand All @@ -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 =
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
7 changes: 3 additions & 4 deletions crates/protocol/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d1884c9

Please sign in to comment.