Skip to content
Business logic Audit finding Intermediate

_computeAvailable() the calculations are wrong

The _computeAvailable function in VaultBooster incorrectly caps the accrued delta amount against the total token balance, which already includes previously available tokens, so the returned available amount can exceed the actual balance. This causes liquidation functions to attempt transfers larger than the balance, leading to failed transactions.

bin2chen Follow with Angry_Mustache_Man, dirk_y and 1 other

Originally disclosed on Code4rena

Submitted by bin2chen, also found by Angry_Mustache_Man, dirk_y, and Giorgio

_computeAvailable() incorrect calculations that result in a return value greater than the current balance, causing methods such as liquidate to fail.

Proof of Concept

VaultBooster._computeAvailable() used to count the number of tokens currently available. There are two conditions:

  1. accrue continuously according to time
  2. the final cumulative value cannot be greater than the current contract balance

The code is as follows:

  function _computeAvailable(IERC20 _tokenOut) internal view returns (uint256) {
    Boost memory boost = _boosts[_tokenOut];
    uint256 deltaTime = block.timestamp - boost.lastAccruedAt;
    uint256 deltaAmount;
    if (deltaTime == 0) {
      return boost.available;
    }
    if (boost.tokensPerSecond > 0) {
      deltaAmount = boost.tokensPerSecond * deltaTime;
    }
    if (boost.multiplierOfTotalSupplyPerSecond.unwrap() > 0) {
      uint256 totalSupply = twabController.getTotalSupplyTwabBetween(address(vault), uint32(boost.lastAccruedAt), uint32(block.timestamp));
      deltaAmount += convert(boost.multiplierOfTotalSupplyPerSecond.intoUD60x18().mul(convert(deltaTime)).mul(convert(totalSupply)));
    }
@>  uint256 availableBalance = _tokenOut.balanceOf(address(this));
@>  deltaAmount = availableBalance > deltaAmount ? deltaAmount : availableBalance;
    return boost.available + deltaAmount;
  }

The current implementation code, limiting the maximum value of deltaAmount is wrong, using the minimum value compared to the current balance _tokenOut.balanceOf(address(this)).

But the current balance includes the previously accumulated boost.available, so normally it should be compared to the difference between the current balance and boost.available.

So the value returned may be larger than the current balance, and LiquidationPair.sol performs source.liquidatableBalanceOf() and source.liquidate() with too large a number, resulting in a failed transfer.

Recommended Mitigation Steps

The maximum value returned should not exceed the current balance

  function _computeAvailable(IERC20 _tokenOut) internal view returns (uint256) {
    Boost memory boost = _boosts[_tokenOut];
    uint256 deltaTime = block.timestamp - boost.lastAccruedAt;
    uint256 deltaAmount;
    if (deltaTime == 0) {
      return boost.available;
    }
    if (boost.tokensPerSecond > 0) {
      deltaAmount = boost.tokensPerSecond * deltaTime;
    }
    if (boost.multiplierOfTotalSupplyPerSecond.unwrap() > 0) {
      uint256 totalSupply = twabController.getTotalSupplyTwabBetween(address(vault), uint32(boost.lastAccruedAt), uint32(block.timestamp));
      deltaAmount += convert(boost.multiplierOfTotalSupplyPerSecond.intoUD60x18().mul(convert(deltaTime)).mul(convert(totalSupply)));
    }
    uint256 availableBalance = _tokenOut.balanceOf(address(this));
-   deltaAmount = availableBalance > deltaAmount ? deltaAmount : availableBalance;
-   return boost.available + deltaAmount;
+   uint256 result = boost.available + deltaAmount;
+   if (result > availableBalance) result = availableBalance;
+   return result;

  }

Assessed type

Context

asselstine (PoolTogether) confirmed


The original report as published on Code4rena, by bin2chen. 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

The code caps the newly accrued delta amount against the total token balance instead of the balance minus the already available amount, so the sum of available plus delta can exceed the balance.

Impact

Liquidation calls may fail because the computed available amount exceeds the actual token balance, preventing successful transfers.

What the attacker needed

None

The fix

The function should cap the final result (boost.available plus deltaAmount) to the current token balance, rather than capping deltaAmount alone.

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 smart contract function that calculates how many tokens are available for liquidation mistakenly compares the newly accrued tokens against the entire contract balance, which already includes tokens that were previously available. This can make the function report more tokens than the contract actually holds, so when a liquidation tries to transfer that amount, it fails because there aren't enough tokens.

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 bin2chen

View all

139 more disclosed reports, best first.

More from PoolTogether

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.