activateProposal() need time delay
The governance contract lets a submitter activate a new proposal immediately, replacing the current active proposal, while the vote function does not take a proposal identifier and always votes on whatever is active. A user's vote could therefore land on a different proposal than intended, and a watcher of pending transactions could front-run a large vote to change the outcome.
Originally disclosed on Code4rena
Submitted by 141345, also found by 0x1f8b, Trust, V_B, and zzzitron
There is no time lock or delay when activating a proposal, the previous one could be replaced immediately. In vote() call, a user might want to vote for the previous proposal, but if the vote() call and the activateProposal() is very close or even in the same block, it is quite possible that the user actually voted for another proposal without much knowledge of. A worse case is some malicious user watching the mempool, and front run a big vote favor/against the activeProposal, effectively influence the voting result.
These situations are not what the governance intends to deliver, and might also affect the results of 2 proposals.
Proof of Concept
activateProposal() can take effect right away, replacing the activeProposal. And vote() does not specify which proposalId to vote for, but the activeProposal could be different from last second.
src/policies/Governance.sol
function activateProposal(uint256 proposalId_) external {
ProposalMetadata memory proposal = getProposalMetadata[proposalId_];
if (msg.sender != proposal.submitter) {
revert NotAuthorizedToActivateProposal();
}
if (block.timestamp > proposal.submissionTimestamp + ACTIVATION_DEADLINE) {
revert SubmittedProposalHasExpired();
}
if (
(totalEndorsementsForProposal[proposalId_] * 100) <
VOTES.totalSupply() * ENDORSEMENT_THRESHOLD
) {
revert NotEnoughEndorsementsToActivateProposal();
}
if (proposalHasBeenActivated[proposalId_] == true) {
revert ProposalAlreadyActivated();
}
if (block.timestamp < activeProposal.activationTimestamp + GRACE_PERIOD) {
revert ActiveProposalNotExpired();
}
activeProposal = ActivatedProposal(proposalId_, block.timestamp);
proposalHasBeenActivated[proposalId_] = true;
emit ProposalActivated(proposalId_, block.timestamp);
}
function vote(bool for_) external {
uint256 userVotes = VOTES.balanceOf(msg.sender);
if (activeProposal.proposalId == 0) {
revert NoActiveProposalDetected();
}
if (userVotesForProposal[activeProposal.proposalId][msg.sender] > 0) {
revert UserAlreadyVoted();
}
if (for_) {
yesVotesForProposal[activeProposal.proposalId] += userVotes;
} else {
noVotesForProposal[activeProposal.proposalId] += userVotes;
}
userVotesForProposal[activeProposal.proposalId][msg.sender] = userVotes;
VOTES.transferFrom(msg.sender, address(this), userVotes);
emit WalletVoted(activeProposal.proposalId, msg.sender, for_, userVotes);
}
Recommended Mitigation Steps
Add time delay when activating a proposal, so that users can be aware of that and vote for the current one within the time window.
fullyallocated (Olympus) disputed and commented:
This is a pretty unique edge case, I can acknowledge as QA.
I actually don’t think its that unique in the case of on chain voting. Imagine a scenario where a user submits a vote with low gas amounts and it is not mined for days later and then the active proposal has changed. I am not sure why the
votefunction wouldn’t take in the intended proposal ID.I am going to leave as medium severity as I do think this impacts the intended functionality of the protocol, but am willing to hear more from the sponsor on why they disagree.
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 vote function relies on a single mutable active proposal instead of an explicit proposal identifier, and activation has no delay, so the target of a vote can change between submission and execution.
Impact
Votes could be counted for a proposal the voter did not intend, and a malicious user watching pending transactions could front-run a large vote to influence the result of two proposals.
What the attacker needed
A governance proposal with enough endorsements; the submitter activates it; victim votes around the same time
The fix
Add a time delay when activating a proposal so users have a window to see the change and vote on the current one.
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 whichever proposal is currently 'active'. The problem is that a new proposal can become active instantly, and the voting function does not say which proposal you mean. So if someone swaps the active proposal just before your vote is processed, your vote counts for the wrong one.
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.