ConvexStakingWrapper.enterShelter() May Erroneously Overwrite amountInShelter Leading To Locked Tokens
The enterShelter function overwrites the amountInShelter value instead of adding to it, so calling it again on the same LP token can set the recorded amount to zero. This can prevent users from withdrawing their tokens from the shelter, potentially locking them permanently after the grace period.
Submitted by leastwood
The shelter mechanism provides emergency functionality in an effort to protect users’ funds. The enterShelter function will withdraw all LP tokens from the pool, transfer them to the shelter contract and activate the shelter for the target LP token. If this function is called again on the same LP token, the amountInShelter value is overwritten, potentially by the zero amount. As a result its possible that the shelter is put in a state where no users can withdraw from it or only a select few users with a finite number of shares are able to. Once the shelter has passed its grace period, these tokens may forever be locked in the shelter contract.
Proof of Concept
ConvexStakingWrapper.sol#L107-L119
function enterShelter(uint256[] calldata _pids) external onlyOwner {
for(uint256 i = 0; i<_pids.length; i++){
IRewardStaking pool = IRewardStaking(convexPool[_pids[i]]);
uint256 amount = pool.balanceOf(address(this));
pool.withdrawAndUnwrap(amount, false);
IERC20 lpToken = IERC20(
pool.poolInfo(_pids[i]).lptoken
);
amountInShelter[lpToken] = amount;
lpToken.safeTransfer(address(shelter), amount);
shelter.activate(lpToken);
}
}
ConvexStakingWrapper.sol#L132-L135
function totalShare(IERC20 _token) external view override returns(uint256) {
// this will be zero if shelter is not activated
return amountInShelter[_token];
}
Recommended Mitigation Steps
Consider adding to the amountInShelter[lpToken] mapping instead of overwriting it altogether. This will allow enterShelter to be called multiple times with no loss of funds for the protocol’s users.
Alex the Entreprenerd (judge) commented:
The finding is valid, the owner can overwrite the
amountInShelterstorage variable causing the math inShelter.withdraw. This will cause issues with distributing previously sheltered tokens.I believe using += instead of overwriting the value may be a sufficient remediation.
Because this is contingent on a “distracted / malicious” admin, I believe Medium Severity to be appropriate.
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 enterShelter function assigns the current pool balance to amountInShelter instead of adding to the existing value, so a second call overwrites the recorded shelter amount.
Impact
Users may be unable to withdraw their tokens from the shelter, and after the grace period those tokens could be permanently locked.
What the attacker needed
Owner calls enterShelter twice on same LP token
The fix
The amountInShelter mapping should be incremented (using +=) rather than overwritten, so multiple calls to enterShelter do not lose track of previously sheltered tokens.
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.
A shelter is a backup contract that holds users' tokens in an emergency. The contract keeps a record of how many tokens are in the shelter, but the function that moves tokens there replaces that record instead of adding to it. If the function runs twice, the record can become wrong (even zero), so users may not be able to get their tokens back.
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.