In the LevelOne::graduateAndUpgrade function, the teacher wage calculation incorrectly assigns 35% of the bursary to each teacher, rather than dividing the 35% share among all teachers. This results in overpayment, potentially exceeding the available bursary, violating the invariant that teachers collectively receive 35%, the principal receives 5%, and 60% remains in the bursary after the upgrade. The issue disrupts financial integrity and could cause the upgrade to fail due to insufficient funds.
The graduateAndUpgrade function calculates teacher wages as follows:
Where TEACHER_WAGE = 35 and PRECISION = 100, this computes 35% of the bursary and assigns it to payPerTeacher. The function then transfers payPerTeacher to each teacher in a loop:
For n teachers, this results in a total payout of 35% * n of the bursary, instead of dividing the 35% share equally among teachers (i.e., 35% / n per teacher). This violates Invariant 4, which specifies the payment structure:
Principal: 5% of bursary
Teachers: 35% of bursary (shared)
Remaining: 60% in bursary after upgrade
For example, with a bursary of 1000e18 USDC and 3 teachers:
Intended: Teachers share 350e18 (35%), so each gets ~116.67e18.
Actual: Each teacher receives 350e18, totaling 1050e18 (105%), leaving insufficient funds for the principal’s 5% (50e18) and the 60% remaining (600e18).
add the following function in LevelOneIAndGraduateTest.t.sol
Overpayment to Teachers: If there are n teachers, the contract pays 35% * n of the bursary to teachers, potentially exceeding the available funds.
Bursary Depletion: The remaining bursary (intended to be 60%) is reduced or becomes negative, breaking the payment structure invariant.
Financial Loss: The contract may fail to transfer funds to LevelTwo or revert due to insufficient balance, disrupting the upgrade process.
Protocol Integrity: Incorrect payouts undermine trust in the system’s financial management.
Foundry
`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.