The mintProfile
function in the SoulboundProfileNFT
contract is vulnerable to reentrancy attacks due to the incorrect order of operations. The function makes an external call to _safeMint
before updating state variables, which allows a malicious contract to re-enter and potentially manipulate the contract's state before the minting process is finalized.
The vulnerability arises because _safeMint
is an external call that interacts with msg.sender
, which could be a malicious smart contract. If msg.sender
is a contract with a fallback function, it can re-enter mintProfile
or other functions before profileToToken[msg.sender]
is updated.
Vulnerability code:
Exploit Scenario:
Attacker deploys a malicious contract that has a fallback function capable of calling mintProfile
again before state changes take effect.
The attacker calls mintProfile()
, and _safeMint(msg.sender, tokenId)
triggers the attacker’s fallback function.
The fallback function re-enters mintProfile
, minting multiple NFTs before profileToToken[msg.sender]
is set.
The attacker obtains multiple profiles despite the require(profileToToken[msg.sender] == 0)
check.
PoC:
Medium Severity: A malicious user can bypass the one-profile-per-user restriction and mint multiple profiles.
Data Corruption: The _profiles mapping can be corrupted, linking multiple token IDs to a single msg.sender.
Protocol Integrity Compromise: The immutability and uniqueness of soulbound profiles are undermined.
Slither (for automated detection)
Manual Review (to verify exploitability)
To prevent reentrancy, the contract should follow the Checks-Effects-Interactions pattern, ensuring that state changes occur before external calls.
Use Reentrancy Guards (nonReentrant)
from OpenZeppelin's ReentrancyGuard.
Emit an event before making external calls to improve transparency.
Perform additional validation on msg.sender
if required.
By implementing these fixes, the mintProfile
function will be protected against reentrancy attacks, ensuring the integrity of the soulbound profile system.
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.