user won’t be able to get his rewards in case of staking with amount = 0
The stake function only calculates pending rewards when the staked amount is greater than zero, but it still updates the reward debt even for zero-amount stakes. A user with pending rewards who calls stake with zero loses those rewards because the debt is increased without crediting the reward.
Originally disclosed on Code4rena
Submitted by CertoraInc, also found by Randyyy
Limbo.sol (stake() function)
If a user has a pending reward and he calls the stake function with amount = 0, he won’t be able to get his reward (he won’t get the reward, and the reward debt will cover the reward)
That’s happening because the reward calculation is done only if the staked amount (given as a parameter) is greater than 0, and it updates the reward debt also if the amount is 0, so the reward debt will be updated without the user will be able to get his reward
gititGoro (Behodler) confirmed and commented:
Good catch! I’d be interested in your mitigation step being provided.
To me, it looks like the simplest solution is just to remove that if statement. Users who stake zero will pay unnecessary gas costs but the contract shouldn’t have to optimise gas consumption for undesired behaviour.
Jack the Pug (judge) increased severity from Low to Medium and commented:
Upgraded to
Medas users can lose their rewards.
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
Users could lose their pending rewards if they stake zero tokens.
What the attacker needed
User has pending rewards; user calls stake with amount 0
The fix
The if statement should be removed so that reward calculation always runs, or the reward debt update should be skipped when the amount is zero.
How it was found
- Have a pending reward in the staking contract.
- Call the stake function with amount = 0.
- The reward debt is updated but the reward is not calculated, so the pending reward is lost.
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.
In a staking contract, users earn rewards over time. The contract tracks how much reward a user has already been credited using a 'reward debt'. If a user stakes zero tokens, the contract still updates this debt but skips calculating the reward, so the user's pending reward is wiped out.
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.