The claimFaucetTokens function allows users to claim faucet tokens and, for first-time claimers, a small amount of Sepolia ETH. The function performs an external ETH transfer before updating critical state variables (lastClaimTime, dailyClaimCount, dailyDrips, hasClaimedEth), enabling a malicious contract to re-enter the function via its receive or fallback function. This can allow multiple claims before state updates occur, bypassing cooldowns and limits.
Likelihood:
Occurs when a claimant is a malicious contract with a crafted receive or fallback function that re-enters claimFaucetTokens.
Occurs during the first claim by a user, as the ETH transfer is only performed for first-time claimers.
Impact:
Malicious contract can drain the contract’s ETH balance by repeatedly claiming before dailyDrips or hasClaimedEth is updated.
Can bypass dailyClaimLimit and CLAIM_COOLDOWN, allowing excessive token claims.
Explanation: The following PoC demonstrates how a malicious contract can exploit the reentrancy vulnerability. The Attack contract calls claimFaucetTokens and, upon receiving ETH, re-enters the function multiple times before the state is updated, allowing it to claim additional tokens and ETH.
Explanation: To prevent reentrancy, we add OpenZeppelin’s ReentrancyGuard to the contract and apply the nonReentrant modifier to claimFaucetTokens. Additionally, we reorder state updates (lastClaimTime, dailyClaimCount, hasClaimedEth, dailyDrips) before the ETH transfer to follow the Checks-Effects-Interactions pattern, ensuring the state is updated before any external call.
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.