An edge case in amplifier allows user to stake after end time, causing reward to be locked in the contract
The staking contract only checks the end time when a previous stake exists, so if nobody staked before the deadline a user can still stake afterwards. That stake prevents the admin from withdrawing the rewards, locking them in the contract indefinitely.
evan Follow with HollaDieWaldfee, hansfriese and 1 other
Originally disclosed on Code4rena
Submitted by evan, also found by HollaDieWaldfee, hansfriese, and chaduke
Observe that if nobody has staked after the period has ended, it’s still possible for a single user to stake even though the period has ended. https://github.com/code-423n4/2023-03-mute/blob/main/contracts/amplifier/MuteAmplifier.sol#L208-L212
if (firstStakeTime == 0) {
firstStakeTime = block.timestamp;
} else {
require(block.timestamp < endTime, "MuteAmplifier::stake: staking is over");
}
The staker can’t get any of the rewards because the update modifier won’t drip the rewards (since _mostRecentValueCalcTime = firstStakeTime >= endTime). https://github.com/code-423n4/2023-03-mute/blob/main/contracts/amplifier/MuteAmplifier.sol#L89-L95
if (_mostRecentValueCalcTime == 0) {
_mostRecentValueCalcTime = firstStakeTime;
}
uint256 totalCurrentStake = totalStake();
if (totalCurrentStake > 0 && _mostRecentValueCalcTime < endTime) {
...
}
At the same time, the protocol can’t withdraw the rewards with rescueToken either since there is a staker, and no reward has been claimed yet (so the following check fails). https://github.com/code-423n4/2023-03-mute/blob/main/contracts/amplifier/MuteAmplifier.sol#L187
else if (tokenToRescue == muteToken) {
if (totalStakers > 0) {
require(amount <= IERC20(muteToken).balanceOf(address(this)).sub(totalRewards.sub(totalClaimedRewards)),
"MuteAmplifier::rescueTokens: that muteToken belongs to stakers"
);
}
}
Impact
Suppose the staking period ends and nobody has staked. The admin would like to withdraw the rewards. A malicious user can front-run the rescueTokens call with a call to stake to lock all the rewards inside the contract indefinitely.
Recommended Mitigation Steps
https://github.com/code-423n4/2023-03-mute/blob/main/contracts/amplifier/MuteAmplifier.sol#L208-L212
The require shouldn’t be inside the else block.
mattt21 (Mute Switch) confirmed
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 end-time check is inside the else branch, so it is skipped when firstStakeTime is zero.
Impact
All rewards can be locked in the contract indefinitely, and the staker cannot claim them either.
What the attacker needed
No one staked before the deadline; attacker can front-run the rescue call
How it was found
- Wait until the staking period has ended with no prior stakers.
- Call stake before the admin calls rescueTokens.
- The stake succeeds because the end-time check is skipped.
- The admin's rescueTokens call now fails because totalStakers is greater than 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 staking contract lets people put tokens in to earn rewards during a fixed period. The code only checked the deadline if someone had already staked, so the first person could join after the deadline. That late stake then blocked the owner from taking back the unclaimed rewards.
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.