Skip to content

fix(vm): account for tip when computing max L2 gas limit#3562

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

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

Conversation

@AvivYossef-starkware
Copy link
Copy Markdown

Summary

Account for the tip when computing the maximum L2 gas amount covered by the account balance in calculate_max_l2_gas_covered.

Problem: The remaining balance is divided 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_per_unit + 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) > balance — failing by ~128 trillion FRI. The fix computes a slightly lower max_l2_gas that passes the balance check.

Note: Same bug exists in Pathfinder (fix submitted at equilibriumco/pathfinder#3346).

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, tip=1001).
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.78%. Comparing base (3c2b557) to head (fa9ea82).
⚠️ Report is 96 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3562      +/-   ##
==========================================
- Coverage   75.70%   70.78%   -4.93%     
==========================================
  Files         389      396       +7     
  Lines       35512    36853    +1341     
==========================================
- Hits        26885    26086     -799     
- Misses       6753     8943    +2190     
+ Partials     1874     1824      -50     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@rodrodros rodrodros left a comment

Choose a reason for hiding this comment

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

Thanks for the fix

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.

2 participants