Donated Tokens Cannot Be Recovered If A Shelter Is Deactivated
When a shelter is deactivated, donated LP tokens are transferred back to the ConvexStakingWrapper contract and become stuck because they are not credited to any user. An attacker could donate tokens and then trigger deactivation, causing those tokens to be permanently lost.
Submitted by leastwood, also found by reassor
The shelter mechanism can be activated and deactivated on a target LP token. The owner of the ConvexStakingWrapper.sol contract can initiate the shelter whereby LP tokens are sent to the Shelter.sol contract. However, if the owner decides to deactivate the shelter before the grace period has passed, all LP tokens are transferred back to the ConvexStakingWrapper.sol contract. Donated tokens are also sent back to the contract. As a result, these tokens do not actually belong to any user and will effectively be lost in the contract.
Proof of Concept
function donate(IERC20 _token, uint256 _amount) external {
require(activated[_token] != 0, "!activated");
savedTokens[_token] += _amount;
_token.safeTransferFrom(msg.sender, address(this), _amount);
}
ConvexStakingWrapper.sol#L107-L130
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);
}
}
function exitShelter(uint256[] calldata _pids) external onlyOwner {
for(uint256 i = 0; i<_pids.length; i++){
IRewardStaking pool = IRewardStaking(convexPool[_pids[i]]);
IERC20 lpToken = IERC20(
pool.poolInfo(_pids[i]).lptoken
);
amountInShelter[lpToken] = 0;
shelter.deactivate(lpToken);
}
}
Recommended Mitigation Steps
Consider allocating donated LP tokens to the contract owner when a shelter is deactivated. This can be done by checking for an excess of LP tokens. Anything greater than amountInShelter can be considered as donated.
Alex the Entreprenerd (judge) commented:
The warden has indentified a way to potentially lose tokens, ultimately the contract could be rewritten to constantly allow redemption.
For those reasons, and because the sponsor acknowledged, I believe the finding to be valid and of medium severity.
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 exitShelter function deactivates the shelter and transfers all LP tokens back to the wrapper without distinguishing donated tokens from user deposits, leaving donated tokens stranded.
Impact
Donated LP tokens could be permanently lost if the shelter is deactivated, as they become stuck in the wrapper contract.
What the attacker needed
Shelter is activated; user donates tokens; owner deactivates shelter
The fix
The contract should be modified to allocate donated LP tokens to the contract owner upon shelter deactivation, by checking for excess tokens above the recorded amount.
How it was found
- Owner activates shelter for a target LP token via enterShelter.
- A user donates LP tokens to the shelter using the donate function.
- Owner calls exitShelter to deactivate the shelter before the grace period ends.
- All LP tokens, including donated ones, are transferred back to the ConvexStakingWrapper contract.
- Donated tokens remain stuck in the contract with no way to recover them.
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 temporary holding place for tokens. Users can donate tokens to it. If the shelter is turned off, all tokens go back to the main contract, but the contract does not know who donated them, so they get stuck. This means donated tokens can be lost forever.
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.