Description:
The graduateAndUpgrade() function in the LevelOne contract contains a critical flaw that causes the function to revert when no teachers exist in the system. The function calculates payPerTeacher by dividing a portion of the bursary by the total number of teachers (totalTeachers). However, if listOfTeachers.length is zero, this calculation will cause a division by zero error, reverting the entire transaction and preventing both the contract upgrade and principal payment distribution.
Code Snippet:
Impact: This vulnerability creates a situation where the contract becomes permanently locked in its current implementation if all teachers are removed. This would:
Prevent contract upgrades, blocking critical improvements or bugfixes
Lock the principal's payment in the contract
Freeze the remaining bursary funds indefinitely
Force the school system to remain in its current state without possibility for advancement
Proof of Concept:
The principal removes all teachers using the removeTeacher() function
The principal attempts to call graduateAndUpgrade() with a valid new implementation address
The transaction reverts with a "division by zero" error when executing the for loop
The principal cannot receive their payment, and the contract upgrade fails
Recommended Mitigation: Add a check to handle the zero-teacher case separately:
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.