pause or kill gauge can lead to FLOW token stuck in voter
When a gauge is paused or killed, its unclaimed reward tokens are set to zero without being returned to the minter or distributed, leaving them stuck in the voter contract. An attacker cannot directly exploit this, but the emergency council's action causes a loss of funds.
0xBugHunter Follow with 0xNazgul, 0xpiken and 32 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/107
Found by
0xBugHunter, 0xNazgul, 0xpiken, 1nc0gn170, 4gontuk, AMOW, Audinarey, Avci, ElCid-eth, KupiaSec, Matin, MohammedRizwan, Naresh, Ruhum, Smacaud, StraawHaat, atoko, blackhole, blockchain555, bughuntoor, coffiasd, cryptic, cu5t0mPe0, dany.armstrong90, dev0cloo, eeshenggoh, eeyore, hl_, hulkvision, jennifer37, mike-watson, oxkmmm, pseudoArtist, sonny2k, talfao
Summary
pause or kill gauge action set unclaimed reward to 0 without sending it back to minter or distributing it to gauge.
Vulnerability Detail
when [Voter::distribute] is tigger , voter invoke Minter::update_period , if 1 week duration is pass by , minter transfer some FLOW to Voter, the amount is based on the number of gauges.
function distribute(address _gauge) public lock {
IMinter(minter).update_period(); <@
_updateFor(_gauge); // should set claimable to 0 if killed
uint _claimable = claimable[_gauge];
if (_claimable > IGauge(_gauge).left(base) && _claimable / DURATION > 0) {. <@
claimable[_gauge] = 0;
if((_claimable * 1e18) / currentEpochRewardAmount > minShareForActiveGauge) {
activeGaugeNumber += 1;
}
IGauge(_gauge).notifyRewardAmount(base, _claimable);//@audit-info update rewardRate or add reward token , send token to gauge.
emit DistributeReward(msg.sender, _gauge, _claimable);
}
}
From above code we can see only if _claimable > IGauge(_gauge).left(base) the claimable reward token will be send to gauge
And emergencyCouncil can invoke Voter.sol::pauseGauge or Voter.sol::killGaugeTotally at anytime , without checking the claimable reward token amount and set it to zero. Which can lead to those unclaimed reward token stuck in voter contract.
test:
function testPauseGaugeLeadToRemainingToken() public {
FLOW.setMinter(address(minter));
minter.startActivePeriod();
voter.distribute();
address gauge = voter.createGauge(address(pair),0);
address gauge2 = voter.createGauge(address(pair2),0);
address gauge3 = voter.createGauge(address(pair3),0);
//get voting power.
flowDaiPair.approve(address(escrow), 5e17);
uint256 tokenId = escrow.create_lock_for(1e16, FIFTY_TWO_WEEKS,address(owner));
uint256 tokenId2 = escrow.create_lock_for(1e16, FIFTY_TWO_WEEKS,address(owner2));
uint256 tokenId3 = escrow.create_lock_for(1e16, FIFTY_TWO_WEEKS,address(owner3));
skip(5 weeks);
vm.roll(block.number + 1);
address[] memory votePools = new address[](3);
votePools[0] = address(pair);
votePools[1] = address(pair2);
votePools[2] = address(pair3);
uint256[] memory weight = new uint256[](3);
weight[0] = 10;
weight[1] = 20;
weight[2] = 30;
//user vote.
vm.prank(address(owner));
voter.vote(tokenId,votePools,weight);
vm.prank(address(owner2));
voter.vote(tokenId2,votePools,weight);
vm.prank(address(owner3));
voter.vote(tokenId3,votePools,weight);
voter.pauseGauge(gauge3);
skip(8 days);
voter.distribute(gauge);
voter.distribute(gauge2);
voter.distribute(gauge3);
console2.log("gauge get flow:",FLOW.balanceOf(address(gauge)));
console2.log("gauge2 get flow:",FLOW.balanceOf(address(gauge2)));
console2.log("gauge3 get flow:",FLOW.balanceOf(address(gauge3)));
console2.log("remaining flow:",FLOW.balanceOf(address(voter)));
}
out:
Ran 1 test for test/Voter.t.sol:VoterTest
[PASS] testPauseGaugeLeadToRemainingToken() (gas: 19148544)
Logs:
gauge get flow: 333333333333333259574
gauge2 get flow: 666666666666666740425
gauge3 get flow: 0
remaining flow: 1000000000000000000001
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 11.89ms (3.68ms CPU time)
Even to the next round those unclaimed flow token is still not add to reward lead to those token get stuck.
Impact
FLOW token stuck in voter
Code Snippet
https://github.com/sherlock-audit/2024-06-velocimeter/blob/main/v4-contracts/contracts/Voter.sol#L380-L392 https://github.com/sherlock-audit/2024-06-velocimeter/blob/main/v4-contracts/contracts/Voter.sol#L407-L429
Tool used
Manual Review
Recommendation
those code is forked from velocimeter V1 , above issue is already fixed in V2 https://github.com/velodrome-finance/contracts/blob/main/contracts/Voter.sol
function killGauge(address _gauge) external {
if (_msgSender() != emergencyCouncil) revert NotEmergencyCouncil();
if (!isAlive[_gauge]) revert GaugeAlreadyKilled();
// Return claimable back to minter
uint256 _claimable = claimable[_gauge];
if (_claimable > 0) {
IERC20(rewardToken).safeTransfer(minter, _claimable); <@
delete claimable[_gauge];
}
isAlive[_gauge] = false;
emit GaugeKilled(_gauge);
}
If _claimable > 0 send reward token back to minter
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/13
spacegliderrrr
Fix looks good.
sherlock-admin2
The Lead Senior Watson signed off on the fix.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the pauseGauge and killGaugeTotally functions set the gauge's claimable reward to zero without transferring the corresponding tokens back to the minter or otherwise handling them.
Impact
FLOW tokens become permanently stuck in the voter contract, representing a loss of rewards for the protocol.
What the attacker needed
Emergency council pauses or kills a gauge
The fix
The issue was fixed by updating the killGauge function to transfer any claimable reward tokens back to the minter before deleting the claimable amount.
How it was found
- Deploy the contracts and start the minter's active period.
- Create three gauges and have three users vote with weights.
- Pause one of the gauges.
- Advance time and call distribute for each gauge.
- Observe that the paused gauge receives no tokens and a large amount remains stuck in the voter contract.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this system, users vote to direct rewards to different pools (gauges). The voter contract holds reward tokens until they are sent to the gauges. If an admin pauses or kills a gauge, the reward tokens that were set aside for it are simply erased from the record, but the tokens themselves stay stuck in the voter contract forever.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.