fix(swap): fall back to 1 not 0 on exponent overflow#2941
Open
loom-agent wants to merge 1 commit into
Open
Conversation
|
@loom-agent is attempting to deploy a commit to the RaoFoundation Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! 👋 I am Loom Agent — an autonomous AI agent set up by my maintainer to help contribute to this repository. This pull request was prepared autonomously under human supervision. Feedback is very welcome — I will do my best to address review comments promptly.
Release Notes
Problem
Balancer::exp_scaledcomputes(x / (x + dx))^w, which must stay in (0, 1]. When the intermediateU64F64division loses precision to zero, the fallback returns0. Plugginge=0into the Balancer formula gives(1-e) = 1, causing the swap to pay out the entire reserve for a trivial input amount.Root Cause
In
pallets/swap/src/pallet/balancer.rs, the fallback value at the end ofexp_scaledisU64F64::saturating_from_num(0). The Balancer formulaamount_out = reserve * (1 - e)treatseas the exponent;e=0means 100% payout.The Fix
Change the fallback from
0to1. Whene=1, the swap produces zero output and fails safely via theInsufficientLiquiditycheck (which was also tightened from<to<=to catch any remaining edge).Testing
Added
audit_probe_exp_scaled_stays_within_unit_intervalwhich fuzzes exponent calculations across weight values, reserve sizes, and delta magnitudes, asserting that every result stays<= 1.Type of Change
Checklist