Skip to content

fix(executor): account for tip when computing max L2 gas limit#3346

Open
AvivYossef-starkware wants to merge 1 commit intoequilibriumco:mainfrom
AvivYossef-starkware:fix/l2-gas-limit-tip-overflow
Open

fix(executor): account for tip when computing max L2 gas limit#3346
AvivYossef-starkware wants to merge 1 commit intoequilibriumco:mainfrom
AvivYossef-starkware:fix/l2-gas-limit-tip-overflow

Conversation

@AvivYossef-starkware
Copy link
Copy Markdown
Contributor

@AvivYossef-starkware AvivYossef-starkware commented Apr 16, 2026

Account for the tip when computing the maximum L2 gas amount covered by the account balance during fee estimation.


Problem: get_max_l2_gas_amount_covered_by_balance divides remaining balance by l2_gas.max_price_per_unit to compute the max affordable L2 gas. However, the blockifier's max_possible_fee (used in verify_can_pay_committed_bounds) computes max_amount * (max_price + tip). When tip > 0, the inflated L2 gas bound exceeds the account balance, causing starknet_simulateTransactions to reject transactions that succeeded on-chain.

Fix: Divide by (max_price_per_unit + tip) to match the blockifier's fee calculation.

Impact: Observed on mainnet block 8821583 (tx index 1, tip=1001). The old formula computed max_l2_gas = 128,174,880,959. The blockifier then checked 128,174,880,959 * (60,200,000,000 + 1001) = 7.716T > balance of 7.716T — failing by ~128 trillion FRI due to the unaccounted tip. The fix computes max_l2_gas = 128,174,878,828 which passes the balance check.

Note: Juno has the same bug in calculate_max_l2_gas_covered (vm/rust/src/entrypoint/execute/process/binary_search_execution.rs:201).


  • add all user-facing changes to CHANGELOG.md

The max L2 gas amount covered by balance was computed by dividing
the remaining balance by `max_price_per_unit`. However, the blockifier's
`max_possible_fee` multiplies by `(max_price_per_unit + tip)`. When the
tip is non-zero, this mismatch causes the inflated L2 gas bound to
exceed the account balance, rejecting transactions that succeed on-chain.

Fix: divide by `(max_price_per_unit + tip)` to match the blockifier's
fee calculation.

Observed on mainnet block 8821583 (tx index 1) where tip=1001 caused
the balance check to fail by ~128 trillion FRI.
Copy link
Copy Markdown
Contributor

@CHr15F0x CHr15F0x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % fmt

@zvolin
Copy link
Copy Markdown
Contributor

zvolin commented Apr 17, 2026

just a general question, maybe you'll know, why is the tip accounted per gas unit? From the docs I can see it is correct, but (max_amount * max_price) + tip would feel more natural to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants