While Hawk High follows good practices for their upgradeable contracts, such as using OpenZeppelin's reliable library, it still has major issues in it's implementation. In it's business logic of paying teachers, it has an arithmetic issue of exceeding more than 100% of the bursary which would fail due to insufficient funds.
The payment structure of the school declares that a teachers would share 35% of the bursary, but in it's logic of graduateAndUpgrade
:
This implies that each teacher receives 35% of the entire bursary, which means if the number of teachers is more than or equal to 3, then the amount to pay them would be more than 100% of the bursary, which would be impossible alongside the 5% cut for the school's principal.
One can verify that this indeed is what occurs, by adding another teacher to the existing list of two teachers in the foundry test suite:
When one runs this with forge test
one gets:
Critical
git
foundry
slither
The appropriate way to handle this bug is to not provide 35% of the entire bursary to each teacher, instead to distributeit proporationally so that all the teachers cumulatively constitute 35% of the bursary. This is in accordance with the payment structure that says:
teachers
share of 35% of bursary
To make this change, one needs to simply divide by the total number of teachers, so the logic in graduateAndUpgrade
changes to:
This splits the 35% of the bursary equally among all the teachers, and ensures that the total payments made to the teachers never exceeds the limit of 35% of bursary.
`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.