yieldFeeBalance wouldn’t be claimed after calling transferTokensOut()
Originally disclosed on Code4rena
Submitted by 0xhunter20
yieldFeeBalance wouldn’t be claimed after calling transferTokensOut() due to the twab supply limit.
Proof of Concept
When _tokenOut == address(this), liquidatableBalanceOf() mints shares to the receiver and accumulates yieldFeeBalance accordingly.
But when it checks the maximum liquidatable amount in liquidatableBalanceOf(), it validates the twap supply limit with the liquidYield only; it might meet the supply limit while minting yieldFeeBalance like the below:
- We assume
totalSupply = 6e28,yieldFeeBalance = 0,twabSupplyLimit = 2^96 - 1 = 7.9e28and the vault has enough available yield. - Then
liquidatableBalanceOf(_tokenOut = address(this))will return_maxAmountOut = 7.9e28 - 6e28 = 1.9e28when_liquidYield > _maxAmountOut. - After calling
transferTokensOut()with_amountOut = 1.9e28,_yieldFeewill be added toyieldFeeBalancebut it can’t be claimed as we met the twap supply limit already.
Recommended Mitigation Steps
liquidatableBalanceOf() shouldn’t apply yieldFeePercentage to compare with _maxAmountOut when _tokenOut == address(this).
function liquidatableBalanceOf(address _tokenOut) public view returns (uint256) {
uint256 _totalSupply = totalSupply();
uint256 _maxAmountOut;
if (_tokenOut == address(this)) {
// Liquidation of vault shares is capped to the TWAB supply limit.
_maxAmountOut = _twabSupplyLimit(_totalSupply);
} else if (_tokenOut == address(_asset)) {
// Liquidation of yield assets is capped at the max yield vault withdraw plus any latent balance.
_maxAmountOut = _maxYieldVaultWithdraw() + _asset.balanceOf(address(this));
} else {
return 0;
}
// The liquid yield is computed by taking the available yield balance and multiplying it
// by (1 - yieldFeePercentage), rounding down, to ensure that enough yield is left for the
// yield fee.
uint256 _liquidYield = _availableYieldBalance(totalAssets(), _totalDebt(_totalSupply));
if (_tokenOut == address(this)) {
if (_liquidYield >= _maxAmountOut) { //compare before applying yieldFeePercentage
_liquidYield = _maxAmountOut;
}
_liquidYield = _liquidYield.mulDiv(FEE_PRECISION - yieldFeePercentage, FEE_PRECISION);
} else {
_liquidYield = _liquidYield.mulDiv(FEE_PRECISION - yieldFeePercentage, FEE_PRECISION);
if (_liquidYield >= _maxAmountOut) { //same as before
_liquidYield = _maxAmountOut;
}
}
return _liquidYield;
}
Assessed type
Invalid Validation
The impact is the same as #91 but the flaw still exists after mitigating #91 because
liquidatableBalanceOf()doesn’t use the newly accumulated yield fees while checking_twabSupplyLimit.
trmid (PoolTogether) confirmed and commented:
Similar to #91, this issue outlines the need for the TWAB supply limit checks to account for the yield fee balance so that the entire yield fee balance is always available to be realized as shares.
Mitigation here.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in PoolTogether. Code4rena made it public on 4 April 2024. Found in the 2024-03-pooltogether audit contest (finding M-05).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.