fix: use checked arithmetic for cumulative gas accounting in payload builder#24
fix: use checked arithmetic for cumulative gas accounting in payload builder#24Himess wants to merge 2 commits intocirclefin:mainfrom
Conversation
…builder Use checked_add and saturating_add for cumulative gas tracking to prevent potential u64 overflow, consistent with the defensive arithmetic pattern applied to reward_beneficiary in circlefin#21.
3d93e31 to
eae0f2a
Compare
|
Overflow here is not practically reachable -- |
…review Per reviewer feedback, saturating_add silently clamps at u64::MAX which would corrupt cumulative_gas_used rather than fail the block build cleanly. Switch to checked_add with PayloadBuilderError propagation, matching the defensive pattern used at the capacity check on line 579.
|
Thanks for the review @atiwari-circle. Agreed, replaced |
Summary
Use checked arithmetic for cumulative gas accounting in the payload builder to prevent potential overflow on
u64addition.Two instances in
arc_ethereum_payload:cumulative_gas_used + pool_tx.gas_limit()— replaced withchecked_add+is_none_orto reject the transaction if the addition overflowscumulative_gas_used += gas_used— replaced withsaturating_addto prevent wrappingThis follows the same defensive arithmetic pattern applied to
reward_beneficiaryin #21, whereu128multiplication was replaced withU256arithmetic to prevent overflow.