op_revm/
transaction.rs

1//! Contains the `[OpTransaction]` type and its implementation.
2pub mod abstraction;
3pub mod deposit;
4pub mod error;
5
6pub use abstraction::{OpTransaction, OpTxTr};
7pub use error::OpTransactionError;
8
9use crate::fast_lz::flz_compress_len;
10
11/// <https://github.com/ethereum-optimism/op-geth/blob/647c346e2bef36219cc7b47d76b1cb87e7ca29e4/core/types/rollup_cost.go#L79>
12const L1_COST_FASTLZ_COEF: u64 = 836_500;
13
14/// <https://github.com/ethereum-optimism/op-geth/blob/647c346e2bef36219cc7b47d76b1cb87e7ca29e4/core/types/rollup_cost.go#L78>
15/// Inverted to be used with `saturating_sub`.
16const L1_COST_INTERCEPT: u64 = 42_585_600;
17
18/// <https://github.com/ethereum-optimism/op-geth/blob/647c346e2bef36219cc7b47d76b1cb87e7ca29e4/core/types/rollup_cost.go#82>
19const MIN_TX_SIZE_SCALED: u64 = 100 * 1_000_000;
20
21/// Estimates the compressed size of a transaction.
22pub fn estimate_tx_compressed_size(input: &[u8]) -> u64 {
23    let fastlz_size = flz_compress_len(input) as u64;
24
25    fastlz_size
26        .saturating_mul(L1_COST_FASTLZ_COEF)
27        .saturating_sub(L1_COST_INTERCEPT)
28        .max(MIN_TX_SIZE_SCALED)
29}