The SoulboundProfileNFT::mintProfile
function is vulnerable to reentrancy attacks due to the use of _safeMint
, which triggers an external call to the recipient's onERC721Received
function. A malicious contract can exploit this to mint multiple profiles, violating the "one profile per user" constraint.
Root Cause:
The SoulboundProfileNFT::mintProfile
function uses _safeMint
, which calls the recipient’s onERC721Received
function.
The state, profileToToken
and _profiles
, is updated after this external call.
A malicious recipient can reenter mintProfile
during the callback, bypassing the profileToToken[msg.sender] == 0
check and minting multiple profiles.
Example Attack Flow:
User A (a malicious contract) calls SoulboundProfileNFT::mintProfile()
.
_safeMint
triggers onERC721Received
in User A’s contract.
User A’s contract reenters mintProfile
before profileToToken
is updated.
A second profile is minted for User A, violating the protocol’s design.
Protocol Integrity Failure: Users can mint multiple profiles, breaking the "one profile per user" rule.
Metadata Corruption: Multiple tokens with conflicting metadata can be associated with a single user.
Fund Loss (Indirect): If the protocol charges fees for profile creation, attackers can drain funds by minting repeatedly.
Add the following test case to your Foundry test suite:
Expected Result Before Fix:
The test passes, showing that the attacker successfully minted two profiles.
Expected Result After Fix:
The test fails, as reentrancy is prevented.
Option 1: Add a Reentrancy Guard
Use OpenZeppelin’s ReentrancyGuard
to block reentrant calls:
Follow the Checks-Effects-Interactions (CEI) Pattern
Restructure the mintProfile function to update state before making external calls.
Likelihood: High, anyone can do it. Impact: Low, several profile will be minted, which is not allowed by the protocol, but only the last one will be stored in profileToToken and won't affect `likeUser` or `matchRewards`.
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.