57656 sc insight incorrect supply cap check uses token id instead of total supply in base mint

  • Submitted on: Oct 27th 2025 at 21:57:31 UTC by @iehnnkta

  • Report ID: #57656

  • Report Type: Smart Contract

  • Report severity: Insight

  • Target: https://github.com/immunefi-team/audit-comp-belong/blob/feat/cairo/src/nft/nft.cairo

  • Impacts: Permanent freezing of NFTs

Description

Brief / Intro

The _base_mint function enforces max_total_supply by comparing token_id + 1 to the cap rather than the actual minted count. This couples the cap to the token ID range, causing legitimate mints to revert and making the configured cap unreachable when IDs aren’t 0-indexed and contiguous.

Vulnerability Details

  • Root cause: admission control ties the cap to token_id (token_id + 1) instead of the real supply (total_supply + 1).

  • According to the docs, the tokenId can be anything. In many codebases token IDs may be derived from user addresses (or other non-contiguous values). If token IDs are non-sequential or large, the current check can permanently DoS the minting process.

  • Even if token IDs are sequential in some deployments, this enforcement is inconsistent with how supply is normally tracked, causing operational mismatches (e.g., a first user mints a high token ID and prevents subsequent valid mints).

Impact

triangle-exclamation

References

  • Vulnerable code location: https://github.com/immunefi-team/audit-comp-belong/blob/a17f775dcc4c125704ce85d4e18b744daece65af/src/nft/nft.cairo#L352-L355

Mitigation

Replace the token_id-based cap check with a total_supply-based check. Example patch:

```cairo fn _base_mint( ref self: ContractState, token_id: u256, recipient: ContractAddress, token_uri: felt252, ) { assert( - token_id + 1 <= self.nft_parameters.max_total_supply.read(), + self.nft_node.total_supply.read() + 1 <= self.nft_parameters.max_total_supply.read(), super::Errors::TOTAL_SUPPLY_LIMIT, );

}

Observed test run:

Was this helpful?