Skip to content
Business logic Audit finding Intermediate

castVote can be called by anyone even those without votes

The governance contract's vote casting function did not check whether the caller had any voting power, so anyone could vote with zero votes. Because each address receives a gas refund for voting, an attacker could use many addresses to drain the vault set aside for refunds.

hansfriese Follow with 0x52 and Trumpero

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-frankendao-judging/issues/25

Found by

hansfriese, 0x52, Trumpero

Summary

Governance#castVote can be called by anyone, even users that don't have any votes. Since the voting refund is per address, an adversary could use a large number of addresses to vote with zero votes to drain the vault.

Vulnerability Detail

function _castVote(address _voter, uint256 _proposalId, uint8 _support) internal returns (uint) {
    // Only Active proposals can be voted on
    if (state(_proposalId) != ProposalState.Active) revert InvalidStatus();

    // Only valid values for _support are 0 (against), 1 (for), and 2 (abstain)
    if (_support > 2) revert InvalidInput();

    Proposal storage proposal = proposals[_proposalId];

    // If the voter has already voted, revert        
    Receipt storage receipt = proposal.receipts[_voter];
    if (receipt.hasVoted) revert AlreadyVoted();

    // Calculate the number of votes a user is able to cast
    // This takes into account delegation and community voting power
    uint24 votes = (staking.getVotes(_voter)).toUint24();

    // Update the proposal's total voting records based on the votes
    if (_support == 0) {
        proposal.againstVotes = proposal.againstVotes + votes;
    } else if (_support == 1) {
        proposal.forVotes = proposal.forVotes + votes;
    } else if (_support == 2) {
        proposal.abstainVotes = proposal.abstainVotes + votes;
    }

    // Update the user's receipt for this proposal
    receipt.hasVoted = true;
    receipt.support = _support;
    receipt.votes = votes;

    // Make these updates after the vote so it doesn't impact voting power for this vote.
    ++totalCommunityScoreData.votes;

    // We can update the total community voting power with no check because if you can vote, 
    // it means you have votes so you haven't delegated.
    ++userCommunityScoreData[_voter].votes;

    return votes;
}

Nowhere in the flow of voting does the function revert if the user calling it doesn't actually have any votes. staking#getVotes won't revert under any circumstances. Governance#_castVote only reverts if 1) the proposal isn't active 2) support > 2 or 3) if the user has already voted. The result is that any user can vote even if they don't have any votes, allowing users to maliciously burn vault funds by voting and claiming the vote refund.

Impact

Vault can be drained maliciously by users with no votes

Code Snippet

https://github.com/sherlock-audit/2022-11-frankendao/blob/main/src/Governance.sol#L607-L646

Tool used

Manual Review

Recommendation

Governance#_castVote should revert if msg.sender doesn't have any votes:

    // Calculate the number of votes a user is able to cast
    // This takes into account delegation and community voting power
    uint24 votes = (staking.getVotes(_voter)).toUint24();

+   if (votes == 0) revert NoVotes();

    // Update the proposal's total voting records based on the votes
    if (_support == 0) {
        proposal.againstVotes = proposal.againstVotes + votes;
    } else if (_support == 1) {
        proposal.forVotes = proposal.forVotes + votes;
    } else if (_support == 2) {
        proposal.abstainVotes = proposal.abstainVotes + votes;
    }

Discussion

zobront

This is great and will fix, but an adversary being able to burn a small pool put aside for gas refunds for no personal benefit seems like a Medium, not a High.

ZakkMan

Fixed: https://github.com/Solidity-Guild/FrankenDAO/pull/21

jack-the-pug

Fix confirmed

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

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

The vote casting function did not revert when the calculated vote count was zero, allowing zero-vote participation and refund claims.

Impact

An attacker could drain the vault's gas refund pool by voting from many zero-vote addresses, though the pool was described as small.

What the attacker needed

Many addresses; active proposal; gas refund pool funded

The fix

The vote function was fixed to revert when the caller has no votes.

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, people vote on proposals using tokens that represent voting power. The vote function never checked that the caller actually had any voting power, so even someone with zero tokens could vote. Since the system paid back gas costs for each vote, an attacker could create many addresses, vote with each, and collect the refunds until the refund pool was empty.

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 by hansfriese

View all

65 more disclosed reports, best first.

More from FrankenDAO

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.