Rebalance will fail due to low precision of percentages
The rebalance function requires the contract's token balance to be zero after deposits, but because percentages are expressed in basis points with low precision, small amounts of dust remain and the check reverts. This causes rebalancing to fail when the last market does not support the token.
Submitted by cmichel, also found by hyh
The AssetManager.rebalance function has a check at the end to ensure that all tokens are deposited again:
require(token.balanceOf(address(this)) == 0, "AssetManager: there are remaining funds in the fund pool");
The idea is that the last market deposits all remainingTokens but the last market does not have to support the token in which case the transaction will fail, or the percentages parameter needs to be chosen to distribute all tokens before the last one (they need to add up to 1e4). However, these percentages have a low precision as they are in base points, i.e, the lowest unit is 1 = 0.01%. This will leave dust in the contract in most cases as the tokens have much higher precision.
POC
Assume the last market does not support the token and thus percentages are chosen as [5000, 5000] to rebalance the first two markets. Withdrawing all tokens form the markets leads to a tokenSupply = token.balanceOf(address(this)) = 10,001:
Then the deposited amount is amountToDeposit = (tokenSupply * percentages[i]) / 10000 = 10,001 * 5,000 / 10,000 = 5,000. The two deposits will leave dust of 10,001 - 2 * 5,000 = 1 in the contract and the token.balanceOf(address(this)) == 0 balance check will revert.
Impact
Rebalancing will fail in most cases if the last market does not support the token due to precision errors.
Recommended Mitigation Steps
Remove the final zero balance check, or make sure that the last market that is actually deposited to receives all remaining tokens.
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 use of integer percentages in basis points (0.01% precision) causes rounding down, leaving dust that violates the zero-balance requirement.
What the attacker needed
Last market does not support the token; percentages do not divide token supply evenly
The fix
Remove the final zero balance check, or make sure that the last market that is actually deposited to receives all remaining tokens.
How it was found
- Choose percentages that sum to 10000 but do not evenly divide the token supply.
- Withdraw all tokens from markets, resulting in a token supply that is not a multiple of 10000.
- Deposit according to percentages, leaving a small remainder.
- The final balance check fails because the contract still holds dust.
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.
When a contract moves tokens between markets, it checks that no tokens are left over. But the percentages used to split the tokens are not precise enough, so tiny amounts get left behind. That makes the check fail and the whole operation stops.
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.