Skip to content
Business logic Audit finding Intermediate

BalancerConnector::_getPositionTVL is calculated incorrectly

The BalancerConnector contract incorrectly divides the token balance by the pool weight when calculating the total value locked (TVL) of a position, even though the balances returned by Balancer already account for weights. This causes the reported TVL to be much lower than the actual value, potentially misleading users and the protocol.

SBSecurity Follow with ladboy233, DPS and 3 others

Originally disclosed on Code4rena

Submitted by SBSecurity, also found by ladboy233, DPS, SeveritySquad, Sentryx, and 0xAlix2

Impact

BalancerConnector misuses the weight of pool tokens, leading to decreased TVL of these positions.

Proof of Concept

If we take a look at the balancer documentation and especially how the tokens are being valued, we can see that they are not using weight to determine the price of the pool.tokens[pool.tokenIndex]:

BalancerDocs

(tokens, balances, lastChangeBlock) = vault.getPoolTokens(poolId);
prices = fetchPricesFromPriceProvider(tokens); //ex. CoinGecko
poolValueUsd = sum(balances[i]*price[i]);
bptPriceUsd = poolValueUsd/bpt.totalSupply();

As we can see they are directly calculate the balance by the price, which is not the case in Noya:

BalancerConnector.sol#L162-L173

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);
}

The reason why weight is not needed here is because the balances returned from getPoolTokens are already split by them. If we look at the DAI-USDC-USDT pool we will see that balances returned are already splitted and there is no need to be divided by their weights. (Note: please see image in warden’s original submission)

But since Noya uses weights to divide the balance of the tokens, the result will be amount which is percentage weight, set in the pool.weights[pool.tokenIndex], of the actual balance and TVL will be accounted much lower as it is in reality.

Example with USDT and values from BalancerConnector.t.sol:

return (((1e18 * 423099282190 * 991435857075096399976) / 333333333333333333) / 2596148431740844293012911818494888)≈ 0.484

Recommended Mitigation Steps

Do not use weights to evaluate the TVL of the position, instead just refactor the _getPositionTVL’s return with proper decimal scaling based on the asset used.

HadiEsna (NOYA) confirmed


The original report as published on Code4rena, by SBSecurity. 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 contract incorrectly divides the token balance by the pool weight when computing TVL, even though the balance from Balancer's getPoolTokens already reflects the weight.

Impact

The TVL of Balancer positions is understated, which could lead to incorrect valuations and potentially affect protocol decisions or user trust.

What the attacker needed

None

The fix

The fix is to remove the division by weight and adjust the return value with proper decimal scaling based on the asset used.

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 money is in a pool of tokens. The contract made a mistake by dividing the token balance by a weight factor, but the balance already included that weight, so the final number was too small. This could make the pool look less valuable than it really is.

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 SBSecurity

View all

8 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.

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.