Users redeem strategy tokens but receives no assets in return
A rounding error in the strategy token to BPT conversion can result in zero BPT claim when a user redeems a small amount of strategy tokens. The redeem function then returns zero without reverting, so the user burns their strategy tokens but receives no assets.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-12-notional-judging/issues/10
Found by
xiaoming90
Summary
Due to a rounding error in Solidity, it is possible that a user burns their strategy tokens, but receives no assets in return due to issues in the following functions:
- StrategyUtils._convertStrategyTokensToBPTClaim
- Boosted3TokenPoolUtils._redeem
- TwoTokenPoolUtils._redeem
Vulnerability Detail
This affects both the TwoToken and Boosted3Token vaults
int256 internal constant INTERNAL_TOKEN_PRECISION = 1e8;
uint256 internal constant BALANCER_PRECISION = 1e18;
Within the StrategyUtils._convertStrategyTokensToBPTClaim function, it was observed that if the numerator is smaller than the denominator, the bptClaim will be zero.
File: StrategyUtils.sol
18: function _convertStrategyTokensToBPTClaim(StrategyContext memory context, uint256 strategyTokenAmount)
19: internal pure returns (uint256 bptClaim) {
20: require(strategyTokenAmount <= context.vaultState.totalStrategyTokenGlobal);
21: if (context.vaultState.totalStrategyTokenGlobal > 0) {
22: bptClaim = (strategyTokenAmount * context.vaultState.totalBPTHeld) / context.vaultState.totalStrategyTokenGlobal;
23: }
24: }
When the bptClaim is zero, the function returns zero instead of reverting. Therefore, it is possible that a user redeems ("burns") their strategy tokens, but receives no assets in return because the number of strategy tokens redeemed by the user is too small.
File: Boosted3TokenPoolUtils.sol
432: function _redeem(
433: ThreeTokenPoolContext memory poolContext,
434: StrategyContext memory strategyContext,
435: AuraStakingContext memory stakingContext,
436: uint256 strategyTokens,
437: uint256 minPrimary
438: ) internal returns (uint256 finalPrimaryBalance) {
439: uint256 bptClaim = strategyContext._convertStrategyTokensToBPTClaim(strategyTokens);
440:
441: if (bptClaim == 0) return 0;
442:
443: finalPrimaryBalance = _unstakeAndExitPool({
444: stakingContext: stakingContext,
445: poolContext: poolContext,
446: bptClaim: bptClaim,
447: minPrimary: minPrimary
448: });
449:
450: strategyContext.vaultState.totalBPTHeld -= bptClaim;
451: strategyContext.vaultState.totalStrategyTokenGlobal -= strategyTokens.toUint80();
452: strategyContext.vaultState.setStrategyVaultState();
453: }
Impact
Loss of assets for the users as they burn their strategy tokens, but receive no assets in return.
Code Snippet
Tool used
Manual Review
Recommendation
Consider reverting if the assets (bptClaim) received is zero. This check has been implemented in many well-known vault designs as this is a commonly known issue (e.g. Solmate)
function _redeem(
ThreeTokenPoolContext memory poolContext,
StrategyContext memory strategyContext,
AuraStakingContext memory stakingContext,
uint256 strategyTokens,
uint256 minPrimary
) internal returns (uint256 finalPrimaryBalance) {
uint256 bptClaim = strategyContext._convertStrategyTokensToBPTClaim(strategyTokens);
- if (bptClaim == 0) return 0;
+ require(bptClaim > 0, "zero asset")
finalPrimaryBalance = _unstakeAndExitPool({
stakingContext: stakingContext,
poolContext: poolContext,
bptClaim: bptClaim,
minPrimary: minPrimary
});
strategyContext.vaultState.totalBPTHeld -= bptClaim;
strategyContext.vaultState.totalStrategyTokenGlobal -= strategyTokens.toUint80();
strategyContext.vaultState.setStrategyVaultState();
}
Discussion
weitianjie2000
valid, will fix
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 integer division truncation in the conversion from strategy tokens to BPT claim, combined with a check that returns zero instead of reverting when the claim is zero.
Impact
Users could lose their strategy tokens without receiving any assets in return.
What the attacker needed
User redeems a small amount of strategy tokens
The fix
The redeem function should revert if the calculated BPT claim is zero, as implemented in many well-known vault designs.
How it was found
- User calls redeem with a small amount of strategy tokens.
- The function _convertStrategyTokensToBPTClaim calculates bptClaim as zero due to rounding.
- The _redeem function sees bptClaim == 0 and returns 0 without reverting.
- The user's strategy tokens are burned but no assets are returned.
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 you put money into a vault, you get tokens representing your share. Later, you can trade these tokens back for the underlying assets. This report found that if you try to redeem a very small number of these tokens, a maths rounding issue can make the system think you are owed nothing, but it still takes your tokens away. So you lose your tokens and get no money back.