Amplifier users might not get all the LP fees they are entitled to
The amplifier contract only claims LP fees inside a conditional block that requires the last calculation time to be before the staking end time. Once any user triggers an update after the end time, the condition can never be true again, so fees earned afterwards are never claimed and stay trapped in the pair.
Submitted by evan
Observe that there is only one place that the amplifier is calling claimFees, and it’s inside an if statement of the update modifier, requiring _mostRecentValueCalcTime < endTime.
https://github.com/code-423n4/2023-03-mute/blob/main/contracts/amplifier/MuteAmplifier.sol#L111
modifier update() {
if (_mostRecentValueCalcTime == 0) {
_mostRecentValueCalcTime = firstStakeTime;
}
uint256 totalCurrentStake = totalStake();
if (totalCurrentStake > 0 && _mostRecentValueCalcTime < endTime) {
uint256 value = 0;
uint256 sinceLastCalc = block.timestamp.sub(_mostRecentValueCalcTime);
uint256 perSecondReward = totalRewards.div(endTime.sub(firstStakeTime));
if (block.timestamp < endTime) {
value = sinceLastCalc.mul(perSecondReward);
} else {
uint256 sinceEndTime = block.timestamp.sub(endTime);
value = (sinceLastCalc.sub(sinceEndTime)).mul(perSecondReward);
}
_totalWeight = _totalWeight.add(value.mul(10**18).div(totalCurrentStake));
_mostRecentValueCalcTime = block.timestamp;
(uint fee0, uint fee1) = IMuteSwitchPairDynamic(lpToken).claimFees();
_totalWeightFee0 = _totalWeightFee0.add(fee0.mul(10**18).div(totalCurrentStake));
_totalWeightFee1 = _totalWeightFee1.add(fee1.mul(10**18).div(totalCurrentStake));
totalFees0 = totalFees0.add(fee0);
totalFees1 = totalFees1.add(fee1);
}
_;
}
Consider the following situation. An user X has staked a large amount of LP tokens, and a user Y has staked a normal amount.
Y withdraws as soon as the staking period ends (block.timestamp > endTime), triggering the update modifier, which sets _mostRecentValueCalcTime = block.timestamp > endTime. Observe that after this point, the amplifier will never call claimFees again since _mostRecentValueCalcTime < endTime will forever be false.
Meanwhile, X forgot about it, and doesn’t withdraw until say 2 weeks after endTime. When X calls withdraw, X won’t get the LP fees for those 2 weeks. In fact, nobody will - they are trapped inside the mute switch pair forever since the amplifier won’t call claim.
Impact
Some LP fees can be trapped inside the mute switch pair when it should really be going to the amplifier users.
Recommended Mitigation Steps
I believe it’s best to move the LP fee calculation out of the if statement.
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
Likely the fee-claiming logic is nested inside a time-gated condition, so once the stored timestamp passes the end time the claim path becomes unreachable.
Impact
LP fees earned after the end time can be trapped in the pair and never reach amplifier users.
What the attacker needed
Users have staked LP tokens; staking period has ended; one user withdraws after the end time
How it was found
- User Y withdraws right after the staking period ends, triggering the update modifier.
- The modifier sets the last calculation time to the current block timestamp, which is past the end time.
- User X withdraws later, but the fee claim is skipped because the time condition is now false.
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.
Users put tokens into a contract and earn a share of trading fees. The contract only collects those fees while a timer condition holds. If someone interacts after the staking period ends, the timer is pushed past the end, so the contract stops collecting fees and later users lose their share.
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.