Hawk High

First Flight #39
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Not following CEI in `LevelOne::enroll` pattern allows for reentrancy

Summary

The LevelOne contract does not follow the Checks-Effects-Interactions (CEI) pattern, which can lead to reentrancy vulnerabilities. The issue is not direct threat, but it is a good practice to follow the CEI pattern to prevent potential reentrancy attacks.

function enroll() external notYetInSession {
if (isTeacher[msg.sender] || msg.sender == principal) {
revert HH__NotAllowed();
}
if (isStudent[msg.sender]) {
revert HH__StudentExists();
}
@> usdc.safeTransferFrom(msg.sender, address(this), schoolFees);
listOfStudents.push(msg.sender);
isStudent[msg.sender] = true;
studentScore[msg.sender] = 100;
bursary += schoolFees;
emit Enrolled(msg.sender);
}

Impact

A malicious contract could re-enter the LevelOne contract during a function call.

Tools Used

Manual review.

Recommendations

Refactor the LevelOne::enroll function to follow the CEI pattern. Ensure that all state updates are performed before any external calls.

Updates

Lead Judging Commences

yeahchibyke Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!