The BaseGauge contract contains a vulnerability where users can earn rewards without staking, minting, or performing any legitimate action. This issue arises from how the _applyBoost function calculates the boost, leading to unintended reward distributions even to users with no stake.
Affected code: BaseGauge::earned
The earned function calculates rewards using the getUserWeight function, which in turn calls _applyBoost. The boost calculation incorrectly applies the minBoost value to users with zero balance. Since minBoost is set to 1e18, the calculation still applies a base weight, resulting in rewards being distributed to non-stakers.
Since boost is always at least minBoost, users without stake can still receive rewards, as getUserWeight returns a nonzero value.
The earned function calls getUserWeight to determine the user's weight in the reward distribution.
getUserWeight calculates the base weight and applies a boost using the _applyBoost function.
The _applyBoost function checks the user's balance of veTokens. Since the balance is zero, it calculates the boost using the calculateBoost function.
The calculateBoost function returns the minBoost value (1e18) when the user's balance is zero, ensuring that the base weight is applied without any reduction.
Impact of minBoost:
Since minBoost is set to 1e18, the base weight is multiplied by 1e18 and divided by 1e18 in the _applyBoost function, effectively returning the base weight unchanged.
This means that even users with no staked tokens receive rewards based on the base weight of the gauge.
Paste the following into BaseGauge.test.js to demonstrate the issue:
Users can receive rewards without participating in the staking process.
This can lead to an unfair distribution of rewards and financial losses for legitimate stakers.
Attackers can repeatedly claim rewards with different accounts without any stake, leading to fund depletion.
Manual Review
Ensure Base Weight is Nonzero: Modify _applyBoost to only apply a boost if the user's balance is greater than zero.
Require Staking Before Earning: Enforce a check in getUserWeight that prevents non-stakers from receiving rewards.
Explicitly Verify Stake Existence: Add validation in earned to confirm that the user has an actual stake before calculating 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.