Hawk High

First Flight #39
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Valid

Incorrect Teacher Payment Calculation Leads to Overpayment

Summary

The system's logic for calculating teacher payments is flawed, leading to significant overpayment and breaking the intended bursary distribution invariant.

Vulnerability Details

In the graduateAndUpgrade() function, the calculation for payPerTeacher incorrectly determines the amount paid to each teacher. Instead of dividing the total amount allocated for all teachers (35% of the bursary) by the number of teachers, the current formula effectively calculates 35% of the total bursary for each teacher individually.

Impact

This vulnerability has a severe financial impact:

  • Massive Overpayment: The total amount paid to teachers will be totalTeachers * 35% of bursary. If there is more than one teacher (totalTeachers > 1), this will significantly exceed the intended 35% allocation and could even exceed the total bursary amount, leading to contract insolvency or unexpected behavior if transfers fail.

  • Invariant Violation: The core invariant that 35% of the bursary is allocated to all teachers is violated.

  • Financial Loss: The contract's funds are drained much faster than intended, potentially impacting future operations or other planned distributions (like the 5% for the principal).

Tools Used

Recommendations

The calculation for payPerTeacher should be corrected to divide the total allocated amount for teachers by the number of teachers. This ensures that the 35% of the bursary is distributed among all teachers, not paid to each teacher individually.

function graduateAndUpgrade(address _levelTwo, bytes memory) public onlyPrincipal {
if (_levelTwo == address(0)) {
revert HH__ZeroAddress();
}
uint256 totalTeachers = listOfTeachers.length;
- uint256 payPerTeacher = (bursary * TEACHER_WAGE) / PRECISION; //@audit missing totalTeachers division
+ uint256 payPerTeacher = (bursary * TEACHER_WAGE) / PRECISION / totalTeachers;
uint256 principalPay = (bursary * PRINCIPAL_WAGE) / PRECISION;
_authorizeUpgrade(_levelTwo);
// ..skip
}
Updates

Lead Judging Commences

yeahchibyke Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

incorrect teacher pay calculation

`payPerTeacher` in `graduateAndUpgrade()` is incorrectly calculated.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.