revm_optimism/
transaction.rs

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