The SDLPoolPrimary
contract's reward distribution mechanism is subject to manipulation because of the way payments are calculated. A global rewardPerToken variable is used to calculate staker rewards and is increased whenever new rewards are added to the pool via the distributeToken function. Nevertheless, this method enables a malicious actor to easily purchase SDL tokens and stake prior to the distributeToken function being called, thereby rapidly accumulating a portion of rewards that were intended to be credited to other stakers. The malicious actor can then immediately claim the rewards, unstake and sell his sdl
therefore stealing rewards from other stakers.
Consider the following scenario:
Assume we have 10 sdl
tokens staked before for alice . and the rewardPerToken is 1 reward
Bob monitors the mempool and observes a pending transaction that will trigger a reward distribution with 100 reward
.
Bob sends 100 SDL
tokens triggering onTokenTransfer
to deposit and front-run the pending reward distribution transaction. In this case bob userRewardPerTokenPaid
will be 1
, and Bob got 0 reward
in rewards.
Once the distributeToken
transaction is confirmed, rewardPerToken
is updated to be : rewardPerToken += 100 / 110 ≈ 1.9 reward
.
Bob immediately calls withdrawRewards
to claim the rewards based on the updated rewardPerToken
which will be according to the following formula :
Bob_staked * (rewardPerToken - userRewardPerTokenPaid[Bob]) = 100 * (1.9 - 1) =
90 reward
Bob then calls withdraw
to withdraw his SDL tokens from the SdlPool
.
By following this steps, Bob was able to instantly obtain 90% of the rewards, which put other stakers at a disadvantage.
console after running test :
This attack enables an actor to unfairly claim a portion of the rewards that were intended to be attributed to other stakers without actually staking SDL tokens.
Manual Review
One possible approach is to add a lock period before calling distributeToken
in which those who staked during that period will not receive rewards.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.