Skip to content
Business logic Audit finding Intermediate

ReraiseETHCrowdfund.sol : Multiple scenarios how pending votes might not be claimable which is a complete loss of funds for a user

The claim functions in ReraiseETHCrowdfund can revert for certain valid configurations, preventing users from claiming their pending voting power and causing a complete loss of funds. The issue arises because the contribution check uses voting power that may be reduced by a funding fee or rounding, and the min/max contribution limits can make it impossible to split voting power across cards.

HollaDieWaldfee Follow with evan and hansfriese

Originally disclosed on Code4rena

Submitted by HollaDieWaldfee, also found by evan and hansfriese

https://github.com/code-423n4/2023-04-party/blob/440aafacb0f15d037594cebc85fd471729bcb6d9/contracts/crowdfund/ReraiseETHCrowdfund.sol#L256-L303

https://github.com/code-423n4/2023-04-party/blob/440aafacb0f15d037594cebc85fd471729bcb6d9/contracts/crowdfund/ReraiseETHCrowdfund.sol#L333-L382

This issue is about how the ReraiseETHCrowdfund claim functionality can be broken.

When the claim functionality is broken this means that a user cannot claim his voting power, resulting in a complete loss of funds.

The claim functionality is not broken in any case, i.e. with any configuration of the ReraiseETHCrowdfund contract.

However the contract can be configured in a way - and by configured I mean specifically the minContribution, maxContribution, minTotalContributions and maxTotalContributions variables - that the claim functionality breaks.

And the configurations under which it breaks are NOT edge cases. They represent the intended use of the contract as discussed with the sponsor.

The fact that when the contract is used as intended it can lead to a complete loss of funds for the users makes me estimate this to be “High” severity.

Proof of Concept

We first need to understand the claim(uint256 tokenId, address contributor) and claimMultiple(uint96[] memory votingPowerByCard, address contributor) functions. They essentially make up the claim functionality as all other functions regarding claiming are just wrappers around them.

Let’s first look at the claim(uint256 tokenId, address contributor) function. The first part of the function is what we are interested in:

Link

function claim(uint256 tokenId, address contributor) public {
    // Check crowdfund lifecycle.
    {
        CrowdfundLifecycle lc = getCrowdfundLifecycle();
        if (lc != CrowdfundLifecycle.Finalized) {
            revert WrongLifecycleError(lc);
        }
    }

    uint96 votingPower = pendingVotingPower[contributor];

    if (votingPower == 0) return;

    {
        uint96 contribution = (votingPower * 1e4) / exchangeRateBps;
        uint96 maxContribution_ = maxContribution;
        // Check that the contribution equivalent of total pending voting
        // power is not above the max contribution range. This can happen
        // for contributors who contributed multiple times In this case, the
        // `claimMultiple` function should be called instead. This is done
        // so parties may use the minimum and maximum contribution values to
        // limit the voting power of each card (e.g.  a party desiring a "1
        // card = 1 vote"-like governance system where each card has equal
        // voting power).
        if (contribution > maxContribution_) {
            revert AboveMaximumContributionsError(contribution, maxContribution_);
        }
    }

What is important is that contribution is calculatesd as:

uint96 contribution = (votingPower * 1e4) / exchangeRateBps;

And then contribution is checked that it is <= maxContribution:

if (contribution > maxContribution_) {
    revert AboveMaximumContributionsError(contribution, maxContribution_);
}

The explanation for why this check is necessary can be seen in the comment:

// This is done
// so parties may use the minimum and maximum contribution values to
// limit the voting power of each card (e.g.  a party desiring a "1
// card = 1 vote"-like governance system where each card has equal
// voting power).

The claimMultiple(uint96[] memory votingPowerByCard, address contributor) function allows to divide the pending voting power across multiple party cards and it employs the following checks:

Link

    uint96 minContribution_ = minContribution;
    uint96 maxContribution_ = maxContribution;
    for (uint256 i; i < votingPowerByCard.length; ++i) {
        if (votingPowerByCard[i] == 0) continue;

        // Check that the contribution equivalent of voting power is within
        // contribution range. This is done so parties may use the minimum
        // and maximum contribution values to limit the voting power of each
        // card (e.g. a party desiring a "1 card = 1 vote"-like governance
        // system where each card has equal voting power).
        uint96 contribution = (votingPowerByCard[i] * 1e4) / exchangeRateBps;
        if (contribution < minContribution_) {
            revert BelowMinimumContributionsError(contribution, minContribution_);
        }

        if (contribution > maxContribution_) {
            revert AboveMaximumContributionsError(contribution, maxContribution_);
        }

        votingPower -= votingPowerByCard[i];

        // Mint contributor a new party card.
        uint256 tokenId = party.mint(contributor, votingPowerByCard[i], delegate);

        emit Claimed(contributor, tokenId, votingPowerByCard[i]);
    }

    // Requires that all voting power is claimed because the contributor is
    // expected to have burned their crowdfund NFT.
    if (votingPower != 0) revert RemainingVotingPowerAfterClaimError(votingPower);
}

We can see that for each party card the contribution needs to be >= minContribution and <= maxContribution. Also the function must deal with all the voting power, so after the function call all pending voting power must be processed:

if (votingPower != 0) revert RemainingVotingPowerAfterClaimError(votingPower);

Now we are in a position to look at a simple scenario how a user can end up without being able to claim his pending voting power (Note that this can also be a griefing attack whereby an attacker contributes for the victim some possibly small amount thereby making it impossible for the victim to claim):

(The test should be added to the ReraiseETHCrowdfund.t.sol test file)

function test_cannotClaim1() public {
        ReraiseETHCrowdfund crowdfund = _createCrowdfund({
            initialContribution: 0,
            initialContributor: payable(address(0)),
            initialDelegate: address(0),
            minContributions: 0.9 ether,
            maxContributions: 1 ether,
            disableContributingForExistingCard: false,
            minTotalContributions: 1 ether,
            maxTotalContributions: 1.5 ether,
            duration: 7 days,
            fundingSplitBps: 0,
            fundingSplitRecipient: payable(address(0))
        });

        address member = _randomAddress();
        vm.deal(member, 2 ether);

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

        assertEq(crowdfund.pendingVotingPower(member), 1.5 ether);

        vm.expectRevert(
            abi.encodeWithSelector(
                ETHCrowdfundBase.AboveMaximumContributionsError.selector,
                1500000000000000000,
                1000000000000000000
            )
        );
        crowdfund.claim(member);
    }

In this test the following values were chosen for the important variables that I mentioned above:

minContribution = 0.9e18
maxContribution = 1e18

minTotalContributions = 1e18
maxTotalContributions = 1.5e18

What happens in the test is that first 1 ETH is contributed then another 0.5 ETH is contributed (It says 1 ETH but maxTotalContributions is hit and so only 0.5 ETH is contributed and the crowdfund is finalized).

The call to the claim function fails because contribution = 1.5 ETH which is above maxContribution.

The important thing is now to understand that claimMultiple can also not be called (therefore the pending voting power cannot be claimed at all).

When we call claimMultiple the contribution for the first party card must be in the range [0.9e18, 1e18] to succeed and therefore the second contribution can only be in the range of [0.5e18,0.6e18] which is below minContribution and therefore it is not possible to distribute the voting power across cards such that the call succeeds.

What we discussed so far could be mitigated by introducing some simple checks when setting up the crowdfund. The sort of checks required are like ”minTotalContributions must be divisible by minContribution”. I won’t go into this deeply however because these checks are insufficient when we introduce a funding fee.

Let’s consider a case with:

minContribution = 1e18
maxContribution = 1e18
minTotalContributions = 2e18
maxTotalContributions = 2e18

(Note that setting up the crowdfund with minContribution==maxContribution is an important use case where the party wants to enforce a “1 card = 1 vote”-policy).

There should be no way how this scenario causes a problem right? The contribution of a user can only be 1e18 or 2e18 and in both cases the checks in the claim functions should pass. - No

It breaks when we introduce a fee. Say there is a 1% fee (fundingSplitBps=100).

The contribution is calculated as (as we know from above):

(Also note that exchangeRateBps=1e4 for all tests, i.e. the exchange rate between ETH and votes is 1:1)

uint96 contribution = (votingPower * 1e4) / exchangeRateBps;

The problem is that votingPower has been reduced by 1% due to the funding fee. So when a user initially contributes 1e18, the contribution here is calculated to be 0.99e18 * 1e4 / 1e4 = 0.99e18 which is below minContribution and claiming is not possible.

Let’s make a final observation: The parameters can also be such that due to rounding a similar thing happens:

minContribution = 1e18 + 1 Wei
maxContribution = 1e18 + 1 Wei
minTotalContributions = 2e18 + 2 Wei
maxTotalContributions = 2e18 + 2 Wei

Due to rounding (when calculating the funding fee or when there is not a 1:1 exchange rate) the 1 Wei in the contribution can be lost (or some other small amount) and thereby when calling claim, the contribution which has been rounded down is below minContribution and the claim fails.

To summarize we have seen 3 scenarios. It is not possible for me to provide an overview of all the things that can go wrong. There are just too many variables. I come back to this point in my recommendation.

Tools Used

VSCode, Foundry

Recommended Mitigation Steps

A part of the fix is straightforward. However this is not a full fix.

I recommend to implement a functionality for claiming that cannot be blocked. I know that this may cause the “1 card = 1 vote”-policy to be violated and it may also cause minContribution or maxContribution to be violated. But maybe this is the price to pay to ensure that users can always claim.

An alternative solution may be to reduce the range of possible configurations of the crowdfund drastically such that it can be mathematically proven that users are always able to claim.

That being said there is an obvious flaw in the current code that has been confirmed by the sponsor.

The contribution amount that is calculated when claiming needs to add back the funding fee amount. I.e. if there was a 1% funding fee, the contribution amount should be 1e18 instead of 0.99e18.

Partial fix:

diff --git a/contracts/crowdfund/ReraiseETHCrowdfund.sol b/contracts/crowdfund/ReraiseETHCrowdfund.sol
index 580623d..0b1ba9e 100644
--- a/contracts/crowdfund/ReraiseETHCrowdfund.sol
+++ b/contracts/crowdfund/ReraiseETHCrowdfund.sol
@@ -268,6 +268,13 @@ contract ReraiseETHCrowdfund is ETHCrowdfundBase, CrowdfundNFT {

         {
             uint96 contribution = (votingPower * 1e4) / exchangeRateBps;
+
+            address payable fundingSplitRecipient_ = fundingSplitRecipient;
+            uint16 fundingSplitBps_ = fundingSplitBps;
+            if (fundingSplitRecipient_ != address(0) && fundingSplitBps_ > 0) {
+                contribution = (contribution * 1e4) / (1e4 - fundingSplitBps_);
+            }
+
             uint96 maxContribution_ = maxContribution;
             // Check that the contribution equivalent of total pending voting
             // power is not above the max contribution range. This can happen
@@ -360,6 +367,13 @@ contract ReraiseETHCrowdfund is ETHCrowdfundBase, CrowdfundNFT {
             // card (e.g. a party desiring a "1 card = 1 vote"-like governance
             // system where each card has equal voting power).
             uint96 contribution = (votingPowerByCard[i] * 1e4) / exchangeRateBps;
+
+            address payable fundingSplitRecipient_ = fundingSplitRecipient;
+            uint16 fundingSplitBps_ = fundingSplitBps;
+            if (fundingSplitRecipient_ != address(0) && fundingSplitBps_ > 0) {
+                contribution = (contribution * 1e4) / (1e4 - fundingSplitBps_);
+            }
+
             if (contribution < minContribution_) {
                 revert BelowMinimumContributionsError(contribution, minContribution_);
             }

0xble (Party) commented:

Additional to the partial fix recommended in the mitigation, this will be mitigated by preventing the case where minContribution may be bypassed for the last contributor when the remaining contribution is less than the minimum.


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 contribution calculation for claiming does not account for the funding fee and rounding, and the min/max contribution checks can be impossible to satisfy when splitting voting power across multiple cards.

Impact

Users may be unable to claim their pending voting power, resulting in a complete loss of their contributed funds; the report also notes a griefing attack where an attacker can contribute a small amount to a victim's pending voting power to block their claim.

What the attacker needed

Crowdfund configured with specific min/max values; user contributes multiple times; or funding fee enabled; or rounding occurs

The fix

The report recommends adding back the funding fee when calculating contribution for claim checks, and also preventing the case where minContribution is bypassed for the last contributor; the sponsor confirmed a partial fix.

How it was found

  1. Create a crowdfund with minContribution 0.9 ETH, maxContribution 1 ETH, minTotalContributions 1 ETH, maxTotalContributions 1.5 ETH.
  2. A user contributes 1 ETH, then attempts to contribute another 1 ETH but only 0.5 ETH is accepted because maxTotalContributions is reached, finalizing the crowdfund.
  3. The user's pending voting power is 1.5 ETH.
  4. The user calls claim, which reverts because the calculated contribution (1.5 ETH) exceeds maxContribution.
  5. The user tries claimMultiple, but any split would require one card's contribution to be below minContribution, so it also reverts.

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 crowdfunding contract, users contribute ETH and later claim voting power (like shares) as NFTs. The contract checks that each claim's equivalent ETH contribution is within a minimum and maximum range. If those checks fail, the user cannot claim at all, and their contributed ETH is stuck. The report shows that with certain settings, even honest users cannot claim because the numbers don't line up.

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.