The LevelOne::graduateAndUpgrade function in the LevelOne contract incorrectly calculates teacher wages during the graduation process. While a total of 35% of the bursary is intended to be distributed among all teachers, the current implementation allocates the entire 35% to each teacher, resulting in a potential fund drain.
In the graduateAndUpgrade function, the teacher wage calculation is performed as follows:
The issue is that payPerTeacher calculates 35% of the total bursary (TEACHER_WAGE = 35, PRECISION = 100), but doesn't divide this amount by the number of teachers. Later, this amount is transferred to each teacher in a loop:
Proof Of Code
If there are multiple teachers (which is the intended use case), the contract will transfer significantly more funds than intended.
For example, with 5 teachers and a bursary of 100,000 USDC:
Expected: Each teacher receives 7,000 USDC (35,000 USDC total, 35% of bursary)
Actual: Each teacher receives 35,000 USDC (175,000 USDC total, 175% of bursary)
This could completely drain the contract funds and make graduation impossible if sufficient funds aren't available.
The error becomes more severe as more teachers are added to the system.
Manual code review
Mathematical analysis
Modify the graduateAndUpgrade function to correctly calculate the payment per teacher by dividing the total teacher allocation by the number of teachers:
Or more concisely:
Additionally, consider adding a check to prevent division by zero in case there are no teachers:
`payPerTeacher` in `graduateAndUpgrade()` is incorrectly calculated.
`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.