perf(l2): compute base blob fee once per block#6006
Open
xqft wants to merge 11 commits into
Open
Conversation
Replace U256 arithmetic with i128 for EIP-4844 blob gas calculation when running in zkVM (zisk/sp1/risc0). This is safe because: - factor = MIN_BASE_FEE_PER_BLOB_GAS (1) - numerator = parent_excess_blob_gas (u64, typically < 100M) - denominator = update_fraction (u64, ~8.8M for mainnet) Expected savings: 25-30M steps (3.8-4.5%) from reduced checked arithmetic overhead and smaller integer operations. Includes test to verify i128 matches U256 for typical values.
…r zkVM Apply same i128 optimization to levm's get_base_fee_per_blob_gas function which is called during transaction execution. This is the main call site with ~769 calls per block.
Lines of code reportTotal lines added: Detailed view |
Benchmark Results ComparisonNo significant difference was registered for any benchmark run. Detailed ResultsBenchmark Results: BubbleSort
Benchmark Results: ERC20Approval
Benchmark Results: ERC20Mint
Benchmark Results: ERC20Transfer
Benchmark Results: Factorial
Benchmark Results: FactorialRecursive
Benchmark Results: Fibonacci
Benchmark Results: FibonacciRecursive
Benchmark Results: ManyHashes
Benchmark Results: MstoreBench
Benchmark Results: Push
Benchmark Results: SstoreBench_no_opt
|
Contributor
|
Just wanted to add a quick comment, I tested this with mainnet blocks without zkVMs and the improvement is also noticeable! Maybe I'll upload a picture later of the results. Edit: It's with a tool that I'm building, I tested random branches and I just saw that yours had a noticeable speedup |
Contributor
Author
|
@JereSalo Nice!! yeah would love to include those results in the description too |
Benchmark Block Execution Results Comparison Against Main
|
Oppen
approved these changes
Jan 23, 2026
ilitteri
approved these changes
Jan 26, 2026
azteca1998
approved these changes
Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimizes EIP-4844 blob gas calculation by computing
base_blob_fee_per_gasonce per block instead of twice per transaction, eliminating redundantfake_exponentialcalls per block.Motivation
The base blob fee per gas is constant for all transactions in a block (determined by
parent_excess_blob_gasandbase_fee_update_fraction), yet it was being recomputed:setup_env()(once per transaction)-
calculate_blob_gas_cost()during transaction execution (viadeduct_caller)This optimization computes the value once at the block level and reuses it.
Changes
Modified:
calculate_blob_gas_cost()now accepts pre-computedbase_blob_fee_per_gasfrom Environmentexecute_block()andexecute_block_pipeline()compute the value once before the transaction loopsetup_env()acceptsbase_blob_fee_per_gasas a parameter instead of computing itexecute_tx,execute_tx_in_block,trace_tx_calls,warm_block,rerun_blockPerformance Results
SP1 - Block 24292781 (mainnet, 341 transactions)
All cycle savings are concentrated in the transaction execution phase (
execute_block), confirming the optimization eliminates redundant calculations during transaction processing.ZisK - Block 24292781 (mainnet, 341 transactions)
Cost Distribution Changes:
Test Configuration: