When the unlockOverride flag is true, users can “freely” vote for gauge weights.
When the governance flag unlockOverride is true, users can create a lock, vote for a gauge weight, and immediately withdraw their tokens, boosting the gauge weight without keeping tokens locked. This lets an attacker manipulate gauge weights for free.
said Follow with Arabadzhiev
Originally disclosed on Code4rena
Submitted by said, also found by Arabadzhiev
https://github.com/code-423n4/2024-03-neobase/blob/main/src/VotingEscrow.sol#L295-L311
https://github.com/code-423n4/2024-03-neobase/blob/main/src/VotingEscrow.sol#L315-L350
Impact
Due to the lack of restrictions on createLock and increaseAmount when the unlockOverride flag is set to true, users can createLock/increaseAmount on VotingEscrow, vote for a gauge inside the GaugeController to increase the desired gauge’s weight, and then immediately withdraw the locked native token from VotingEscrow to boost their desired gauge’s weight for “free”.
Proof of Concept
When users lock their native token on VotingEscrow, they gain the ability to increase gauge weight on GaugeController based on the amount of native token they’ve locked, at the expense of having to lock the native token for LOCKTIME (1825 days) period, or until the governance toggle unlockOverride and set it to true.
https://github.com/code-423n4/2024-03-neobase/blob/main/src/VotingEscrow.sol#L357
function withdraw() external nonReentrant {
LockedBalance memory locked_ = locked[msg.sender];
// Validate inputs
require(locked_.amount > 0, "No lock");
>>> require(locked_.end <= block.timestamp || unlockOverride, "Lock not expired");
require(locked_.delegatee == msg.sender, "Lock delegated");
// Update lock
uint256 amountToSend = uint256(uint128(locked_.amount));
LockedBalance memory newLocked = _copyLock(locked_);
newLocked.amount = 0;
newLocked.end = 0;
newLocked.delegated -= int128(int256(amountToSend));
newLocked.delegatee = address(0);
locked[msg.sender] = newLocked;
newLocked.delegated = 0;
// oldLocked can have either expired <= timestamp or zero end
// currentLock has only 0 end
// Both can have >= 0 amount
_checkpoint(msg.sender, locked_, newLocked);
// Send back deposited tokens
(bool success, ) = msg.sender.call{value: amountToSend}("");
require(success, "Failed to send CANTO");
emit Withdraw(msg.sender, amountToSend, LockAction.WITHDRAW, block.timestamp);
}
However, due to the lack of restrictions on calling createLock and increaseAmount when unlockOverride is set to true, users can lock their native token, use it to vote on GaugeController, and immediately withdraw the token to manipulate and boost the desired gauge weights.
Add the following test inside GaugeController.t.sol:
function testVoteGaugeWeightUnlockOverride() public {
vm.startPrank(gov);
gc.add_gauge(gauge1, 0);
gc.add_gauge(gauge2, 0);
ve.toggleUnlockOverride();
vm.stopPrank();
vm.startPrank(user1);
ve.createLock{value: 1 ether}(1 ether);
uint256 nextEpoch = ((block.timestamp + WEEK) / WEEK) * WEEK;
gc.vote_for_gauge_weights(gauge1, 10000); // vote 100% for gauge1
ve.withdraw();
vm.stopPrank();
console.logUint(gc.gauge_relative_weight_write(gauge1, nextEpoch));
}
Run the test:
forge test --match-contract GaugeControllerTest --match-test testVoteGaugeWeightUnlockOverride -vv
Output:
Logs:
1000000000000000000
From the test, it can be observed that relative gauge weight’s of desired gauge increased for next epoch.
Recommended Mitigation Steps
Considering that unlockOverride is potentially used to finish the lock time early for all users inside VotingEscrow, consider adding a check inside createLock and increaseAmount. If unlockOverride is set to true, revert the operation.
Assessed type
Invalid Validation
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 createLock and increaseAmount functions do not check the unlockOverride flag, so users can lock and immediately withdraw while still having voted.
Impact
An attacker could manipulate gauge weights for free, potentially directing rewards to a chosen gauge without locking tokens for the required period.
What the attacker needed
UnlockOverride flag is true; attacker has native tokens
The fix
The createLock and increaseAmount functions should revert when unlockOverride is true.
How it was found
- Governance adds gauges and turns on unlockOverride.
- User creates a lock with native tokens.
- User votes for a gauge with full weight.
- User withdraws the locked tokens immediately.
- The gauge's relative weight for the next epoch is increased.
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.
A voting system gives more power to people who lock their tokens for a long time. A special switch lets everyone unlock early. The report shows that with the switch on, someone can lock tokens, vote, and take the tokens back right away, so they get voting power without the cost.
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.