Description: The expel() function in the LevelOne contract contains an unbounded loop that iterates through the entire listOfStudents array to find and remove a specific student. As the school grows and the number of enrolled students increases, this operation will consume more gas, potentially exceeding the block gas limit and making it impossible to expel students.
Code Snippet:
Impact: If the number of enrolled students becomes too large, the principal will be unable to expel students due to gas limitations. This breaks a critical administrative function of the contract, potentially preventing the principal from enforcing school discipline or removing problematic students.
Proof of Concept:
Assume the school enrollment grows to several hundred or thousand students.
The principal attempts to expel a student who is positioned near the end of the array.
The loop must iterate through most or all students, consuming gas for each iteration.
Once the number of students is large enough, the transaction will fail with an "out of gas" error.
Recommended Mitigation: Implement a more gas-efficient method for tracking and removing students by using a mapping to track each student's index 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.