Skip to content
Business logic Audit finding Intermediate

GroupBuy may purchase NFT not in the allowed list

When the purchase proof is empty, the GroupBuy contract compares the token ID directly to the Merkle root instead of verifying a proof. This allows an attacker to purchase any token whose ID equals the Merkle root, even if it is not in the allowed list.

gzeon Follow with Trust and Lambda

Originally disclosed on Code4rena

Submitted by gzeon, also found by Trust and Lambda

When _purchaseProof.length == 0, GroupBuy.purchase compare the tokenId with the merkleRoot. This allows any tokenId that matches the merkleRoot to be purchased, even if they are not included in the allow list during setup.

https://github.com/code-423n4/2022-12-tessera/blob/f37a11407da2af844bbfe868e1422e3665a5f8e4/src/modules/GroupBuy.sol#L186-L188

        if (_purchaseProof.length == 0) {
            // Hashes tokenId to verify merkle root if proof is empty
            if (bytes32(_tokenId) != merkleRoot) revert InvalidProof();

Proof of Concept

Add the following to GroupBuy.t.sol. It would still revert (since no such nft existed) but not as expected.

    // modified from testPurchaseRevertInvalidProof
    function testPurchaseRevertInvalidTokenIdZeroLength() public {
        // setup
        testContributeSuccess();
        // exploit
        uint256 invalidPunkId = uint256(nftMerkleRoot);
        bytes32[] memory invalidPurchaseProof = new bytes32[](0);
        // expect
        vm.expectRevert(INVALID_PROOF_ERROR);
        // execute
        _purchase(
            address(this),
            currentId,
            address(punksBuyer),
            address(punks),
            invalidPunkId,
            minValue,
            purchaseOrder,
            invalidPurchaseProof
        );
    }

Tools Used

Foundry

Recommended Mitigation Steps

Hash the tokenId even if there is only when length is 1.

stevennevins (Tessera) disagreed with severity

HickupHH3 (judge) decreased severity to Medium and commented:

Best report because Foundry POC.


The original report as published on Code4rena, by gzeon. 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 contract incorrectly treats an empty proof as a special case where the token ID is compared directly to the Merkle root, bypassing the intended allow-list verification.

Impact

An attacker could purchase an NFT that is not on the allowed list, potentially bypassing the group's intended restrictions.

What the attacker needed

A group buy contract with an allow list; attacker can call purchase

The fix

The contract should always verify the Merkle proof, even when the proof length is zero, by hashing the token ID and checking it against the root.

How it was found

  1. Set up the contract with a Merkle root for the allow list.
  2. Call purchase with an empty proof and a token ID equal to the Merkle root.
  3. The contract does not revert with InvalidProof as expected, allowing the purchase.

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 Merkle root is a single fingerprint representing a list of allowed items. Normally, a buyer provides a proof showing their item is in that list. Here, if no proof is given, the contract just checks if the item's ID equals the fingerprint itself, which is a mistake. So someone can buy an item that was never approved, as long as its ID happens to match the fingerprint.

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 gzeon

View all

46 more disclosed reports, best first.

More from Tessera - Versus 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.