Open github-actions[bot] opened 1 year ago
Agree with the proposed solution.
Great finding, agree with medium severity
Fix implemented at https://github.com/Bond-Protocol/options/pull/5
Will look into this, seems all the duplicate suggest the fix:
lastEpochClaimed[msg.sender] = epoch;
but the implemented fix is
lastEpochClaimed[msg.sender] = epoch -1
maybe testing can help as well, just want to make sure there is no off-by-one issue o(╥﹏╥)o
Will look into this, seems all the duplicate suggest the fix:
lastEpochClaimed[msg.sender] = epoch;
but the implemented fix is
lastEpochClaimed[msg.sender] = epoch -1
maybe testing can help as well, just want to make sure there is no off-by-one issue o(╥﹏╥)o
The reason to set lastEpochClaimed to epoch - 1
is that you want the user state to appear like they have claimed everything before the epoch they started staking on. They haven't claimed any tokens for the current epoch yet, so that would be inaccurate.
@ctf-sec did you have a chance to review this more?
Yes, fix looks good
bin2chen
medium
stake() missing set lastEpochClaimed when userBalance equal 0
Summary
because
stake()
don't setlastEpochClaimed[user] = last epoch
ifuserBalance
equal 0 So all new stake user must loop from 0 tolast epoch
for_claimRewards()
As the epoch gets bigger and bigger it will waste a lot of GAS, which may eventually lead toGAS_OUT
Vulnerability Detail
in
stake()
, when the first-time stake() onlyrewardsPerTokenClaimed[msg.sender]
but don't setlastEpochClaimed[msg.sender]
so every new staker , needs claims from 0
With each new addition of epoch, the new stake must consumes a lot of useless loops, from loop 0 to
last epoch
Whenepoch
reaches a large size, it will result in GAS_OUT and the method cannot be executedImpact
When the
epoch
gradually increases, the new take will waste a lot of GAS When it is very large, it will cause GAS_OUTCode Snippet
https://github.com/sherlock-audit/2023-06-bond/blob/main/options/src/fixed-strike/liquidity-mining/OTLM.sol#L324-L327
Tool used
Manual Review
Recommendation