Calculation underflow/overflow in BalancerPairOracle, which will affect pools in Aura Finance
The BalancerPairOracle contract calculates LP token prices using arithmetic that can underflow or overflow, causing the price calculation to revert. This means that for Balancer-like collateral tokens, the oracle will fail in most cases, preventing their use as collateral.
Source: https://github.com/sherlock-audit/2023-04-blueberry-judging/issues/11
Found by
n1punp
Summary
LP price calculation for Balancer Pair in BalancerPairOracle will produce calculation underflow/overflow (so Aura pools won't work too).
Vulnerability Detail
- The values r0, r1 can underflow, e.g. if resA < resB --> r0 = 0, so it'll go to the else case --> and so
ratiowill be 0 -->fairResAcalculation will revert upon dividing by 0. - There are also other math calculations there that will cause reverts, e.g. ratio ** wB will lead to overflow. What you'd need here is Balancer's implementation of
bpowor similar.
Impact
LP price for Balancer-like collateral token will revert in most cases, if not all.
Code Snippet
Tool used
Manual Review
Recommendation
- Change the calculation logic so it aligns with Alpha's original implementation (with precision control), e.g. https://github.com/AlphaFinanceLab/alpha-homora-v2-contract/blob/master/contracts/oracle/BalancerPairOracle.sol#L42-L53 (you can see there's BONE extra precision in each step)
Discussion
n1punp
Escalate for 10 USDC.
I think this is incorrectly excluded. The issue is not related to flashloan via BalancerPairOracle, but rather an organic math overflow/underflow, since the implementation is directly using 0.8.x's default SafeMath mode. Upon certain conditions (e.g. resA < resB the calculation will always revert).
sherlock-admin
Escalate for 10 USDC. I think this is incorrectly excluded. The issue is not related to flashloan via BalancerPairOracle, but rather an organic math overflow/underflow, since the implementation is directly using 0.8.x's default SafeMath mode. Upon certain conditions (e.g.
resA < resBthe calculation will always revert).
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
ctf-sec
I don't think this report has sufficient prove
hrishibhat
Escalation accepted
Considering this issue a valid medium
sherlock-admin
Escalation accepted
Considering this issue a valid medium
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the calculation uses direct multiplication and division without sufficient precision or overflow protection, leading to underflow when reserves are unequal and overflow when raising a ratio to a power.
What the attacker needed
Balancer-like collateral token used; reserves unequal (resA < resB)
The fix
The calculation logic should be changed to align with Alpha's original implementation, which includes extra precision (BONE) in each step.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where a price calculation can fail because the numbers become too small or too large for the computer to handle. When the calculation fails, the system cannot determine the price of a token, so it stops working for that token.