Boosted3TokenPoolUtils.sol : _redeem - updating the `totalBPTHeld , totalStrategyTokenGlobal` after `_unstakeAndExitPool` is not safe
In the _redeem function, the contract calls _unstakeAndExitPool before reducing totalBPTHeld and totalStrategyTokenGlobal, so the recorded balances stay stale during that external call. The author suggests a re-entrancy risk but does not show a concrete attack, and the sponsor notes re-entrancy is already blocked on the vault controller side.
Source: https://github.com/sherlock-audit/2022-12-notional-judging/issues/30
Found by
ak1
Summary
_redeem function is used to claim the BPT amount using the strategy tokens.
It is first calling the _unstakeAndExitPool function and then updating the totalBPTHeld , totalStrategyTokenGlobal
Vulnerability Detail
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;
finalPrimaryBalance = _unstakeAndExitPool({
stakingContext: stakingContext,
poolContext: poolContext,
bptClaim: bptClaim,
minPrimary: minPrimary
});
strategyContext.vaultState.totalBPTHeld -= bptClaim;
strategyContext.vaultState.totalStrategyTokenGlobal -= strategyTokens.toUint80();
strategyContext.vaultState.setStrategyVaultState();
}
First _unstakeAndExitPool is called and then totalBPTHeld and totalStrategyTokenGlobal are updated.
Impact
Reentering during any of the function call inside _unstakeAndExitPool could be problematic.
stakingContext.auraRewardPool.withdrawAndUnwrap(bptClaim, false)
BalancerUtils._swapGivenIn
Well it need deep study to analyze the impact, but I would suggest to update the balance first and then call the _unstakeAndExitPool
Code Snippet
Tool used
Manual Review
Recommendation
First update totalBPTHeld and totalStrategyTokenGlobal and then call the _unstakeAndExitPool
Discussion
weitianjie2000
invalid: we have disallow re-entrancy on the vault controller side
weitianjie2000
valid: we've decided to make the fix just in case
jeffywu
Agree, we can mark this issue as valid although I disagree with the High severity rating here. There is no clear re-entrancy vector that has been articulated and the code being called in _unstakeAndExitPool is both known and trusted (both Balancer and Aura).
hrishibhat
Agree with the sponsor about the issue being medium as there is no re-entrancy attack described in the issue. Considering this a medium severity issue.
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
Impact
The stale accounting could allow re-entrancy during the withdraw or swap calls, but no concrete attack is described and the vault controller reportedly blocks re-entrancy.
What the attacker needed
Ability to trigger _redeem; re-entrancy not blocked
The fix
The balances should be updated before calling _unstakeAndExitPool, and the project decided to make that change as a precaution.
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 is a smart contract that tracks how many pool tokens and strategy tokens it holds. It sends tokens out through an external call before it updates its own records, so during that call the records are out of date. If an attacker could run code in that gap, they might act on the wrong numbers, but the report does not prove such an attack works.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.