Skip to content
Business logic Audit finding Intermediate

Griefing risk in mint

The mint function allows an optional list of subprotocol NFTs to register, but the encoded CID NFT ID is not guaranteed to match the newly minted ID. An attacker can frontrun a mint transaction to cause the victim's transaction to revert, or this can happen randomly during busy periods.

shenwilly Follow with gzeon

Originally disclosed on Code4rena

Submitted by shenwilly, also found by gzeon

CidNFT.sol#L147-L157 CidNFT.sol#L177-L182

CidNFT.mint() has an optional parameter _addList that enables users to register subprotocol NFTs to the CID NFT right after the mint.

However, there is no guarantee that the _cidNFTID encoded in _addList is the same ID as the newly minted NFT. If there is a pending mint transaction and another user frontrun the mint transaction with higher fee, the previous transaction will revert as the _cidNFTID is no longer the expected ID.

CidNFT.sol#L177-L182

address cidNFTOwner = ownerOf[_cidNFTID];
if (
    cidNFTOwner != msg.sender &&
    getApproved[_cidNFTID] != msg.sender &&
    !isApprovedForAll[cidNFTOwner][msg.sender]
) revert NotAuthorizedForCIDNFT(msg.sender, _cidNFTID, cidNFTOwner);

A malicious actor can grief this by frontrunning users that try to mint with non-zero _addList, causing their mint transaction to fail.

In absence of malicious actor, it is also possible for this issue to happen randomly during busy period where a lot of users are trying to mint at the same time.

Proof of Concept

  • The next CidNFT mint ID is 1000.
  • Alice wants to mint and prepares _addList with the expected _cidNFTID of 1000.
  • Bob saw Alice’s transaction and frontran her, incrementing the next minting ID to 1001.
  • Alice’s transaction tries to add subprotocol NFTs to ID 1000 which is owned by Bob. This causes the transaction to revert.

Recommended Mitigation Steps

Modify mint so that the minted ID is the one used during the add loop, ensuring that mint will always succeed.

berndartmueller (judge) commented:

Although this submission and H-01 both share a common root cause of frontrunning mints and colliding CidNFT ids in the CidNFT.add function, it is essential to note that the impact of each issue is significantly different and therefore warrant to be kept separate.

OpenCoreCH (Canto Identity) confirmed


The original report as published on Code4rena, by shenwilly. 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 mint function does not ensure that the CID NFT ID used in the add list matches the newly minted ID, so a frontrun mint can cause the add operation to target an ID owned by someone else.

What the attacker needed

Victim mints with non-zero _addList; attacker can frontrun transaction

The fix

Modify the mint function so that the minted ID is used during the add loop, ensuring the mint always succeeds.

How it was found

  1. The next CidNFT mint ID is 1000.
  2. Alice prepares a mint transaction with an add list expecting ID 1000.
  3. Bob sees Alice's transaction and frontruns it, incrementing the next mint ID to 1001.
  4. Alice's transaction tries to add subprotocol NFTs to ID 1000, which is now owned by Bob, causing a revert.

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 mint a new NFT, you can also attach other NFTs to it in the same transaction. The code assumes the new NFT will get a specific ID, but someone else can mint first and take that ID, making your transaction fail. This is a griefing attack where the attacker does not gain anything but wastes your gas.

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 shenwilly

View all

12 more disclosed reports, best first.

More from Canto Identity Subprotocols 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.