If a gauge that a user has voted for gets removed, their voting power allocated for that gauge will be lost
When a gauge that a user has voted for is removed by governance, the user's allocated voting power is permanently lost because they cannot remove their vote from the removed gauge. This prevents them from voting on other gauges with that power.
Arabadzhiev Follow with said
Originally disclosed on Code4rena
Submitted by Arabadzhiev, also found by said
Impact
When a gauge that an user has voted for gets removed by the governance, their voting power allocated for that gauge will be lost forever.
Proof of Concept
Due to the current way the GaugeController::vote_for_gauge_weights function is implemented, whenever a given gauge that users have voted for gets removed, all of the voting powers allocated by those users to that gauge will be permanently lost. The same issue has actually already been reported in this report from the last Code4rena audit of the codebase.
As it can be seen from the following snippet:
function testLostVotingPower() public {
// prepare
uint256 v = 10 ether;
vm.deal(gov, v);
vm.startPrank(gov);
ve.createLock{value: v}(v);
// add gauges
gc.add_gauge(gauge1, 0);
gc.add_type("", 0);
gc.add_gauge(gauge2, 1);
// all-in on gauge1
gc.vote_for_gauge_weights(gauge1, 10000);
// governance removes gauge1
gc.remove_gauge_weight(gauge1);
gc.remove_gauge(gauge1);
// cannot vote for gauge2
vm.expectRevert("Used too much power");
gc.vote_for_gauge_weights(gauge2, 10000);
// cannot remove vote for gauge1
vm.expectRevert("Gauge not added"); // @audit remove after mitigation
gc.vote_for_gauge_weights(gauge1, 0);
// cannot vote for gauge2 (to demonstrate again that voting power is not removed)
vm.expectRevert("Used too much power"); // @audit remove after mitigation
gc.vote_for_gauge_weights(gauge2, 10000);
}
the recommended fix from that report has actually been implemented.
However, there are two other changes there as well. The isValidGauge mapping has been replaced with a new one named gauge_types_, which practically serves the same purpose as the old one in the context of this snippet. More importantly though, a new require statement has been added, as it can be seen on the last code line of the snippet, which checks whether the gauge type is greater than 0 and reverts otherwise. Since the gauge type for a given gauge address can only be 0, in the case where the gauge does not actually exist (i.e. it has been removed or it was never created in the first place), this means that the implemented fix will no longer work and because of that the issue is once again present in the current implementation of the GaugeController.
The following coded PoC, which is a modification of the one in the above linked report verifies the existence of the issue:
function testLostVotingPower() public {
// prepare
uint256 v = 10 ether;
vm.deal(gov, v);
vm.startPrank(gov);
ve.createLock{value: v}(v);
// add gauges
gc.add_gauge(gauge1, 0);
gc.change_gauge_weight(gauge1, 100);
gc.add_type("", 100);
gc.add_gauge(gauge2, 1);
gc.change_gauge_weight(gauge2, 100);
// all-in on gauge1
gc.vote_for_gauge_weights(gauge1, 10000);
// governance removes gauge1
gc.remove_gauge_weight(gauge1);
gc.remove_gauge(gauge1);
// cannot vote for gauge2
vm.expectRevert("Used too much power");
gc.vote_for_gauge_weights(gauge2, 10000);
// cannot remove vote for gauge1
vm.expectRevert("Gauge not added"); // @audit remove after mitigation
gc.vote_for_gauge_weights(gauge1, 0);
// cannot vote for gauge2 (to demonstrate again that voting power is not removed)
vm.expectRevert("Used too much power"); // @audit remove after mitigation
gc.vote_for_gauge_weights(gauge2, 10000);
}
Recommended Mitigation Steps
Remove the additional require statement that checks whether the gauge type for the _gauge_addr is different from 0, in order to allow users to remove their votes from removed gauges:
function vote_for_gauge_weights(address _gauge_addr, uint256 _user_weight) external {
require(_user_weight >= 0 && _user_weight <= 10_000, "Invalid user weight");
require(_user_weight == 0 || gauge_types_[_gauge_addr] != 0, "Can only vote 0 on non-gauges"); // We allow withdrawing voting power from invalid (removed) gauges
VotingEscrow ve = votingEscrow;
(
,
/*int128 bias*/
int128 slope_, /*uint256 ts*/
) = ve.getLastUserPoint(msg.sender);
require(slope_ >= 0, "Invalid slope");
uint256 slope = uint256(uint128(slope_));
uint256 lock_end = ve.lockEnd(msg.sender);
uint256 next_time = ((block.timestamp + WEEK) / WEEK) * WEEK;
require(lock_end > next_time, "Lock expires too soon");
int128 gauge_type = gauge_types_[_gauge_addr] - 1;
- require(gauge_type >= 0, "Gauge not added");
...
}
Assessed type
Invalid Validation
Voting power is considered an asset and can be lost in this scenario without malicious governance intent or mistake.
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 a require statement that checks the gauge type is greater than zero prevents users from removing their vote from a gauge that has been removed (and thus has type zero).
Impact
The user's voting power allocated to the removed gauge is permanently lost, and they cannot use it to vote on other gauges.
What the attacker needed
User has voting power from a lock; user voted for a gauge; governance removes that gauge
The fix
Remove the additional require statement that checks whether the gauge type is different from zero, so users can remove their votes from removed gauges.
How it was found
- Create a lock to obtain voting power.
- Add two gauges with different types.
- Vote all voting power for the first gauge.
- Governance removes the first gauge.
- Attempt to vote for the second gauge, which reverts with 'Used too much power'.
- Attempt to remove vote from the first gauge, which reverts with 'Gauge not added'.
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 lock tokens to get voting power and can direct that power to different gauges (reward pools). If a gauge is removed by governance, the user's voting power assigned to it becomes stuck: they cannot withdraw it or reassign it to another gauge. This means they lose the ability to use that voting power elsewhere.
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.