Permanent funds lock in StargateRewardableWrapper
The StargateRewardableWrapper calls the Stargate staking contract's deposit function during every deposit, withdraw, or transfer, which in turn calls updatePool. If the Stargate admin sets totalAllocPoint to zero, updatePool reverts due to division by zero, causing all such operations to fail and locking user funds in the wrapper.
Originally disclosed on Code4rena
Submitted by auditor0517
The staked funds might be locked because the deposit/withdraw/transfer logic reverts.
Proof of Concept
In StargateRewardableWrapper, _claimAssetRewards() claims the accumulated rewards from the staking contract and it’s called during every deposit/withdraw/transfer in _beforeTokenTransfer() and _claimAndSyncRewards().
function _claimAssetRewards() internal override {
stakingContract.deposit(poolId, 0);
}
And in the stargate staking contract, deposit() calls updatePool() inside the function.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (lpSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);
uint256 stargateReward = multiplier.mul(stargatePerBlock).mul(pool.allocPoint).div(totalAllocPoint); //@audit revert when totalAllocPoint = 0
pool.accStargatePerShare = pool.accStargatePerShare.add(stargateReward.mul(1e12).div(lpSupply));
pool.lastRewardBlock = block.number;
}
function deposit(uint256 _pid, uint256 _amount) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
updatePool(_pid);
...
}
The problem is updatePool() reverts when totalAllocPoint == 0 and this value can be changed by stargate admin using set().
So user funds might be locked like the below.
- The stargate staking contract had one pool and
totalAllocPoint = 10. - In
StargateRewardableWrapper, some users staked their funds using deposit(). - After that, that pool was removed by the stargate admin due to an unexpected reason. So the admin called set(0, 0) to reset the pool. Then
totalAllocPoint = 0now. In the stargate contract, it’s not so critical because this contract has emergencyWithdraw() to rescue funds without caring about rewards. Normal users can withdraw their funds using this function. - But in
StargateRewardableWrapper, there is no logic to be used under the emergency and deposit/withdraw won’t work because_claimAssetRewards()reverts in updatePool() due to 0 division.
Recommended Mitigation Steps
We should implement a logic for an emergency in StargateRewardableWrapper.
During the emergency, _claimAssetRewards() should return 0 without interacting with the staking contract and we should use stakingContract.emergencyWithdraw() to rescue the funds.
Assessed type
Error
cccz (judge) decreased severity to Medium and commented:
External requirement with specific owner behavior.
Add call to
emergencyWithdraw. PR: https://github.com/reserve-protocol/protocol/pull/896
Status: Mitigation confirmed. Full details in reports from ronnyx2017, bin2chen and RaymondFam.
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
User funds could be permanently locked in the wrapper because deposit, withdraw, and transfer all revert, and the wrapper has no emergency withdrawal function.
What the attacker needed
Stargate admin sets totalAllocPoint to 0; Users have funds staked in the wrapper
The fix
The wrapper should implement an emergency mode where _claimAssetRewards() returns without interacting with the staking contract and uses stakingContract.emergencyWithdraw() to rescue funds; this was later mitigated by adding a call to emergencyWithdraw.
How it was found
- The stargate staking contract had one pool and totalAllocPoint = 10.
- Users staked their funds in StargateRewardableWrapper using deposit().
- The stargate admin removed the pool by calling set(0, 0), making totalAllocPoint = 0.
- In StargateRewardableWrapper, deposit/withdraw/transfer fail because _claimAssetRewards() reverts in updatePool() due to division by zero.
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 wrapper contract lets users stake funds and earn rewards. It relies on an external staking contract. If the admin of that external contract changes a setting to zero, a calculation inside it divides by zero and fails. Because the wrapper calls that function on every deposit or withdrawal, users can no longer move their funds, and the wrapper has no emergency exit.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.