The enroll function in Session1.sol performs external interactions before updating the contract’s internal state, violating the Checks-Effects-Interactions (CEI) pattern. This could potentially open up the function to reentrancy-like issues and lead to inconsistent state.
The enroll function is implemented as follows:
This function first performs an external call to usdc.safeTransferFrom, and only after that updates critical internal state variables such as isStudent, listOfStudents, and studentScore.
If the usdc contract is malicious or contains a callback mechanism, it could re-enter the enroll function before the internal state has been updated. Since the student isn’t marked as enrolled yet, the second call could succeed again, leading to:
Duplicate entries in listOfStudents
Unintended financial or logical behavior when managing students (e.g., during expulsion)
While this may not be exploitable in the current setup, following the CEI pattern is a critical best practice to mitigate similar risks and ensure robust contract logic.
Data Inconsistency: Duplicate entries in listOfStudents with conflicting isStudent values
Potential Reentrancy Risk: Reentrancy vector enabled via external usdc call
Logical Vulnerabilities: Unexpected behavior during expulsion or reward logic
Manual Code Review
Refactor the function to follow the Checks-Effects-Interactions pattern:
Perform all checks first.
Update internal state.
Then perform external interactions.
Emit events last.
Proposed Fix:
This ensures state consistency even if the external call behaves unexpectedly.
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.