Skip to content
Smart contracts Audit finding Intermediate

ETHCrowdfundBase.sol : totalVotingPower is increased too much in the _finalize function

The ETHCrowdfundBase._finalize function increases the party's total voting power by an amount that includes funding fees, while individual users receive voting power based only on their contributions minus fees. This mismatch means the sum of users' voting power is less than the total, making unanimous votes impossible and potentially preventing any proposal from being executed.

HollaDieWaldfee Follow with hansfriese

Originally disclosed on Code4rena

Submitted by HollaDieWaldfee, also found by hansfriese

This issue is about how the ETHCrowdfundBase._finalize functions calls PartyGovernanceNFT.increaseTotalVotingPower with an amount that does not reflect the sum of the individual users’ voting power.

Thereby it will become impossible to reach unanimous votes. In other words and more generally the users’ votes are worth less than they should be as the percentage is calculated against a total amount that is too big.

In short, this is how the issue is caused:

  1. The voting power that a user receives is based on the amount they contribute MINUS funding fees
  2. The amount of voting power by which totalVotingPower is increased is based on the total contributions WITHOUT subtracting funding fees

Proof of Concept

Let’s first look at the affected code and then at the PoC.

The votingPower that a user receives for making a contribution is calculated in the ETHCrowdfundBase._processContribution function.

We can see that first the funding fee is subtracted and then with the lowered amount, the votingPower is calculated:

Link

// Subtract fee from contribution amount if applicable.
address payable fundingSplitRecipient_ = fundingSplitRecipient;
uint16 fundingSplitBps_ = fundingSplitBps;
if (fundingSplitRecipient_ != address(0) && fundingSplitBps_ > 0) {
    uint96 feeAmount = (amount * fundingSplitBps_) / 1e4;
    amount -= feeAmount;
}

// Calculate voting power.
votingPower = (amount * exchangeRateBps) / 1e4;

Even before that, totalContributions has been increased by the full amount (funding fees have not been subtracted yet):

Link

uint96 newTotalContributions = totalContributions + amount;
uint96 maxTotalContributions_ = maxTotalContributions;
if (newTotalContributions >= maxTotalContributions_) {
    totalContributions = maxTotalContributions_;

    // Finalize the crowdfund.
    // This occurs before refunding excess contribution to act as a
    // reentrancy guard.
    _finalize(maxTotalContributions_);

    // Refund excess contribution.
    uint96 refundAmount = newTotalContributions - maxTotalContributions;
    if (refundAmount > 0) {
        amount -= refundAmount;
        payable(msg.sender).transferEth(refundAmount);
    }
} else {
    totalContributions = newTotalContributions;
}

(Note that the above code looks more complicated than it is because it accounts for the fact that maxTotalContributions might be reached. But this is not important for explaining this issue)

When PartyGovernanceNFT.increaseTotalVotingPower is called it is with the newVotingPower that has been calculated BEFORE funding fees are subtracted:

Link

uint96 newVotingPower = (totalContributions_ * exchangeRateBps) / 1e4;
party.increaseTotalVotingPower(newVotingPower);

// Transfer fee to recipient if applicable.
address payable fundingSplitRecipient_ = fundingSplitRecipient;
uint16 fundingSplitBps_ = fundingSplitBps;
if (fundingSplitRecipient_ != address(0) && fundingSplitBps_ > 0) {
    uint96 feeAmount = (totalContributions_ * fundingSplitBps_) / 1e4;
    totalContributions_ -= feeAmount;
    fundingSplitRecipient_.transferEth(feeAmount);
}

Therefore totalVotingPower is increased more than the sum of the voting power that the users have received.

Let’s look at the PoC:

function test_totalVotingPower_increased_too_much() public {
        ReraiseETHCrowdfund crowdfund = _createCrowdfund({
            initialContribution: 0,
            initialContributor: payable(address(0)),
            initialDelegate: address(0),
            minContributions: 0,
            maxContributions: type(uint96).max,
            disableContributingForExistingCard: false,
            minTotalContributions: 2 ether,
            maxTotalContributions: 5 ether,
            duration: 7 days,
            fundingSplitBps: 1000,
            fundingSplitRecipient: payable(address(1))
        });

        address member1 = _randomAddress();
        address member2 = _randomAddress();
        vm.deal(member1, 1 ether);
        vm.deal(member2, 1 ether);

        // Contribute, should be allowed to update delegate
        vm.startPrank(member1);
        crowdfund.contribute{ value: 1 ether }(member1, "");
        vm.stopPrank();

        vm.startPrank(member2);
        crowdfund.contribute{ value: 1 ether }(member2, "");
        vm.stopPrank();

        skip(7 days);
        console.log(party.getGovernanceValues().totalVotingPower);
        crowdfund.finalize();
        console.log(party.getGovernanceValues().totalVotingPower);

        console.log(crowdfund.pendingVotingPower(member1));
        console.log(crowdfund.pendingVotingPower(member2));
    }

See that totalVotingPower is increased from 0 to 2e18.

The voting power of both users is 0.9e18 (10% fee).

Thereby both users together receive a voting power of 1.8e18 which is only 90% of 2e18.

Therefore it is impossible to reach an unanimous vote.

Tools Used

VSCode, Foundry

Recommended Mitigation Steps

The fix is easy: We must consider the funding fee when increasing the totalVotingPower.

Fix:

diff --git a/contracts/crowdfund/ETHCrowdfundBase.sol b/contracts/crowdfund/ETHCrowdfundBase.sol
index 4392655..3c11160 100644
--- a/contracts/crowdfund/ETHCrowdfundBase.sol
+++ b/contracts/crowdfund/ETHCrowdfundBase.sol
@@ -274,10 +274,6 @@ contract ETHCrowdfundBase is Implementation {
         // Finalize the crowdfund.
         delete expiry;

-        // Update the party's total voting power.
-        uint96 newVotingPower = (totalContributions_ * exchangeRateBps) / 1e4;
-        party.increaseTotalVotingPower(newVotingPower);
-
         // Transfer fee to recipient if applicable.
         address payable fundingSplitRecipient_ = fundingSplitRecipient;
         uint16 fundingSplitBps_ = fundingSplitBps;
@@ -287,6 +283,10 @@ contract ETHCrowdfundBase is Implementation {
             fundingSplitRecipient_.transferEth(feeAmount);
         }

+        // Update the party's total voting power.
+        uint96 newVotingPower = (totalContributions_ * exchangeRateBps) / 1e4;
+        party.increaseTotalVotingPower(newVotingPower);
+
         // Transfer ETH to the party.
         payable(address(party)).transferEth(totalContributions_);
     }

0xean (judge) increased severity to High and commented:

I am upgrading severity here to match #27 and will look forward to sponsor comments.

I think this exposes a way in which there are parameter sets that leads to a loss of funds by not allowing any proposal to be executed.

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 order of operations: total voting power is increased before subtracting the funding fee, so it does not match the sum of individual voting powers.

Impact

The sum of users' voting power is less than the total voting power, so unanimous votes cannot be reached and proposals may be impossible to execute, potentially leading to a loss of funds.

What the attacker needed

A crowdfund with a funding fee set; At least one contributor

The fix

The fix is to subtract the funding fee from totalContributions before calculating and increasing the total voting power.

How it was found

  1. Create a crowdfund with a funding fee (e.g., 10%) and a funding split recipient.
  2. Two users each contribute 1 ether.
  3. After the crowdfund duration, finalize the crowdfund.
  4. Observe that totalVotingPower is increased to 2e18, while each user's voting power is 0.9e18, totaling 1.8e18.

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 crowdfunding contract, when people contribute money, they get voting power. The contract also tracks a total voting power. A bug caused the total to be increased by the full contribution amount, but each person's voting power was reduced by a fee. So the total was bigger than the sum of everyone's voting power, making it impossible for all voters to agree unanimously.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.