Skip to content
Business logic Audit finding Advanced

Usage of BalancerStrategy.updateCache will cause single sided Loss, discount to Depositor and to OverBorrow from Singularity

The BalancerStrategy caches a pool balance derived from a single-sided withdrawal simulation, which can be manipulated by swapping in the pool. An attacker could temporarily inflate or deflate the strategy's reported balance to over-borrow, unfairly liquidate, or extract value from deposits.

GalloDaSballo Follow with carrotsmuggler, kaden and 1 other

Originally disclosed on Code4rena

Submitted by GalloDaSballo, also found by carrotsmuggler, kaden, and cergyk

The BalancerStrategy uses a cached value to determine it’s balance in pool for which it takes Single Sided Exposure.

This means that the Strategy has some BPT tokens, but to price them, it’s calling vault.queryExit which simulates withdrawing the LP in a single sided manner.

Due to the single sided exposure, it’s trivial to perform a Swap, that will change the internal balances of the pool, as a way to cause the Strategy to discount it’s tokens.

By the same process, we can send more ETH as a way to inflate the value of the Strategy, which will then be cached.

Since _currentBalance is a view-function, the YieldBox will accept these inflated values without a way to dispute them

https://github.com/Tapioca-DAO/tapioca-yieldbox-strategies-audit/blob/05ba7108a83c66dada98bc5bc75cf18004f2a49b/contracts/balancer/BalancerStrategy.sol#L138-L147

    function _deposited(uint256 amount) internal override nonReentrant {
        uint256 queued = wrappedNative.balanceOf(address(this));
        if (queued > depositThreshold) {
            _vaultDeposit(queued);
            emit AmountDeposited(queued);
        }
        emit AmountQueued(amount);

        updateCache(); /// @audit this is updated too late (TODO PROOF)
    }

POC

  • Imbalance the pool (Sandwich A)
  • Update updateCache
  • Deposit into YieldBox, YieldBox is using a view function, meaning it will use the manipulated strategy _currentBalance
  • _deposited trigger an updateCache
  • Rebalance the Pool (Sandwich B)
  • Call updateCache again to bring back the rate to a higher value
  • Withdraw at a gain

Result

Imbalance Up -> Allows OverBorrowing and causes insolvency to the protocol Imbalance Down -> Liquidate Borrowers unfairly at a profit to the liquidator Sandwhiching the Imbalance can be used to extract value from the strategy and steal user deposits as well

Mitigation

Use fair reserve math, avoid single sided exposure (use the LP token as underlying, not one side of it)

cryptotechmaker (Tapioca) confirmed


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

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 strategy prices its single-sided pool position using a manipulable spot simulation (queryExit) and caches the result, rather than using manipulation-resistant reserve math.

Impact

Imbalancing up could allow over-borrowing and insolvency, imbalancing down could unfairly liquidate borrowers, and sandwiching the imbalance could extract value from the strategy and steal user deposits.

What the attacker needed

Ability to swap in the Balancer pool; strategy holds BPT tokens; attacker can deposit and withdraw

The fix

The strategy should use fair reserve math and avoid single-sided exposure by using the LP token as the underlying rather than one side of it.

How it was found

  1. Imbalance the pool (Sandwich A)
  2. Update updateCache
  3. Deposit into YieldBox, which uses the manipulated strategy balance
  4. _deposited triggers an updateCache
  5. Rebalance the Pool (Sandwich B)
  6. Call updateCache again to bring back the rate to a higher value

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.

A strategy contract holds pool tokens and uses a simulated withdrawal to estimate their value. Because that estimate depends on the pool's current balances, someone can swap tokens in the pool to make the estimate wrong for a short time. The strategy then caches that wrong value, which can be used to borrow too much or trade at a profit.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by GalloDaSballo

View all

30 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.