perf(l2): compute base blob fee once per block#6001
Closed
xqft wants to merge 6 commits into
Closed
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
|
Replace the i128 conditional compilation approach with block-level caching to reduce redundant fake_exponential calls from ~1536 per block to 1. Changes: - Remove fake_exponential_i128() and all cfg(zkvm) conditional compilation - Update calculate_blob_gas_cost() to use pre-computed base_blob_fee_per_gas from Environment instead of recomputing (eliminates ~768 calls/block) - Compute base_blob_fee_per_gas once in execute_block/execute_block_pipeline and pass to all transactions (eliminates ~768 calls/block) - Thread the pre-computed value through setup_env, execute_tx, and execute_tx_in_block functions - Update all call sites in tracing, warm_block, and Evm wrapper Benefits: - Simpler codebase: removes 89 lines of conditional compilation - Same or better performance: 1 U256 fake_exponential vs 1536 i128 operations - More maintainable: single code path for all execution contexts - Architecturally correct: block-level constants computed at block level Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Document the block-level base blob fee caching optimization that achieved -7.86% step reduction (-50.4M steps) on mainnet block 24291039. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Benchmark Block Execution Results Comparison Against Main
|
Contributor
Author
|
superseded by #6006 |
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, while also simplifying the codebase by removing conditional compilation that was added in a previous approach.
Changes
Removed:
fake_exponential_i128()function and all zkVM-specific conditional compilation (#[cfg(any(feature = "zisk", feature = "sp1", feature = "risc0"))])block.rsandutils.rsModified:
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
ZisK Profile - Block 24291039 (mainnet, 382 transactions)
Function-Level Impact
LEVM::execute_tx(382 calls)LEVM::execute_blockVM::execute(386 calls)Memory Operations
Benefits
Test Plan
cargo test -p ethrex-common- All tests passcargo test -p ethrex-vm- All tests passcargo test -p ethrex-levm- All tests passRelated
scripts/zkvm-bench/logbook.md(Entry docs: add milestones #1)zerocopy_triebase branch