totalVotingPower needs to be snapshotted for each proposal because it can change and thereby affect consensus when accepting / vetoing proposals
The total voting power used to decide whether a proposal passes is read live rather than from the same snapshot as the individual votes. If total voting power changes after a proposal is created, the pass threshold is calculated against the wrong denominator, so a proposal can become impossible to pass or pass with fewer votes than intended.
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee
This issue does not manifest itself in a limited segment of the code.
Instead it spans multiple contracts and derives its impact from the interaction of these contracts.
In the PoC section I will do my best in explaining how this results in an issue.
I discussed this with the sponsor and they explained to me that this issue is due to a PR that has unintentionally not been merged.
So they have already written the code that is necessary to fix this issue. It’s just not been merged with this branch. So since the sponsor knows about this already and it’s just the PR that has gone missing it’s not necessary for me to provide the full Solidity code to fix this issue.
In short, this issue is due to the fact that the totalVotingPower is not snapshotted when a proposal is created.
The votes that are used to vote for a proposal (or veto it) are based on a specific snapshot (1 block prior to the proposal being created).
When the totalVotingPower changes this leads to unintended consequences.
When totalVotingPower decreases, votes become more valuable than they should be.
And when totalVotingPower increases, votes become less valuable than they should be.
Proof of Concept
When a proposal is created via the PartyGovernance.propose function, the proposal’s proposedTime is set:
ProposalStateValues({
proposedTime: uint40(block.timestamp),
passedTime: 0,
executedTime: 0,
completedTime: 0,
votes: 0
}),
When users then vote in order to accept the proposal or veto the proposal, their votes are based on the snapshot at the proposedTime - 1 timestamp.
We can see this in the PartyGovernance.accept function:
uint96 votingPower = getVotingPowerAt(msg.sender, values.proposedTime - 1, snapIndex);
And we can see it in the VetoProposal.voteToVeto function:
uint96 votingPower = party.getVotingPowerAt(
msg.sender,
proposalValues.proposedTime - 1,
snapIndex
);
However the totalVotingPower to determine whether enough votes have been collected is the current totalVotingPower:
if (
values.passedTime == 0 &&
_areVotesPassing(
values.votes,
_governanceValues.totalVotingPower,
_governanceValues.passThresholdBps
)
) {
if (
_areVotesPassing(
newVotes,
governanceValues.totalVotingPower,
governanceValues.passThresholdBps
)
The totalVotingPower is not constant. It can increase and decrease.
Now we can understand the issue. The totalVotingPower must be based on the same time as the votes (i.e. proposedTime - 1).
Let’s look at a scenario:
At the time of proposal creation (proposedTime - 1):
Alice: 100 Votes
Bob: 50 Votes
Chris: 50 Votes
totalVotingPower=200
Let’s say 80% of votes are necessary for the proposal to pass.
Now the totalVotingPower is increased (e.g. by a ReraiseETHCrowdfund) since David now has 100 Votes:
Alice: 100 Votes
Bob: 50 Votes
Chris: 50 Votes
David: 100 Votes
totalVotingPower=300
Now it is impossible for the proposal to pass.
The proposal needs 80% of 300 Votes which is 240 Votes. But the votes are used from the old snapshot and there were only 200 Votes.
The old totalVotingPower should have been used (200 Votes instead of 300 Votes).
Similarly there is an issue when totalVotingPower decreases:
Alice: 100 Votes
Bob: 50 Votes
Chris: 0 Votes
totalVotingPower=150
If 60% of the votes are necessary for the proposal to pass, Alice can make the proposal pass on her own because totalVotingPower=150 is used even though the old totalVotingPower=200 should be used.
Tools Used
VSCode
Recommended Mitigation Steps
As explained above the sponsor already has the code to implement snapshotting the totalVotingPower.
In short the following changes need to be made:
- Snapshot
totalVotingPowerwhenever it is changed - Whenever
totalVotingPoweris used to calculate whether a proposal is accepted / vetoed, the snapshot should be used
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 contract snapshots individual voting power at proposal time but reads the current total voting power when checking whether votes pass, so the two sides of the percentage come from different points in time.
Impact
A proposal could become impossible to pass after total voting power increases, or could pass with fewer votes than intended after it decreases, affecting both acceptance and veto outcomes.
What the attacker needed
A governance party with proposals; total voting power changes after proposal creation
The fix
The total voting power should be snapshotted whenever it changes and the snapshot from the proposal time should be used when checking whether votes pass.
How it was found
- Create a proposal, which records the proposed time.
- Change the total voting power, for example by adding a new crowdfund contributor.
- Vote on the proposal; individual votes use the old snapshot but the pass check uses the new total.
- Observe that the proposal can no longer reach the threshold, or can pass with too few 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 voting system, each person's voting power is frozen at the moment a proposal is made, but the total amount of voting power in the system is not frozen. The pass mark is a percentage of that total. If the total changes later, the percentage is applied to the wrong number, so the result can be unfair.
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.