op_alloy_protocol::fee

Function calculate_tx_l1_cost_ecotone

Source
pub fn calculate_tx_l1_cost_ecotone(
    input: &[u8],
    base_fee: U256,
    base_fee_scalar: U256,
    blob_base_fee: U256,
    blob_base_fee_scalar: U256,
) -> U256
Expand description

Calculate the gas cost of a transaction based on L1 block data posted on L2, post-Ecotone.

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.

Function is actually computed as follows for better precision under integer arithmetic: calldataGas*(l1BaseFee*16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar)/16e6