A critical vulnerability exist in RAAC Protocol's gauge reward distribution system, specifically in the BaseGauge.sol
and GaugeController.sol
contract. The vulnerability allows attackers to exploit the reward distribution mechanism through front-running attacks, enabling them to capture disproportionate rewards at the expense of legitimate long-term stakers.
This attack leverages the lack of time-weighted staking mechanisms and proper reward distribution safeguards. An attacker would monitor pending reward distributions and strategically time their stakes to maximize reward capture, effectively stealing rewards from users who have staked larger amounts for longer periods.
Affected Functions in BaseGauge.sol:
getRewardPerToken()
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/BaseGauge.sol#L568
- Vulnerable to manipulation of reward rate calculations
earned(address account)
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/BaseGauge.sol#L583
- would be exploited due to immediate reward eligibility
stake(uint256 amount)
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/BaseGauge.sol#L261
- No time-weighted mechanism or minimum stake period
getReward()
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/BaseGauge.sol#L327
- Allows immediate reward claims without vesting
_updateReward(address account)
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/BaseGauge.sol#L167
- Updates rewards without considering stake duration
Affected Functions in GaugeController.sol:``https://github.com/Cyfrin/2025-02-raac/blob/main/contracts/core/governance/gauges/GaugeController.sol
distributeRevenue(GaugeType gaugeType, uint256 amount)
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/GaugeController.sol#L511
- would be front-run
_distributeToGauges(GaugeType gaugeType, uint256 amount
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/GaugeController.sol#L534
- Predictable distribution mechanism
_calculateReward(address gauge)
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/GaugeController.sol#L360
- Linear reward calculation without time-weighting
The flaw allows attackers to exploit these functions by monitoring pending reward distributions and strategically timing their stakes to maximize reward capture. This is possible because:
The reward calculation mechanism in getRewardPerToken(
uses current total supply
without time-weighting
New stakes in stake()
become immediately eligible for rewards.
The distributeRevenue()
function's execution is predictable and can be front-run
getReward()
allows immediate claiming without any vesting period.
This is particularly severe because:
It undermines the core staking incentive mechanism
Allows for systematic exploitation with minimal capital requirement
Disproportionately impacts long-term stakers who are crucial for protocol stability
Creates a negative feedback loop that could lead to mass withdrawals
It stems from several interconnected issues in the reward distribution architecture:
Reward Rate Calculation Flaw: In Baseguage.sol
This calculation uses the current totalSupply()
without considering stake duration, making it vulnerable to manipulation through quick deposits and withdrawals.
2.Immediate Reward Eligibility: In the earned function
: https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/BaseGauge.sol#L583
New stakes immediately become eligible for rewards without any vesting or time-lock period.
In GuageController.sol:
The distribution mechanism is predictable and would be front-run.
Proof of Code: Add this code in a testfile and run it.
OUTPUT:-
The test results demonstrate several critical issues:
Disproportionate Reward Distribution:
Legitimate user staked 1000e18 tokens
Attacker staked only 100e18 tokens (10% of legitimate stake)
Yet both received exactly 437,229 reward tokens
Reward Calculation Manipulation:
Initial rewardPerTokenStored: 0
Post-attack rewardPerTokenStored: 43290043290043288
The attacker's front-running caused equal reward distribution despite unequal stakes
Stake Ratio: 10:1 (Legitimate:Attacker)
Reward Ratio: 1:1 (Legitimate:Attacker)
This represents a 10x efficiency in reward extraction for the attacker
Attack Efficiency:
The attacker achieved equal rewards with only 10% of the capital commitment
The attack was executed within a single transaction
The timing of the attack (front-running the reward distribution) was crucial for its success
Based on the POC, here's the step-by-step attack execution:
Waiting Period
The attacker monitors the blockchain for pending reward distributions.
3. Front-Running Attack Execution
Reward Accrual Period:
Reward Claims & Analysis.
This POC demonstrates that despite having only 10% of the total stake, the attacker receives more than 50% of the rewards:
The vulnerability exists due to several architectural decisions:
Linear Reward Distribution: Rewards are distributed linearly based on current stakes rather than time-weighted stakes.
No Minimum Staking Period: Users can stake and immediately become eligible for rewards.
Predictable Distribution: The reward distribution mechanism is deterministic and can be predicted.
No Anti-Front-Running Measures: Lack of mechanisms to prevent quick stake-and-withdraw behavior.
Immediate Reward Eligibility: New stakes immediately participate in reward distribution without any warm-up period.
The impact of this vulnerability is severe and multi-faceted:
Economic Impact
Direct theft of rewards from legitimate stakers
Devaluation of long-term staking positions
Potential for repeated exploitation leading to significant losses
2. Protocol Stability
Discourages long-term staking
Creates incentives for manipulative behavior
Undermines the protocol's tokenomics model
foundry
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.