Skip to content

fix(miner): use saturating_sub in bid gas-limit check - #401

Open
mark0-cn wants to merge 1 commit into
bnb-chain:mainfrom
mark0-cn:mark0/fix/bid-simulator-saturating-gas
Open

mark0-cn wants to merge 1 commit into
bnb-chain:mainfrom
mark0-cn:mark0/fix/bid-simulator-saturating-gas

Conversation

@mark0-cn

Copy link
Copy Markdown

Summary

The bid gas-limit guard in BidSimulator (src/node/miner/bid_simulator.rs) computed gas_limit - system_txs_gas - PAY_BID_TX_GAS_LIMIT with plain u64 subtraction. The sibling check ~80 lines below already uses saturating_sub for the same quantity, so this is an inconsistency.

If the reserved system-tx gas estimate plus PAY_BID_TX_GAS_LIMIT exceeds the block gas limit, the plain subtraction underflows — panicking in debug builds, and wrapping to a near-u64::MAX value in release, which inverts the check so the "gas limit exceeded" guard never fires. Mainnet gas limits are large so the trigger probability is low, but it's an unguarded arithmetic op on the MEV bid path fed by external builders.

Fix: use saturating_sub, matching the neighbouring code.

The bid gas-limit guard computed `gas_limit - system_txs_gas - PAY_BID_TX_GAS_LIMIT`
with plain u64 subtraction, while the sibling check ~80 lines below already uses
`saturating_sub`. When the reserved system-tx gas estimate plus the pay-bid gas
exceeds the block gas limit, the plain subtraction underflows — panicking in
debug, wrapping to a huge value in release (inverting the check). Use
saturating_sub, matching the neighbouring code.
@mark0-cn
mark0-cn requested a review from joey0612 as a code owner June 22, 2026 10:28
@hashdit-bot

hashdit-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

Pull Request Review

This PR fixes an arithmetic safety bug in the miner bid gas-limit guard by replacing plain u64 subtraction with chained saturating_sub in src/node/miner/bid_simulator.rs. The change aligns this guard with nearby existing logic and prevents underflow behavior that could otherwise panic in debug builds or wrap in release builds. Overall, it hardens bid validation on an externally influenced MEV path without changing business logic.

Sensitive Content

No sensitive content detected.

Security Issues

No serious security issues detected.


Generated by Hashdit Bot. This tool can absolutely NOT replace manual audits.

@mark0-cn

Copy link
Copy Markdown
Author

@joey0612

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.

1 participant