The enroll()
function in the LevelOne
contract is vulnerable to reentrancy attacks due to unsafe interaction with an external token contract safeTransferFrom
before updating state variables. An attacker can reenter the function during the token transfer callback, potentially manipulating contract state or enrolling multiple times with a single payment.
The enroll()
function does not follow the Checks-Effects-Interactions (CEI) pattern by performing an external call usdc.safeTransferFrom(msg.sender, address(this), schoolFees)
before updating state variables ```listOfStudents, isStudent, studentScore etc.).
Attack Scenario:
i. Attacker Deploys Malicious Token:
A malicious ERC20 token triggers a reentrant call to enroll()
during safeTransferFrom.
ii. Reentrancy Execution:
First Call: enroll() → safeTransferFrom → Malicious token callback → enroll() again.
Second Call: Processes another enrollment before the first call updates state.
iii. Result:
Attacker enrolls twice while only paying once.
Bursary accounting is corrupted (under-counts fees).
Attackers can bypass fees or exhaust student slots.
If the contract held ETH/ERC20s, reentrancy could drain funds.
Bursary and studentScore may become inconsistent.
Foundry
VS Code
Apply the Checks-Effects-Interactions pattern by uisng safeTransferFrom
Last
Use OpenZeppelin’s ReentrancyGuard
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.