Skip to content
Business logic Audit finding Intermediate

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.

HollaDieWaldfee Follow

Originally disclosed on Code4rena

Submitted by HollaDieWaldfee

https://github.com/code-423n4/2023-04-party/blob/440aafacb0f15d037594cebc85fd471729bcb6d9/contracts/party/PartyGovernance.sol#L598-L605

https://github.com/code-423n4/2023-04-party/blob/440aafacb0f15d037594cebc85fd471729bcb6d9/contracts/proposals/VetoProposal.sol#L46-L51

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:

Link

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:

Link

uint96 votingPower = getVotingPowerAt(msg.sender, values.proposedTime - 1, snapIndex);

And we can see it in the VetoProposal.voteToVeto function:

Link

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:

Link

if (
    values.passedTime == 0 &&
    _areVotesPassing(
        values.votes,
        _governanceValues.totalVotingPower,
        _governanceValues.passThresholdBps
    )
) {

Link

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:

  1. Snapshot totalVotingPower whenever it is changed
  2. Whenever totalVotingPower is used to calculate whether a proposal is accepted / vetoed, the snapshot should be used

0xble (Party) confirmed


The original report as published on Code4rena, by HollaDieWaldfee. 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 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

  1. Create a proposal, which records the proposed time.
  2. Change the total voting power, for example by adding a new crowdfund contributor.
  3. Vote on the proposal; individual votes use the old snapshot but the pass check uses the new total.
  4. 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.

More by HollaDieWaldfee

View all

39 more disclosed reports, best first.

More from Party Protocol

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.