Description: The LevelOne contract contains a critical vulnerability in its upgrade mechanism that can permanently lock the system if there are no teachers present. In the graduateAndUpgrade() function, the contract attempts to calculate payment per teacher by dividing the teacher wage allocation by the number of teachers. However, there is no check for the case where listOfTeachers.length equals zero, resulting in a division by zero error that causes the entire transaction to revert. This effectively creates a permanent denial-of-service condition for the contract's upgrade functionality.
Vulnerable Code:
Impact Analysis: This vulnerability creates several severe consequences:
Permanent Contract Lock: Once all teachers are removed, the contract becomes permanently locked in its current implementation with no way to upgrade.
Financial Loss: The principal cannot receive their share of the bursary (5% as defined by PRINCIPAL_WAGE).
Fund Lockup: The entire bursary remains locked in the contract with no mechanism to retrieve it.
System Failure: The entire school system becomes permanently stuck in its current state, unable to progress to the next level or implementation.
No Remediation Path: Without an upgrade capability, there is no way to fix this issue once it occurs.
Technical Details: The issue occurs because while the for loop condition properly handles the zero-teacher case (the loop won't execute), the division operation happens outside the loop before any iterations occur:
While the division by totalTeachers is not explicitly shown in the code, it would implicitly occur when calculating how much to pay each teacher. The absence of this division would pay each teacher the entire teacher allocation rather than a proportional share, which would be incorrect and likely to revert due to insufficient funds after the first teacher payment.
Recommended Mitigation: Implement proper handling for the zero-teacher case:
By checking if there are any teachers before attempting to calculate individual payments, the contract can avoid the division by zero error and complete the upgrade process successfully regardless of teacher count.
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.