Description: The LevelOne contract implements an inefficient mechanism for removing teachers that can lead to denial of service. The removeTeacher() function requires linear time complexity O(n) to find and remove a teacher from the listOfTeachers array, where n is the total number of teachers. As this list grows, the gas cost increases proportionally, creating a condition where the function may become unusable due to exceeding block gas limits.
Code Snippet:
Impact: The current implementation creates a critical vulnerability where the contract could reach a state in which teacher management operations become impossible. If the principal cannot remove teachers, this limits the contract's administrative flexibility and potentially blocks necessary organization changes. This issue could be exploited by a malicious principal who adds many teachers to make the system unmanageable.
Detailed Analysis: Each iteration of the loop requires:
Reading an address from storage (~2,100 gas per read)
Comparison operation (~3 gas)
If a match is found, write operations (~5,000 gas)
With Ethereum's current block gas limit of approximately 30 million gas, this function would fail with roughly 10,000+ teachers in the worst case. However, practical limitations would be lower due to other operations in the function.
Recommended Mitigation:
Implement a mapping-based index tracking system to achieve O(1) removal operations.
Consider implementing batch operations for managing multiple teachers.
Add administrative functions to handle system recovery if the list becomes too large.
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.