The Staking contract for LoveToken allows users to stake tokens to earn rewards over time, calculated on a weekly basis. This mechanism is designed to reward long-term holders. However, a vulnerability exists where an attacker can exploit the contract's reward calculation logic using a flash loan, enabling them to claim disproportionately high rewards.
The issue lies within the claimRewards
function, which calculates the reward based on the total amount of tokens staked and the time elapsed since the last claim. The contract does not account for the duration each individual token was staked, allowing the calculation of rewards based on the current balance at the time of claim. This oversight makes it possible for an attacker to:
Stake a small amount of tokens.
Wait for a week to become eligible for rewards.
Obtain a large amount of tokens via a flash loan just before claiming rewards.
Deposit the flash-loaned tokens, significantly increasing their staked balance.
Call claimRewards
to claim a large number of rewards based on the artificially inflated staked amount.
Withdraw the flash-loaned tokens and return them to the flash loan provider, keeping the excess rewards.
This vulnerability can lead to the inflation of the reward token's supply, devaluing the token and undermining the integrity of the staking mechanism. It allows attackers to drain the staking pool's rewards with minimal initial investment, potentially causing significant financial loss to the protocol and its legitimate users.
Manual code review
To mitigate this vulnerability and prevent exploitation, consider implementing the following changes:
Snapshot Mechanism: Introduce a mechanism to take snapshots of user balances at each block. Calculate rewards based on the amount of time each token was actually staked, rather than the balance at the time of claiming.
Lock-up Period: Implement a lock-up period for newly deposited tokens, during which these tokens do not earn rewards. This period should be at least as long as the reward calculation period (e.g., one week).
High severity, this allows users to claim additional rewards without committing to intended weekly staking period via multi-deposit/deposit right before claiming 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.