Skip to content
Business logic Audit finding Intermediate

ETHCrowdfundBase.sol#processContribution - Impossible to finalize crowdfund because of minContribution check

A crowdfund contract enforces a minimum contribution amount, but when the minimum contribution exceeds the gap between the maximum and minimum total contribution goals, contributions that would push the total over the maximum are refunded down to an amount below the minimum, causing a revert. This makes it impossible to reach either the minimum or maximum total, so the crowdfund cannot be finalised early and remains stuck until expiry.

TresDelinquentes Follow with Pechenite, Arz and 7 others

Originally disclosed on Code4rena

Submitted by TresDelinquentes, also found by Pechenite, Arz, Neon2835, J4X, D1r3Wolf, 3docSec, Bauchibred, chainsnake, and adeolu

The contract implements a state variable minContribution, which enforces a minimum contribution to the crowdfund.

An issue occurs when minContribution > maxTotalContribution - minTotalContribution. The protocol team even accounted for such a case, but they assumed that minTotalContribution can always be reached, so a host can then call finalize and finalize the crowdfund early, but that isn’t the case.

        // Check that the contribution amount is at or above the minimum. This
        // is done after `amount` is potentially reduced if refunding excess
        // contribution. There is a case where this prevents a crowdfunds from
        // reaching `maxTotalContributions` if the `minContribution` is greater
        // than the difference between `maxTotalContributions` and the current
        // `totalContributions`. In this scenario users will have to wait until
        // the crowdfund expires or a host finalizes after
        // `minTotalContribution` has been reached by calling `finalize()`.
        uint96 minContribution_ = minContribution;
        if (amount < minContribution_) {
            revert BelowMinimumContributionsError(amount, minContribution_);
        }

Let’s look at an example: (Keep in mind that the values can vary, this is just an example). minContribution = 2e18 minTotalContribution = 9e18 maxTotalContribution = 10e18

  • There is already 8.5e18 ETH contributed to the crowdfund.
  • We need 0.5e18 ETH to reach minTotalContribution and 1.5e18 ETH to reach maxTotalContribution, but both of these cases are impossible since minContribution = 2e18.
  • Alice contributes 2e18 ETH and totalContributions = 10.5e18, so we refund Alice 0.5e18 ETH and amount is now 1.5e18.

Then we apply this check, which will always revert. We can’t send less than minContribution and even if we send more, after we apply the refund amount will always be smaller than minContribution.

    if (amount < minContribution_) {
            revert BelowMinimumContributionsError(amount, minContribution_);
    }

At this point the crowdfund is stuck in limbo, minTotalContribution and maxTotalContribution can never be reached. Because minTotalContribution isn’t reached, the host can’t finalize the crowdfund early. Thus, the crowdfund will eventually expire and be lost.

Users will be able to call refund only after the crowdfund is Lost. The DoS will last as long as the duration of the crowdfund. If duration = 14 days, then the users will recover their funds after 14 days.

Note that if emergencyDisabled = true, the DAO won’t be able to retrieve their funds through emergencyExecute and the users will have to wait until the crowdfund is lost.

This issue can occur without anyone being malicious, although a malicious user can set up the correct state more effectively.

Proof of Concept

Paste the following inside test/crowdfund/InitialETHCrowdfund.t.sol in contract InitialETHCrowdfundTest and run forge test --mt test_MinTotalContributionsProblem -vvvv:

function _createCrowdfund(
        CreateCrowdfundArgs memory args,
        bool initialize
    ) internal returns (InitialETHCrowdfund crowdfund) {
        crowdfundOpts.initialContributor = args.initialContributor;
        crowdfundOpts.initialDelegate = args.initialDelegate;
        crowdfundOpts.minContribution = args.minContributions;
        crowdfundOpts.maxContribution = args.maxContributions;
        crowdfundOpts.disableContributingForExistingCard = args.disableContributingForExistingCard;
        crowdfundOpts.minTotalContributions = args.minTotalContributions;
        crowdfundOpts.maxTotalContributions = args.maxTotalContributions;
        crowdfundOpts.duration = args.duration;
        crowdfundOpts.exchangeRateBps = args.exchangeRateBps;
        crowdfundOpts.fundingSplitBps = args.fundingSplitBps;
        crowdfundOpts.fundingSplitRecipient = args.fundingSplitRecipient;
        crowdfundOpts.gateKeeper = args.gateKeeper;
        crowdfundOpts.gateKeeperId = args.gateKeeperId;

        partyOpts.name = "Test Party";
        partyOpts.symbol = "TEST";
        partyOpts.governanceOpts.partyImpl = partyImpl;
        partyOpts.governanceOpts.partyFactory = partyFactory;
        partyOpts.governanceOpts.voteDuration = 7 days;
        partyOpts.governanceOpts.executionDelay = 1 days;
        partyOpts.governanceOpts.passThresholdBps = 0.5e4;
        partyOpts.governanceOpts.hosts = new address[](1);
        partyOpts.governanceOpts.hosts[0] = address(this);

        crowdfund = InitialETHCrowdfund(payable(address(initialETHCrowdfundImpl).clone()));
        if (initialize) {
            crowdfund.initialize{ value: args.initialContribution }(
                crowdfundOpts,
                partyOpts,
                MetadataProvider(address(0)),
                ""
            );
        }
    }

function test_MinTotalContributionsProblem() public {
         InitialETHCrowdfund crowdfund = _createCrowdfund(
            CreateCrowdfundArgs({
                initialContribution: 0,
                initialContributor: payable(address(0)),
                initialDelegate: address(0),
                // notice the value, it's > maxTotalContributions - minTotalContributions,
                minContributions: 2 ether,
                maxContributions: type(uint96).max,
                disableContributingForExistingCard: false,
                minTotalContributions: 9 ether,
                maxTotalContributions: 10 ether,
                duration: 7 days,
                exchangeRateBps: 1e4,
                fundingSplitBps: 0,
                fundingSplitRecipient: payable(address(0)),
                gateKeeper: IGateKeeper(address(0)),
                gateKeeperId: bytes12(0)
            })
        );
        Party party = crowdfund.party();

        // Simulating users contributing to reach 8.5e18 ETH contributed
        address alice = _randomAddress();
        vm.deal(alice, 10_000 ether);
        vm.prank(alice);
        crowdfund.contribute{value: 8.5 ether }(address(alice), "");

        // Can't contribute anything < 2 ether
        vm.prank(alice);
        vm.expectRevert();
        crowdfund.contribute{value: 1 ether }(address(alice), "");

        // Can't contribute 2 ether, because 0.5 ether will be refuned which is < minContribution
        vm.prank(alice);
        vm.expectRevert();
        crowdfund.contribute{value: 2 ether}(address(alice), "");

        // At this point the crowdfund is in limbo, it can't be finalized,
        // Host, can't finalize the crowdfund
        vm.prank(address(this));
        vm.expectRevert();
        crowdfund.finalize();
    }

Tools Used

Foundry

Recommended Mitigation Steps

Possible solution is not to allow minContributions > maxTotalContributions - minTotalContributions. This mitigation may not be the best long-term solution, so we suggest exploring different mitigation.

Assessed type

DoS

0xble (Party) confirmed and commented via duplicate issue #453:

Would like to note this setup is not currently possible in production due to the way we allow crowdfunds to be configured for ETH raises in our UI at party.app. This is because either minTotalContributions == maxTotalContributions or maxTotalContributions == type(uint96).max depending on the option the Party creator selects when they choose “Allow Flexible Contributions” in our “Start a Party” page.

0xble (Party) commented via duplicate issue #453:

Posting this here too for reference:

Upon reflection, while it is similar to the issue pointed out in the comment, the finding does add nuance beyond what was acknowledged in our code comment and points out a scenario that goes beyond that mentioned. We’d like to consider it valid. It also helps that the mitigation is strong, we’d like to implement it

In our comment we mention “In this scenario, users will have to wait until the crowdfund expires or a host finalizes”, but in this finding’s scenario, it would not be possible for a host to finalize.

Another, probably more significant, factor behind us changing our minds to consider this valid and “sponsor confirmed” is that the mitigation proposed cleanly prevents the scenario from happening.

Perhaps we are being too lenient here to consider it valid. I do not entirely disagree with the comment here. I’ll just give the reasoning behind why we chose to confirm the issue, but would like to leave it to the judge to ultimately decide, as I lack context on the standard C4 usually applies to validate finding.

gzeon (judge) commented via duplicate issue #453:

This is clearly out-of-scope, the fact that the proposed mitigation is good should not affect the validity of this issue for fairness.

J4X (warden) commented via duplicate issue #453:

@gzeon - Thanks for taking a look at the issue. I’d like to emphasize that, in my perspective, this issue should not be considered out of scope based on the following arguments.

The rationale for categorizing this issue as out of scope is primarily linked to the comment in Line 247-254. However, it’s crucial to note that the comment discusses a different scenario and severity. Specifically, the comment states, “In this scenario, users will have to wait until the crowdfund expires or a host finalizes after minTotalContribution has been reached by calling finalize()”. It’s important to highlight that the host finalizing the crowdfund is not feasible in the context showcased and validated by the POC. In this case, I’ve outlined that no host has the capability to prematurely close the fund and rescue user funds. This leads to a different threat than described by the comment, which incorrectly gives users the security of their funds being rescued by a host in the case of a crowdfund getting stuck.

Furthermore, the comment illustrates a situation where minTotalContributions can still be reached by depositing, while maxTotalContributions cannot be achieved. This state can be described as an invariant: minTotalContributions <= potentialDeposits < maxTotalContributions. In this case, I’ve presented that neither of these thresholds can be reached. The invariant for my scenario reads as follows: potentialDeposits < minTotalContributions <= maxTotalContributions. Looking at those invariants one can easily determine that although using similar variables, the 2 states differ.

It’s crucial to note that my issue outlines a method by which a malicious user could exploit the vulnerability to freeze other users’ funds or potentially lead to a loss of user funds, due to the arbitrarily selectable duration of the crowdfund. Unlike the situation described in the comment, a “permanent” loss of user funds would be possible in my case. According to the comment, the host can always close the funds after a sufficient number of deposits have been received. This is impossible in the state my issue describes, as minTotalContributions can never be reached, further differentiating the issues.

gzeon (judge) commented via duplicate issue #453:

Fair, judging as Medium due to funds are only stuck but not lost in a reasonably configured party (expire after realistic duration).


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

The contract checks the contribution amount against the minimum after refunding any excess over the maximum total, without ensuring that the refunded amount still meets the minimum, and without validating that the minimum contribution is compatible with the gap between the total goals.

Impact

The crowdfund cannot be finalised early and remains stuck until it expires, after which users can only then request refunds; the text notes that if emergencyDisabled is true, funds cannot be retrieved via emergencyExecute either.

What the attacker needed

Crowdfund configured with minContribution > maxTotal -…; contributions reach a total where remaining space <…

The fix

The recommended mitigation is to disallow configurations where minContributions > maxTotalContributions - minTotalContributions, though the text suggests exploring other solutions.

How it was found

  1. Create a crowdfund with minContribution = 2 ether, minTotalContributions = 9 ether, maxTotalContributions = 10 ether.
  2. Have users contribute 8.5 ether in total.
  3. Attempt to contribute 1 ether: it reverts because it is below the minimum contribution.
  4. Attempt to contribute 2 ether: the excess 0.5 ether is refunded, leaving 1.5 ether, which is below the minimum, so it reverts.
  5. Attempt to finalise the crowdfund: it reverts because the minimum total has not been reached.

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.

A crowdfund lets people add money until a target is reached. The contract also says each person must add at least a certain amount. If someone tries to add more than the remaining space, the extra is refunded, but then the amount actually added can fall below the minimum, so the transaction is rejected. This can leave the crowdfund unable to reach its goal, so it cannot be closed early and people must wait for it to expire to get their money back.

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 TresDelinquentes

View all

4 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.