Skip to content
Business logic Audit finding Intermediate

ETH will get stuck if all NFTs do not get sold.

The FixedPrice and LPDA sale contracts only transfer collected ETH to the sale receiver when every NFT in the batch is sold. If only some NFTs sell, the ETH remains stuck in the contract with no function to withdraw it, forcing the creator to buy the remaining NFTs to recover funds.

AkshaySrivastav Follow with seyni, tnevler and 34 others

Originally disclosed on Code4rena

Submitted by AkshaySrivastav, also found by seyni, tnevler, wait, nalus, immeas, gzeon, lukris02, minhtrng, kiki_dev, adriro, Soosh, KingNFT, mahdikarimi, ladboy233, jonatascm, kree-dotcom, csanuragjain, _Adam, hihen, jadezti, reassor, gz627, 0xA5DF, 0xdeadbeef0x, nameruse, danyams, hansfriese, Madalad, gasperpre, yixxas, Parth, lumoswiz, obront, eyexploit, rvierdiiev, and 0x52

https://github.com/code-423n4/2022-12-escher/blob/main/src/minters/FixedPrice.sol#L73

https://github.com/code-423n4/2022-12-escher/blob/main/src/minters/LPDA.sol#L81-L88

Impact

In the buy function of FixedPrice and LPDA contracts, the transfer of funds to saleReceiver only happens when newId becomes equal to finalId, i.e, when the entire batch of NFTs gets sold completely.

FixedPrice:

        if (newId == sale_.finalId) _end(sale);

LPDA:

        if (newId == temp.finalId) {
            sale.finalPrice = uint80(price);
            uint256 totalSale = price * amountSold;
            uint256 fee = totalSale / 20;
            ISaleFactory(factory).feeReceiver().transfer(fee);
            temp.saleReceiver.transfer(totalSale - fee);
            _end();
        }

This logic can cause issues if only a subset of NFTs get sold. In that case the ETH collected by contract from the sales of NFTs will get stuck inside the contract.

There is no function inside those contracts to recover the ETH collected from the partial sale of the NFT batch. There is also no function to send back those ETH to the NFT buyers. This causes the ETH to be in a stuck state as they cannot be pulled from the contracts.

The only way to recover those ETH is to explicitly buy the entire batch of to-be-sold NFTs so that the contract automatically triggers the sale ending conditions. This recovery method may require a decent amount of upfront capital to buy all unsold NFTs.

Proof of Concept

Consider this scenario:

  • The sale contract deployer deploys a sale contract (FixedSale) to sell 100 NFTs ranging from id 1 to 100 with price 1 ETH per NFT.
  • Users only buy the initial 10 NFTs. So the sale contract now has 10 ETH and currently 90 NFTs are unsold.
  • No more users buy anymore NFTs from the sale contract.
  • The 10 ETH are in stuck state as the saleReceiver cannot pull them out even though some NFTs have been already legitimately sold.
  • To recover those 10 ETH, the contract deployer or saleReceiver has to come up with 90 ETH and buy the unsold 90 NFTs.

The scenario for the LPDA sale contract is similar. ETH can get stuck for partial batch NFT sales and upfront capital will be needed to recover the ETH.

Recommended Mitigation Steps

The contracts can have an additional function to claim the ETH collected from already successful NFT sales.

    function claim() external onlyOwner {
        ISaleFactory(factory).feeReceiver().transfer(address(this).balance / 20);
        sale.saleReceiver.transfer(address(this).balance);
    }

Please note, use of transfer is not recommended. The above code is just an example mitigation.

mehtaculous (Escher) disagreed with severity and commented:

The creator could simply buy the remaining IDs and then receive their ETH in the same transaction, effectively unsticking the sale. Not considered High priority, but do agree there should be a better cancellation pattern for when all the NFTs do not get sold.

berndartmueller (judge) decreased severity to Medium and commented:

The demonstrated finding has an external requirement (too many token ids, low buy pressure,…), and there exists the possibility for the creator to buy the remaining, unsold IDs (which may or may not be expensive). Therefore, I am downgrading the finding to Medium severity.


The original report as published on Code4rena, by AkshaySrivastav. 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 contracts only release funds when the entire batch of NFTs is sold, with no fallback withdrawal function for partial sales.

Impact

ETH from partial sales becomes stuck in the contract, and the creator may need significant upfront capital to buy the remaining NFTs to recover it.

What the attacker needed

A deployed sale contract; partial NFT sales; no further purchases

The fix

The contracts should include a function allowing the owner to claim the ETH collected from successful sales.

How it was found

  1. Deploy a FixedPrice sale contract for 100 NFTs at 1 ETH each.
  2. Users buy only the first 10 NFTs, leaving 90 unsold.
  3. No further purchases occur, so the 10 ETH remain stuck in the contract.
  4. To recover the ETH, the creator must buy the remaining 90 NFTs.

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 you buy an NFT, your money (ETH) goes into a smart contract. The contract is supposed to send that money to the seller, but it only does so after every single NFT in the batch is sold. If not all NFTs sell, the money stays trapped in the contract and nobody can take it out.

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 AkshaySrivastav

View all

16 more disclosed reports, best first.

More from Escher contest

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.