Skip to content
Smart contracts Audit finding Intermediate

BalancerConnector has incorrect implementation of totalSupply, positionTVL and total TVL will be invalid

The BalancerConnector contract incorrectly uses totalSupply() instead of totalActualSupply() when calculating the value of a user's position in a Balancer pool. This causes the total value locked (TVL) and share calculations to be wrong, potentially leading to incorrect share pricing.

oakcobalt Follow with grearlake, BenRai and 5 others

Originally disclosed on Code4rena

Submitted by oakcobalt, also found by grearlake, BenRai, pkqs90, DPS, SeveritySquad, Sentryx, and cu5t0mpeo

Proof of Concept

In BalancerConnector::_getPositionTVL, when calculating connector held LP token ratio, IERC20(pool.pool).totalSupply() is called. This is an incorrect implementation.

In Balancer, totalSupply() is different from totalActualSupply(). Based on Balancer doc:

getActualSupply: This is the most common/current function to call. getActualSupply is used by the most recent versions of Weighted and Stable Pools. It accounts for pre-minted BPT as well as due protocol fees.

totalSupply: In general, totalSupply only makes sense to call for older “legacy” pools. The original Weighted and Stable Pools do not have pre-minted BPT, so they follow the typical convention of using totalSupply to account for issued pool shares.

In short, totalSupply will include pre-minted BPT(balancer pool tokens) and shouldn’t be used when calculating user position value. The pool’s arithmetic behaves as if it didn’t exist, and the BPT total supply is not a useful value. getAcutalSupply should be used instead.

//contracts/connectors/BalancerConnector.sol
    function _getPositionTVL(HoldingPI memory p, address base) public view override returns (uint256) {
        PositionBP memory PTI = registry.getPositionBP(vaultId, p.positionId);
        PoolInfo memory pool = abi.decode(PTI.additionalData, (PoolInfo));
        uint256 lpBalance = totalLpBalanceOf(pool);
        (, uint256[] memory _tokenBalances,) = IBalancerVault(balancerVault).getPoolTokens(pool.poolId);
|>      uint256 _totalSupply = IERC20(pool.pool).totalSupply();

        uint256 _weight = pool.weights[pool.tokenIndex];

        uint256 token1bal = valueOracle.getValue(pool.tokens[pool.tokenIndex], base, _tokenBalances[pool.tokenIndex]);
|>      return (((1e18 * token1bal * lpBalance) / _weight) / _totalSupply);
    }

(https://github.com/code-423n4/2024-04-noya/blob/9c79b332eff82011dcfa1e8fd51bad805159d758/contracts/connectors/BalancerConnector.sol#L167)

In addition, in BalancerConnecot.t.sol we can see the intention is to use weighted pools with pre-minted BPT(USDC-DAI-USDT Stable Pool). Based on the deployed pool contract, totalSupply is 2596148430608596515167161432296901 . totalAcutalSupply is 1036029413274776191102780.

Recommended Mitigation Steps

Use IERC20(pool.pool).totalActualSupply() with compatible pools.

HadiEsna (NOYA) confirmed and commented:

True, needs to be fixed. But not high severity I think.

gzeon (judge) commented:

Considering as High Risk due to TVL impact share calculation.


The original report as published on Code4rena, by oakcobalt. 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 used totalSupply() instead of totalActualSupply() for Balancer pools that have pre-minted BPT, so the total supply included tokens that should not count.

Impact

The total value locked and share calculations for the vault could be incorrect, which may affect how shares are priced for users.

What the attacker needed

Vault uses BalancerConnector with a pool that has…

The fix

The code should use totalActualSupply() instead of totalSupply() for compatible Balancer pools.

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 report is about a smart contract that calculates how much a user's investment is worth. It used the wrong number for the total number of pool tokens, which made the calculated value too low. That could cause users to get incorrect shares when they deposit or withdraw.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by oakcobalt

View all

50 more disclosed reports, best first.

More from NOYA

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.