Skip to content
Business logic Audit finding Intermediate

Selling will be bricked if all other tokens are withdrawn to ERC20 token

The fee splitter's total supply calculation returns zero when every token holder has withdrawn their tokens to the ERC20 contract, so the fee distribution call reverts. This means a remaining holder cannot sell their tokens, effectively locking them out of the sale path.

BowTiedOriole Follow with d3e4, McToady and 14 others

Originally disclosed on Code4rena

Submitted by BowTiedOriole, also found by d3e4, McToady, slylandro_star, 0xmystery, ether_sky, amaechieth, 0xPhantom, wangxx2026, nuthan2x, zxriptor, Bobface, Krace, hals, cats, EV_om, and AlexCzm

https://github.com/code-423n4/2024-01-curves/blob/main/contracts/FeeSplitter.sol#L90

https://github.com/code-423n4/2024-01-curves/blob/main/contracts/FeeSplitter.sol#L43-L46

https://github.com/code-423n4/2024-01-curves/blob/main/contracts/Curves.sol#L248

FeeSplitter.addFees() reverts if the totalSupply of the token is 0. The total supply is calculated via the formula below:

return (curves.curvesTokenSupply(token) - curves.curvesTokenBalance(token, address(curves))) * PRECISION;

Consider the following scenario:

  1. Alice buys 1 Curve token to initiate herself as a token subject and withdraws her token to ERC20.
  2. Bob buys 1 Curve token.
  3. Charlie buys 10 Curve tokens and immediately withdraws all of them to the ERC20 contract.
  4. Bob tries to sell 1 Curve token but is not able to because all other tokens are ERC20.

Bob’s transaction will revert because FeeSplitter.totalSupply() will return 0.

Proof of Concept

it("Selling can be bricked if all other tokens are in ERC20 contract", async () => {
    await testContract.setMaxFeePercent(parseEther('.4'));
    await testContract.setProtocolFeePercent(parseEther('.1'), owner.address);
    await testContract.setExternalFeePercent(parseEther('.1'), parseEther('.1'), parseEther('.1'));

    await testContract.buyCurvesToken(owner.address, 1);
    await testContract.connect(owner).withdraw(owner.address, 1);

    await testContract.connect(friend).buyCurvesToken(owner.address, 1, { value: parseEther("1")});
    await testContract.connect(friend2).buyCurvesToken(owner.address, 5, { value: parseEther("1")});
    await testContract.connect(friend2).withdraw(owner.address, 5);

    await expect(testContract.connect(friend).sellCurvesToken(owner.address, 1)).to.be.revertedWith("NoTokenHolders()");
});

Recommended Mitigation Steps

Check if the Curve contract balance matches the total supply, and if so, send the holder fee to the protocol.

if (curvesTokenSupply[curvesTokenSubject] == curvesTokenBalance[curvesTokenSubject][address(this)]) {
    (bool success, ) = feesEconomics.protocolFeeDestination.call{value: holderFee}("");
    if (!success) revert CannotSendFunds();
} else {
    feeRedistributor.onBalanceChange(curvesTokenSubject, msg.sender);
    feeRedistributor.addFees{value: holderFee}(curvesTokenSubject);
}

Alternatively, you can call _transferFees prior to updating token balances and supply, but this will require reentrancy guards as well as other adjustments to the fee calculations.

andresaiello (Curves) confirmed


The original report as published on Code4rena, by BowTiedOriole. 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 total supply calculation subtracts the contract's own token balance, so when all tokens sit in the ERC20 wrapper the result is zero and the fee distribution reverts.

Impact

A holder may be unable to sell their tokens while all other tokens are held in the ERC20 contract, blocking the sale.

What the attacker needed

Tokens withdrawn to ERC20 contract; at least one remaining holder

The fix

The report suggests checking whether the contract's token balance equals the total supply and, if so, sending the holder fee to the protocol instead of the fee redistributor.

How it was found

  1. Alice buys one token and withdraws it to the ERC20 contract.
  2. Bob buys one token.
  3. Charlie buys ten tokens and withdraws all of them to the ERC20 contract.
  4. Bob tries to sell one token and the transaction 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 token contract tracks who owns how many tokens. Some owners moved their tokens into a separate ERC20 wrapper contract, which changes how the contract counts holders. When the contract tried to work out the total supply for fee sharing, it got zero and refused to continue, so the last remaining seller could not complete a sale.

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 BowTiedOriole

View all

4 more disclosed reports, best first.

More from Curves

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.