The graduateAndUpgrade function in the LevelOne contract incorrectly calculates and distributes payments to teachers. Instead of sharing 35% of the bursary among all teachers, the current implementation gives each teacher 35% of the total bursary, causing the transaction to revert when there are multiple teachers due to insufficient funds.
The payment distribution logic in the graduateAndUpgrade function incorrectly calculates teacher payments:
In the LevelOne contract, the teacher payment calculation is implemented as follows:
The problem here is that each teacher receives (bursary * TEACHER_WAGE) / PRECISION tokens, which means each teacher gets 35% of the bursary. If there are multiple teachers, this will distribute much more than the intended 35% total allocation for teachers.
For example, if there are 3 teachers, the function will attempt to pay out 105% (3 × 35%) of the bursary just to teachers, which is clearly incorrect and will cause the function to revert due to insufficient funds.
The correct implementation should be dividing the total teacher allocation among all teachers:
This issue has severe consequences for the contract functionality:
The function will revert if there are more than 2 teachers due to insufficient funds (with 3 teachers, it would try to pay 105% of the bursary just to teachers)
With a large number of teachers, the transaction will almost certainly fail due to insufficient funds
The contract fails to meet its core invariant regarding teacher payment distribution
Manual code review
Modify the graduateAndUpgrade function to correctly calculate the payment per teacher by first calculating the total amount for all teachers and then dividing it equally. Also handle the case where there are no teachers:
This implementation ensures that the 35% allocation for teachers is correctly shared among all teachers, with each teacher receiving an equal portion of the total teacher allocation, and also handles the case where there are no teachers by keeping their allocation in the contract.
`payPerTeacher` in `graduateAndUpgrade()` is incorrectly calculated.
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.