In Hawk High, due to not having a limit on the maximum number of employed teachers, the LevelOne::removeTeacher
function is a potential vector for Denial of Service either running out of gas or becoming infeasible to remove a teacher 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::removeTeacher
function.
The Code Issue
The LevelOne:removeTeacher
function is used by the Principal to remove a teacher from Hawk High employment. The function iterates over a for loop that is unbounded. It is unbounded because there is no set maximum limit to the number of teachers that can be employed at Hawk High.
Therefore, for a large number of employed teachers, it becomes gas expensive for the Principal to remove a teacher, especially if the teacher is indexed at the end of the listOfTeachers
array.
When there are many teachers enrolled, the function may either
consume all gas when run causing a Denial of service,
become unfeasible to remove a teacher due to high gas cost
In either case, the intended functionality is broken.
Affected Code
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 remove a teacher from the employment and salary structure in a feasible manner.
When there are many teachers enrolled, the function may:
consume all gas when run causing a Denial of service, failing to remove a teacher. A teacher may still get paid even though they are not employed and still use teacher related functions in the contract.
become unfeasible to remove a teacher due to high gas costs causing the same above issues.
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 teachers employed (10), while the second instance has a larger number of employed teachers students (500). The gas expense of removing a teacher from each are compared to show that it is more expensive to remove a teacher when more are employed.
Note: if multiple teachers are to be expelled, this is an even more gas expensive operation.
Running: forge test --mt testPotentialDoSOnRemovingTeachers -vvv
Code
A recommended mitigation to this, is to set a reasonable maximum limit to the number of employed teachers. For flexibility, the principal can adjust the number of allowed teachers depending on supply and demand.
Unbounded loops in teacher lists could result in high gas usage when trying to remove a teacher when teachers 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.