buyPass sells a tier only while passSupply[id] < passMaxSupply[id]. IFestivalPass documents maxSupply as the "Maximum number of passes that can be sold". It is the only scarcity and capacity control on passes.
buyPass makes its external interaction before it updates state. _mint goes through OpenZeppelin _updateWithAcceptanceCheck -> ERC1155Utils.checkOnERC1155Received, which calls onERC1155Received on any buyer with code. ++passSupply[collectionId] runs only after that callback returns, and buyPass has no reentrancy guard. A contract buyer that calls buyPass again from the callback therefore sees the stale passSupply every time. Each nested call passes the cap check, so one remaining slot becomes any number of passes.
Likelihood:
Any account that deploys a receiver contract can do it whenever a tier has at least one unsold pass, which is the normal state throughout a sale. No privileged role is involved.
The attacker pays face value for every pass and needs a custom contract. The motive is scalping a capped tier, or collecting the extra welcome bonuses and 2x/3x earners, so this is a deliberate, specific action rather than an accident.
Impact:
The tier's supply cap is broken. In the PoC, a BACKSTAGE tier with cap 3 and one slot left ends at passSupply == 7, with the attacker holding 5 passes. A tier with cap 1 and nothing sold yields 10 passes in one transaction. The festival is oversold, and holders of a capped asset are diluted.
Every over-cap pass also mints an unplanned welcome bonus (75 BEAT for 5 BACKSTAGE passes in the PoC) and adds an extra 2x/3x reward earner. The attacker pays face value per pass, so no ETH is stolen. Honest buyers are refused afterwards, but they would have hit the cap anyway; the added harm is the k - 1 passes above the cap.
BF02ReentrantBuyer calls buyPass{value: price}(3) again from onERC1155Received while a counter is below k.
test_baseline_capEnforcedForEOA shows that an EOA cannot go past the cap.
test_reentrancy_mintsPastMaxSupply starts from passSupply = MAX - 1 and ends at MAX - 1 + k. The attacker holds k passes and k bonuses and paid exactly k x price.
test_reentrancy_fromZero_capOfOne mints 10 passes against a cap of 1.
Save as test/PoC_BF-02.t.sol and run from the repository root:
FOUNDRY_FFI=false forge test --match-path test/PoC_BF-02.t.sol -vv
Observed output (excerpt):
Follow checks-effects-interactions: count the pass before _mint hands control to the buyer. Adding OpenZeppelin ReentrancyGuard and marking buyPass nonReentrant gives defence in depth.
# Function `FestivalPass:buyPass` Lacks Defense Against Reentrancy Attacks, Leading to Exceeding the Maximum NFT Pass Supply ## Description * Under normal circumstances, the system should control the supply of tokens or resources to ensure that it does not exceed a predefined maximum limit. This helps maintain system stability, security, and predictable behavior. * The function `FestivalPass:buyPass` does not follow the **Checks-Effects-Interactions** pattern. If a user uses a malicious contract as their account and includes reentrancy logic, they can bypass the maximum supply limit. ```solidity function buyPass(uint256 collectionId) external payable { // Must be valid pass ID (1 or 2 or 3) require(collectionId == GENERAL_PASS || collectionId == VIP_PASS || collectionId == BACKSTAGE_PASS, "Invalid pass ID"); // Check payment and supply require(msg.value == passPrice[collectionId], "Incorrect payment amount"); require(passSupply[collectionId] < passMaxSupply[collectionId], "Max supply reached"); // Mint 1 pass to buyer @> _mint(msg.sender, collectionId, 1, ""); // question: potential reentrancy? ++passSupply[collectionId]; // VIP gets 5 BEAT welcome bonus, BACKSTAGE gets 15 BEAT welcome bonus uint256 bonus = (collectionId == VIP_PASS) ? 5e18 : (collectionId == BACKSTAGE_PASS) ? 15e18 : 0; if (bonus > 0) { // Mint BEAT tokens to buyer BeatToken(beatToken).mint(msg.sender, bonus); } emit PassPurchased(msg.sender, collectionId); } ``` ## Risk **Likelihood**: * If a user uses a contract wallet with reentrancy logic, they can trigger multiple malicious calls during the execution of the `_mint` function. **Impact**: * Although the attacker still pays for each purchase, the total number of minted NFTs will exceed the intended maximum supply. This can lead to supply inflation and user dissatisfaction. ## Proof of Concept ````Solidity //SPDX-License-Identifier: MIT pragma solidity 0.8.25; import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol"; import "../src/FestivalPass.sol"; import "./FestivalPass.t.sol"; import {console} from "forge-std/Test.sol"; contract AttackBuyPass{ address immutable onlyOnwer; FestivalPassTest immutable festivalPassTest; FestivalPass immutable festivalPass; uint256 immutable collectionId; uint256 immutable configPassPrice; uint256 immutable configPassMaxSupply; uint256 hackMintCount = 0; constructor(FestivalPassTest _festivalPassTest, FestivalPass _festivalPass, uint256 _collectionId, uint256 _configPassPrice, uint256 _configPassMaxSupply) payable { onlyOnwer = msg.sender; festivalPassTest = _festivalPassTest; festivalPass = _festivalPass; collectionId = _collectionId; configPassPrice = _configPassPrice; configPassMaxSupply = _configPassMaxSupply; hackMintCount = 1; } receive() external payable {} fallback() external payable {} function DoAttackBuyPass() public { require(msg.sender == onlyOnwer, "AttackBuyPass: msg.sender != onlyOnwer"); // This attack can only bypass the "maximum supply" restriction. festivalPass.buyPass{value: configPassPrice}(collectionId); } function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4){ if (hackMintCount festivalPass.passMaxSupply(targetPassId)); } } ``` ```` ## Recommended Mitigation * Refactor the function `FestivalPass:buyPass` to follow the **Checks-Effects-Interactions** principle. ```diff function buyPass(uint256 collectionId) external payable { // Must be valid pass ID (1 or 2 or 3) require(collectionId == GENERAL_PASS || collectionId == VIP_PASS || collectionId == BACKSTAGE_PASS, "Invalid pass ID"); // Check payment and supply require(msg.value == passPrice[collectionId], "Incorrect payment amount"); require(passSupply[collectionId] < passMaxSupply[collectionId], "Max supply reached"); // Mint 1 pass to buyer - _mint(msg.sender, collectionId, 1, ""); ++passSupply[collectionId]; + emit PassPurchased(msg.sender, collectionId); + _mint(msg.sender, collectionId, 1, ""); // VIP gets 5 BEAT welcome bonus, BACKSTAGE gets 15 BEAT welcome bonus uint256 bonus = (collectionId == VIP_PASS) ? 5e18 : (collectionId == BACKSTAGE_PASS) ? 15e18 : 0; if (bonus > 0) { // Mint BEAT tokens to buyer BeatToken(beatToken).mint(msg.sender, bonus); } - emit PassPurchased(msg.sender, collectionId); } ```
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.