In `SantasList.sol`, the `buyPresent` function violates the secure **Checks-Effects-Interactions (CEI)** pattern. The contract initiates an external interaction by calling `_mintAndIncrement()`, which triggers the OpenZeppelin `_safeMint` protocol, **before** increasing the state variable tracking the token identifiers (`s_tokenCounter++`).
Furthermore, because SantaToken.sol utilizes the minimal Solmate ERC20 suite, it lacks the implicit global state locks or structural safety overrides present in more defensive frameworks. When _safeMint executes, it verifies if the recipient is a contract and immediately dispatches an external execution control transfer via the onERC721Received hook.
A malicious smart contract can intercept this execution hook and perform a re-entry back into buyPresent while the previous execution frame remains incomplete. Because the global s_tokenCounter state has not settled, this disrupts internal tracking and breaks proper token status sequence constraints.
Likelihood:
High. The buyPresent function is completely public, unguarded by any access control modifiers, and does not implement a nonReentrant state lock.
Impact:
NFT State Exploitation & Mint Hijacking: Attackers can hijack the execution stack mid-transaction to re-order asset ownership parameters, bypass contract supply limitations, or break sequential index assumptions relied upon by external tracking marketplaces.
To execute this attack, the attacker deploys a malicious contract containing an orchestrated onERC721Received logic gate acting as the execution interceptor:
Add the following test scenario to your test/unit/SantasListTest.t.sol file to prove that the execution successfully duplicates ownership claims before the initial call block resolves:
Enforce the strict Checks-Effects-Interactions model by updating all internal status numbers before sending out external calls or processing standard ERC721 mint hooks.
Introduce a defensive execution guard wrapper by adding OpenZeppelin's ReentrancyGuard and applying the nonReentrant modifier directly to the buyPresent entry point.
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.