The redeem process updates the rewards in the wrong order
The redeem process burns the user's staked tokens before updating their fee rewards, so the reward calculation uses the reduced balance and under-accrues rewards. An attacker could repeatedly redeem to lose out on rewards, though the text does not describe an attack.
Cosine Follow with aman, jennifer37 and 2 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-05-elfi-protocol-judging/issues/274
Found by
Cosine, aman, jennifer37, mstpr-brainbot, pashap9990
Summary
When users redeem their stakeToken's their balance decreases hence right before the redeem request the rewards should be synced. However, the code does the opposite which leads to wrong accrual of rewards.
Vulnerability Detail
As we can see in RedeemProcess::executeRedeemStakeToken(), after the burning of the tokens, the rewards are updated:
function executeRedeemStakeToken(uint256 requestId, Redeem.Request memory redeemRequest) external {
uint256 redeemAmount;
if (CommonData.getStakeUsdToken() == redeemRequest.stakeToken) {
redeemAmount = _redeemStakeUsd(redeemRequest);
} else if (CommonData.isStakeTokenSupport(redeemRequest.stakeToken)) {
redeemAmount = _redeemStakeToken(redeemRequest);
} else {
revert Errors.StakeTokenInvalid(redeemRequest.stakeToken);
}
-> FeeRewardsProcess.updateAccountFeeRewards(redeemRequest.account, redeemRequest.stakeToken);
.
}
However, this approach is incorrect. The actual flow should be to update the account's fee rewards right before the burn to sync the account with its latest accrued rewards. Once this is done and the burn is completed, there is no need to update the account's fee rewards again since the next time the user interacts, the fee rewards will be synced, similar to the typical Masterchef contract approach.
Impact
Unfair accrual of rewards, high.
Code Snippet
Tool used
Manual Review
Recommendation
Accrue the rewards in the beginning function
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/0xCedar/elfi-perp-contracts/pull/29
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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 reward update is called after the token burn instead of before, so the reward calculation uses the post-burn balance.
Impact
Users receive unfairly low rewards when redeeming staked tokens; the text rates this as high impact.
What the attacker needed
User has staked tokens and accrued rewards
The fix
The issue was fixed by moving the reward accrual to the beginning of the redeem function.
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.
When you stake tokens, you earn rewards based on how many you have staked. If you withdraw some tokens, the system should first calculate the rewards you earned up to that point, then reduce your stake. This code does it the other way round, so you get fewer rewards than you should.
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.