Description: The LevelOne contract's expel() function contains a critical vulnerability that could render the function inoperable as the number of students increases. The function uses a linear search (O(n) complexity) through the entire listOfStudents array to locate and remove a specific student, which becomes problematic at scale due to Ethereum's block gas limitations.
Code Snippet:
Impact: This vulnerability creates a serious limitation on the contract's scalability. As the school grows beyond a certain size, the principal will lose the ability to expel students, which is a core administrative function. This effectively places an implicit cap on the number of students the system can handle, contrary to what would be expected from the contract's design.
Detailed Analysis: Each iteration of the loop requires:
Reading an address from storage (~2,100 gas)
Comparison operation (~3 gas)
Potential array manipulation operations if a match is found (~5,000+ gas)
Considering Ethereum's current block gas limit (~30M gas), the theoretical maximum number of students before the function becomes unusable is approximately 10,000 in the worst case. However, the practical limit is likely much lower when considering other operation costs in the function.
Proof of Concept:
Deploy the contract and enroll 5,000 students.
Attempt to expel a student who is at the end of the array or doesn't exist.
The transaction will fail with an "out of gas" error as the required gas exceeds the block limit.
Recommended Mitigation: Implement constant-time (O(1)) student removal by tracking the index of each student in the array:
Unbounded loops in student lists could result in high gas usage when trying to expel a students when students are plenty. This could result in a possible DoS
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.