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.
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.
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.
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
- Set up the contract with a Merkle root for the allow list.
- Call purchase with an empty proof and a token ID equal to the Merkle root.
- 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.