Rewards can be claimed multiple times #3
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
johnnycash
Vulnerability details
Impact
An attacker can claim its reward 256 *
epochDuration
seconds after the timestamp at which the promotion started. The vulnerability allows him to claim a reward several times to retrieve all the tokens associated to the promotion.Analysis
claimRewards()
claim rewards for a given promotion and epoch. In order to prevent a user from claiming a reward multiple times, the mapping _claimedEpochs keeps track of claimed rewards per user:(The comment is wrong, epochs are packed into a uint256 which allows 256 epochs to be stored).
_epochIds
is an array ofuint256
. For each_epochId
in this array,claimRewards()
checks that the reward associated to this_epochId
isn't already claimed thanks to_isClaimedEpoch()
. _isClaimedEpoch() checks that the bit_epochId
of_claimedEpochs
is unset:However, if
_epochId
is greater than 255,_isClaimedEpoch()
always returns false. It allows an attacker to claim a reward several times._calculateRewardAmount() just makes use of
_epochId
to tell whether the promotion is over.Proof of Concept
The following test should result in a reverted transaction, however the transaction succeeds.
Tools Used
Text editor.
Recommended Mitigation Steps
A possible fix could be to change the type of
_epochId
touint8
in:_calculateRewardAmount()
_updateClaimedEpoch()
_isClaimedEpoch()
and change the type of
_epochIds
touint8[]
inclaimRewards()
.The text was updated successfully, but these errors were encountered: