State function does not require majority of votes for supporting and passing a proposal
The `state` function in the Governor contract uses a strict less-than comparison, so a proposal with equal for and against votes (and sufficient quorum) is considered Succeeded rather than Defeated. This allows a proposal with exactly 50% support to pass, potentially enabling critical proposals to be executed without majority support.
Submitted by rbserver, also found by csanuragjain and Solimander
When determining the proposal’s state, the following state function is called, which can execute else if (proposal.forVotes < proposal.againstVotes || proposal.forVotes < proposal.quorumVotes) { return ProposalState.Defeated; }. If proposal.forVotes and proposal.againstVotes are the same, the proposal is not considered defeated when the quorum votes are reached by the for votes. However, many electoral systems require that the for votes to be more than the against votes in order to conclude that the proposal is passed because the majority of votes supports it. If the deployed DAO wants to require the majority of votes to support a proposal in order to pass it, the state function would incorrectly conclude that the proposal is not defeated when the for votes and against votes are the same at the end of voting. As a result, critical proposals, such as for updating implementations or withdrawing funds from the treasury, that should not be passed can be passed, or vice versa, so the impact can be huge.
function state(bytes32 _proposalId) public view returns (ProposalState) {
// Get a copy of the proposal
Proposal memory proposal = proposals[_proposalId];
// Ensure the proposal exists
if (proposal.voteStart == 0) revert PROPOSAL_DOES_NOT_EXIST();
// If the proposal was executed:
if (proposal.executed) {
return ProposalState.Executed;
// Else if the proposal was canceled:
} else if (proposal.canceled) {
return ProposalState.Canceled;
// Else if the proposal was vetoed:
} else if (proposal.vetoed) {
return ProposalState.Vetoed;
// Else if voting has not started:
} else if (block.timestamp < proposal.voteStart) {
return ProposalState.Pending;
// Else if voting has not ended:
} else if (block.timestamp < proposal.voteEnd) {
return ProposalState.Active;
// Else if the proposal failed (outvoted OR didn't reach quorum):
} else if (proposal.forVotes < proposal.againstVotes || proposal.forVotes < proposal.quorumVotes) {
return ProposalState.Defeated;
// Else if the proposal has not been queued:
} else if (settings.treasury.timestamp(_proposalId) == 0) {
return ProposalState.Succeeded;
// Else if the proposal can no longer be executed:
} else if (settings.treasury.isExpired(_proposalId)) {
return ProposalState.Expired;
// Else the proposal is queued
} else {
return ProposalState.Queued;
}
}
Proof of Concept
Please append the following test in test\Gov.t.sol. This test will pass to demonstrate the described scenario.
function test_ProposalIsSucceededWhenNumberOfForAndAgainstVotesAreSame() public {
vm.prank(founder);
auction.unpause();
createVoters(7, 5 ether);
vm.prank(address(treasury));
governor.updateQuorumThresholdBps(2000);
bytes32 proposalId = createProposal();
vm.warp(block.timestamp + governor.votingDelay());
// number of for and against votes are both 2
castVotes(proposalId, 2, 2, 3);
vm.warp(block.timestamp + governor.votingPeriod());
// the proposal is considered succeeded when number of for and against votes are the same after voting ends
assertEq(uint256(governor.state(proposalId)), uint256(ProposalState.Succeeded));
// the proposal can be queued afterwards
governor.queue(proposalId);
assertEq(uint256(governor.state(proposalId)), uint256(ProposalState.Queued));
}
Tools Used
VSCode
Recommended Mitigation Steps
If there is no need to pass a proposal when proposal.forVotes and proposal.againstVotes are the same at the end of voting, then Governor.sol#L441-L442 can be changed to the following code.
} else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < proposal.quorumVotes) {
return ProposalState.Defeated;
Otherwise, a governance configuration can be added to indicate whether the majority of votes is needed or not for supporting and passing a proposal. The state function then could return ProposalState.Defeated when proposal.forVotes <= proposal.againstVotes if so and when proposal.forVotes < proposal.againstVotes if not.
tbtstl (Nouns Builder) confirmed
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The warden has shown how, due to a flaw in order of operations and usage of the strict less than sign operator, a proposal with exactly 50% support can still pass as successful.
This can be dramatic as the definition of Majority is “The greater number”, which we would quantity as 50% + 1.
The finding is valid in that a situation can arise in which a proposal, with 50% detractors, would still pass, however, the specific operator
<means that this can happen exclusively if the different is by one, meaning that of all possible “vote distributions”, we’d need a perfect 50/50.Because of that, while I believe the finding should be mitigated, I think the finding is of Medium Severity as it will happen only in a specific situation.
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 `state` function uses a strict less-than comparison (`<`) instead of less-than-or-equal (`<=`) when checking if for votes are less than against votes, so a tie is not treated as defeated.
Impact
A proposal with exactly 50% support can pass and be queued, potentially allowing critical actions like updating implementations or withdrawing funds without a true majority; the judge noted this only occurs in a perfect tie.
What the attacker needed
A deployed DAO with this Governor contract; a proposal with exactly equal for and against votes; quorum reached by for votes
The fix
The comparison should be changed to less-than-or-equal (`<=`) so that a tie is considered defeated, or a governance configuration should be added to specify whether a majority is required.
How it was found
- Create a proposal and advance time past the voting delay.
- Cast 2 for votes and 2 against votes, with total quorum reached.
- Advance time past the voting period.
- Check the proposal state: it is Succeeded despite equal for and against votes.
- Queue the proposal, which then becomes Queued.
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 a voting system, a proposal should only pass if more people vote for it than against it. Here, the code checks if 'for' votes are less than 'against' votes to decide if it failed. If they are exactly equal, the proposal is not marked as failed and can pass, even though it only has half the support. This means a proposal could be accepted without a true majority.
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.