Closed c4-bot-6 closed 2 months ago
alcueca changed the severity to 3 (High Risk)
alcueca marked the issue as primary issue
alcueca marked the issue as duplicate of #16
alcueca changed the severity to 2 (Med Risk)
alcueca marked the issue as satisfactory
Lines of code
https://github.com/code-423n4/2024-09-fenix-finance/blob/main/contracts/core/VotingEscrowUpgradeableV2.sol#L660-L675
Vulnerability details
Impact
Rewards cannot be distributed to some gauges.
Proof of Concept
When a gauge is created, the
gaugesState.index
is set to the currentindex
at L669.If the gauge is created before calling
notifyRewardAmount
, thegaugesState.index
is set to the old index. As a result, the new gauge can receive more rewards than the actual rewards, while other gauges may not receive any rewards.Let's consider the following scenario:
poolA
andgaugeA
, withindex
initially set to 0.poolA
in the first week:weightsPerEpoch = 100
,totalWeightsPerEpoch = 100
.gaugeB
forpoolB
at the start of the second week:gaugesState[gaugeB] = 0
.distribute
function forpoolA
, and the minter transfers 100 FNX. They do not call the function forpoolB
because they did not vote for it.index = 100 * 1e18 / 100 = 1e18
gaugesState[gaugeA].index = 1e18
gaugesState[gaugeB].index = 0
poolA
andpoolB
individually in the second week:weightsPerEpoch[poolA] = 50
weightsPerEpoch[poolB] = 50
totalWeightsPerEpoch = 100
distribute
function for both pools, and the minter transfers another 100 FNX.index = index + 100 * 1e18 / 100 = 2e18
gaugeA
: 50 * (2e18 - 1e18) / 1e18 = 50gaugeB
: 50 * (2e18 - 0) / 1e18 = 100Even though the
VoterUpgradeableV2
contract receives 100 FNX from the minter, it attempts to transfer 150 FNX to the gauges. As a result, the rewards distribution to the gauges is reverted.Tools Used
Manual Review
Recommended Mitigation Steps
Gauge creation should only be permitted after receiving rewards from the minter for each epoch.
Assessed type
Other