Normal Behavior:
In a secure smart contract system, functions that interact with external contracts (such as token mints, burns, or ETH transfers) should always update all relevant internal state before making any external calls. This is known as the Checks-Effects-Interactions (CEI) pattern and is a fundamental best practice in Solidity to prevent reentrancy attacks. Additionally, using reentrancy guards (such as OpenZeppelin’s ReentrancyGuard
) is recommended for extra protection.
Issue:
In the FestivalPass
contract, several core functions (buyPass
, attendPerformance
, and redeemMemorabilia
) violate the CEI pattern. They make external calls (to BeatToken.mint
or BeatToken.burnFrom
) before updating critical state variables such as supply counters, attendance records, or item IDs. This allows a malicious contract to reenter these functions before the state is updated, bypassing important checks and invariants. As a result, attackers can:
Mint more passes or NFTs than the maximum allowed.
Receive multiple rewards for a single action.
Drain the contract’s ETH balance if similar patterns exist in withdrawal logic.
Relevant Code Example:
Other Affected Functions:
attendPerformance
: External call to BeatToken.mint
before updating attendance state.
redeemMemorabilia
: External call to BeatToken.burnFrom
before incrementing currentItemId
.
Likelihood:
This vulnerability is highly likely to be exploited in any public or composable system where users can deploy arbitrary contracts. Attackers can create malicious contracts specifically designed to exploit reentrancy by calling back into the vulnerable functions before state is updated.
The risk is further increased if the project is high-profile, has valuable assets, or is deployed on a public network where adversaries actively search for such flaws.
Impact:
Supply Manipulation: Attackers can mint more passes or NFTs than the intended maximum, breaking scarcity guarantees and devaluing legitimate user holdings.
Multiple Rewards: Attackers can receive multiple attendance rewards or bonuses for a single event, draining the reward pool and undermining the intended incentive structure.
Fund Drain: If similar patterns exist in withdrawal or payment logic, attackers could drain the contract’s ETH or token balances.
Loss of Trust: Exploitation of these vulnerabilities can lead to significant financial loss, user complaints, negative publicity, and loss of trust in the protocol.
To demonstrate the exploit, copy and paste the following code into your test file (e.g., test/contract.t.sol
). This test deploys a malicious contract that exploits the reentrancy vulnerability in buyPass
to mint more passes than the maximum supply. Similar attacks can be constructed for attendPerformance
and redeemMemorabilia
.
Explanation:
The attacker contract calls buyPass
, which triggers BeatToken.mint
.
During the mint, the attacker's onERC1155Received
is called, which reenters buyPass
before the supply is updated.
This allows the attacker to mint more passes than the maximum supply, bypassing the intended limit.
Variants:
Similar attacker contracts can be written for attendPerformance
(to claim multiple rewards) and redeemMemorabilia
(to mint more NFTs than allowed).
1. Refactor to Checks-Effects-Interactions Pattern:
Update all vulnerable functions to update internal state before making any external calls. This ensures that reentrant calls will fail the relevant checks.
2. Add Reentrancy Guards:
Consider using OpenZeppelin’s ReentrancyGuard
to further protect all functions that transfer tokens or ETH, or interact with external contracts.
3. Review All External Calls:
Audit all functions for similar patterns, including those that interact with user contracts, token contracts, or perform ETH transfers.
4. Test for Reentrancy:
Add comprehensive tests for reentrancy using attacker contracts to ensure that all critical functions are protected.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.