Use the widening mul_ratio helper in the driver fee-to-sell-token conversion#4671
Use the widening mul_ratio helper in the driver fee-to-sell-token conversion#4671squadgazzz wants to merge 1 commit into
Conversation
|
Claude finished @squadgazzz's task in 1m 50s —— View job PR Review: Overflow-safe fee conversion
Verdict: LGTM. The change is correct and faithfully preserves the previous semantics while fixing the latent false-overflow.
Non-blocking follow-up (out of scope): Skipping a fixture-heavy test here is reasonable given the helper's existing unit coverage of widening/rounding. |
27e30dc to
f786297
Compare
jmg-duarte
left a comment
There was a problem hiding this comment.
LGTM but another concern about how we're modelling the math
| .checked_mul_ratio(&prices.buy, &prices.sell) | ||
| .ok_or(Math::Overflow)? |
There was a problem hiding this comment.
I wonder if we should just make the checked_mul_ratio return Result instead of Option; since it already checks for the div by zero internally, it would make more sense to erase the error into an option as needed instead of duplicating the check to augment the option into a result (with error info)
There was a problem hiding this comment.
Probably makes sense now. Will open a follow-up PR out of the hotfix.
f786297 to
1fdc3e0
Compare
1fdc3e0 to
8aa8fa1
Compare
Description
Companion to #4669. The driver's
protocol_fee_in_sell_tokenconverts a buy-token fee into the sell token by multiplying with the solution's clearing prices in 256 bits, the same unwidened pattern that zeroed 26 executions on xdai when a solver scaled its prices to 1e60. Here the input is a/solveresponse rather than solver-authored calldata, so nothing has broken yet, but an overflow silently discards an otherwise valid solution and puts an arbitrary cap on how solvers may scale their solution prices.The conversion now goes through
number::U256Ext::checked_mul_ratio, the shared helper #4669 introduced (the driver's ownutil::mathwrappers were folded into it there).Changes
protocol_fee_in_sell_tokenuseschecked_mul_ratiowith an explicit zero-divisor guard, preserving theDivisionByZerovsOverflowdistinctionHow to test
Existing tests. The conversion now delegates to
checked_mul_ratio, whose unit tests already cover the widening and rounding behavior; a fixture-heavy test at this level would only re-prove the helper.Related issues
Fixes #4670