The LevelOne.sol::graduateAndUpgrade function incorrectly calculates the teacher fee by not incorporating the number of teachers and with the current variable assumptions it will revert when there are more than 2 teachers onboarded (with the current TEACHER_WAGE variable).
The LevelOne.sol::graduateAndUpgrade function incorrectly calculates the teacher fee by not incorporating the number of teachers. This causes the contract to pay out too much in teacher fees. Furthermore, when there are more than 2 teachers onboarded to Hawk High (assuming >= 34% TEACHER_WAGE), the function will revert due to insufficient funds. Causing unpaid wages to both the teacher and principal.
The teacher fees are calculated as follows in the LevelOne.sol::graduateAndUpgrade function:
The above function should also divide the payPerTeacher calculation by the number of teachers.
The LevelOne.sol::graduateAndUpgrade only works when there is only one teacher onboarded. When more than one teacher is onboarded then the function incorrectly calcuylate the teacher fees as it does not divide the fees by the number of teachers. This ultimately will cause the function to overpay the teacher wages and drain all the bursary when there are more than 2 teachers onboarded (with the current variables).
Impact is high as the function overpays the teacher wages and drains the bursary.
Likelihood is also high as the function will always calculate the teacher fee incorrectly when there are more than 1 teacher onboarded.
Manual review
Foundry test
Proof of Concept:
Adding the below code to the LeveOnelAndGraduateTest.t.sol file will cause the function to revert..
1. Adding the number of teachers to the calculation of the teacher fees:
By updating the graduateAndUpgrade function to calculate the teacher fees correctly, the function will no longer overpay the teacher wages. Furthermore, to be in line with Checks-Effects-Interactions, the function should update also the bursary before any external calls.
The above calculation correct the teacher wage (assuming 3 teachers):
(3e22 * 35) / 3 / 100 = 35e20
`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.