Skip to content
Audit finding Intermediate

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.

n1punp Follow

Originally disclosed on Sherlock

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 ratio will be 0 --> fairResA calculation 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 bpow or similar.

Impact

LP price for Balancer-like collateral token will revert in most cases, if not all.

Code Snippet

https://github.com/sherlock-audit/2023-04-blueberry/blob/main/blueberry-core/contracts/oracle/BalancerPairOracle.sol#L53-L64

Tool used

Manual Review

Recommendation

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 < resB the 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.

The original report as published on Sherlock, by n1punp. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by n1punp

View all

2 more disclosed reports, best first.

More from Blueberry Update #3

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.