In Hawk High, due to not having a limit on the maximum number of students, the LevelOne::expel
function is a potential vector for Denial of Service either running out of gas or becoming infeasible to remove a student due to gas cost.
The Hawk High LevelOne
contract is potentially vulnerable to a Denial of Service attack via an unbounded array in the LevelOne::expel
function.
The Code Issue
The LevelOne:expel
function is used by the Principal to remove a student from Hawk High. The function iterates over a for loop that is unbounded. It is unbounded because there is no set maximum limit to the number of students that can enroll at Hawk High.
Therefore, for a large number of enrolled students, it becomes gas expensive for the Principal to remove a student, especially if the student is indexed at the end of the listOfStudents
array. If there are many students enrolled, the function may
consume all gas when run causing a Denial of service,
become unfeasible to expel a student due to high gas cost
In either case, the intended functionality is broken.
Affected Code Area
The severity of this bug is Medium as there is no impact to any funds, directly or indirectly. However, it breaks the expected functionality of being able to expel a student in a feasible manner.
When there are many students enrolled, the function may:
consume all gas when run causing a Denial of service, failing to expel the student
become unfeasible to expel a student as it is expensive
Manual Review
Foundry
Description
I have created a runnable Proof-of-Concept that deploys two instances of Hawk High - Level One. One instance has a few students enrolled (30), while the second instance has a larger number of enrolled students (3000). The gas expense of expelling a student from each are compared to show that it is more expensive to expel a student when more are enrolled.
Note: if multiple students are to be expelled, this is an even more gas expensive operation.
Running: forge test --mt testPotentialDoSonExpelingStudents -vvv
Code
A recommended mitigation to this, is to set a reasonable maximum limit to the number of enrolled students.
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.