Skip to content
Business logic Audit finding Intermediate

PartyGovernanceNFT#rageQuit() can lead to token loss for users when dealing with zero-balance ERC20 during a rageQuit()

The rageQuit function in PartyGovernanceNFT skips the minimum withdrawal amount check when the calculated withdrawal amount for an ERC20 token is zero, allowing users to burn their Party tokens without receiving any tokens in return. An attacker could exploit this by ensuring the Party's balance of a token is zero before a user calls rageQuit, causing the user to lose their tokens.

TresDelinquentes Follow with 0xA5DF, 3docSec and 1 other

Originally disclosed on Code4rena

Submitted by TresDelinquentes, also found by 0xA5DF, 3docSec, and Pechenite

Calling Party’s rageQuit() with a zero-balance ERC20 disregards the minWithdrawAmounts array, resulting in the loss of user tokens without compensation.

Proof of Concept

Consider the following scenario illustrating the issue:

  1. A Party holds USDC tokens.
  2. The entire USDC balance is transferred to another account, e.g., via a proposal.
  3. Alice, unaware of the Party’s depleted USDC holdings, attempts to rageQuit().
  4. Alice specifies minimum withdrawal amounts using uint256[] minWithdrawAmounts.
  5. Despite specifying minWithdrawAmounts, all of Alice’s Party tokens are burned, and she receives nothing in return.

In PartyGovernanceNFT#rageQuit() the withdrawl amount for each ERC20 is calculated as follows:

withdrawAmounts[i] += (balance * getVotingPowerShareOf(tokenIds[j])) / 1e18;

Where:

balance = uint256 balance = address(withdrawTokens[i]) == ETH_ADDRESS ? address(this).balance : withdrawTokens[i].balanceOf(address(this));

However, if the token is an ERC20 for which the Party does not have any remaining balance, withdrawAmounts[i] would be equal to 0.

This means the following check would not be executed at all:

if (amount > 0) { //@audit Would be skipped if amount is equal to 0.
    // ...
    // Check amount is at least minimum.
    if (amount < minAmount) { // This is never checked if amount is equal to 0.
        revert BelowMinWithdrawAmountError(amount, minAmount);
    }

    // ...
    payable(receiver).transferEth(amount);
}

Since the check for the minimum withdrawal amount is within the if statement, it is never executed when amount is equal to 0, leading to unintended NFT loss.

uint96 totalVotingPowerBurned = _burnAndUpdateVotingPower(tokenIds, !isAuthority_);

// Update total voting power of party.
_getSharedProposalStorage().governanceValues.totalVotingPower -= totalVotingPowerBurned;

PoC:

// Add this to PartyGovernanceNFT.t.sol

function testRageQuitDoesNotHonorMinWithdrawAmountIsERC20BalanceIsZero() external {
    // Create party
    (Party party, , ) = partyAdmin.createParty(
        partyImpl,
        PartyAdmin.PartyCreationMinimalOptions({
            host1: address(this),
            host2: address(0),
            passThresholdBps: 5100,
            totalVotingPower: 100,
            preciousTokenAddress: address(toadz),
            preciousTokenId: 1,
            rageQuitTimestamp: 0,
            feeBps: 0,
            feeRecipient: payable(0)
        })
    );

	// Configure rage quit
    vm.prank(address(this));
    party.setRageQuit(uint40(block.timestamp) + 1);

	// Give alice 10 voting tokens out of 100
    address alice = makeAddr("alice");
    vm.prank(address(partyAdmin));
    uint256 tokenId = party.mint(alice, 10, alice);

	// An ERC20 in which the party previously had holdings
	// but now it's balance is == 0.
    IERC20[] memory tokens = new IERC20[](1);
    tokens[0] = IERC20(address(new DummyERC20()));

	// The minimum withdraw alice is willing to accept
    uint256[] memory minWithdrawAmounts = new uint256[](1);
    minWithdrawAmounts[0] = 1; // Notice it's a value >0 to demonstrate the non-working check

    uint256[] memory tokenIds = new uint256[](1);
    tokenIds[0] = tokenId;

    // Make sure the party has 0 balance
    DummyERC20(address(tokens[0])).deal(address(party), 0);

    // Before
    assertEq(party.votingPowerByTokenId(tokenId), 10); // alice has 10 voting tokens
    assertEq(tokens[0].balanceOf(alice), 0); // alice has 0 DummyERC20s

    vm.prank(alice);
    party.rageQuit(tokenIds, tokens, minWithdrawAmounts, alice); // This should revert

    // After
    assertEq(party.votingPowerByTokenId(tokenId), 0); // alice has lost her 10 voting tokens
    assertEq(tokens[0].balanceOf(alice), 0); // alice's dummyERC20 balance is still 0
    assertEq(party.getGovernanceValues().totalVotingPower, 90);
}

Recommended Mitigation Steps

To ensure that the BelowMinWithdrawAmountError check is performed even when amount is equal to 0, amount > 0 must be replaced with amount >= 0 in the rageQuit() function. Here’s the modified code snippet:

--- a/contracts/party/PartyGovernanceNFT.sol
+++ b/contracts/party/PartyGovernanceNFT.sol
@@ -418,17 +418,17 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
                     // Transfer fee to fee recipient.
                     if (address(token) == ETH_ADDRESS) {
                         payable(feeRecipient).transferEth(fee);
                     } else {
                         token.compatTransfer(feeRecipient, fee);
                     }
                 }

-                if (amount > 0) {
+                if (amount >= 0) {
                     uint256 minAmount = minWithdrawAmounts[i];

                     // Check amount is at least minimum.
                     if (amount < minAmount) {
                         revert BelowMinWithdrawAmountError(amount, minAmount);
                     }

                     // Transfer token from party to recipient.

Assessed type

Invalid Validation

gzeon (judge) commented:

Linking over the comment made here.

Potential value leak, no reason to ignore specified values. Judging as Medium… because while a function of the protocol is impacted, asset is not lost considering the user should call ragequit before the proposal that transfer out the token is executed.

0xble (Party) confirmed


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 minimum withdrawal amount check is placed inside an if (amount > 0) block, so it is never executed when the calculated withdrawal amount is zero.

Impact

Users could lose their Party tokens without receiving any tokens in return when the Party's balance of a specified ERC20 is zero, but the judge noted that the asset is not lost if the user calls rageQuit before the proposal that transfers out the token is executed.

What the attacker needed

Party holds an ERC20 token; Token balance becomes zero before rageQuit; User calls rageQuit with minWithdrawAmounts

The fix

The check should be performed even when the amount is zero by replacing `amount > 0` with `amount >= 0` in the `rageQuit()` function.

How it was found

  1. A Party holds USDC tokens.
  2. The entire USDC balance is transferred to another account, e.g., via a proposal.
  3. Alice, unaware of the Party’s depleted USDC holdings, attempts to rageQuit().
  4. Alice specifies minimum withdrawal amounts using uint256[] minWithdrawAmounts.
  5. Despite specifying minWithdrawAmounts, all of Alice’s Party tokens are burned, and she receives nothing in return.

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.

When a user wants to leave a Party (a group investment club), they call rageQuit to burn their membership tokens and receive their share of the assets. They can specify a minimum amount they are willing to accept for each token. However, if the Party has no balance of a particular token, the code skips the minimum check entirely, so the user's membership tokens are burned and they get nothing 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.