Hawk High

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

Incorrect Calculation of Teacher Payments in `graduateAndUpgrade` Function

Summary

In `LevelOne.sol` the graduateAndUpgrade function contains a logical error in calculating the payment for teachers. Specifically, the payPerTeacher value is calculated without dividing the total amount allocated to teachers by the number of teachers. This results in incorrect payouts where each teacher receives the entire allocated amount instead of their fair share.

Vulnerability Details

The graduateAndUpgrade function is designed to distribute payments from the bursary to both the principal and the teachers. However, the teacher payment calculation does not account for the number of teachers (totalTeachers).

Currently, the payPerTeacher variable is computed as follows:

uint256 payPerTeacher = (bursary * TEACHER_WAGE) / PRECISION;

This value represents the total amount allocated for teacher payments, but it is incorrectly interpreted as the payment per teacher. The function then distributes this amount to each teacher in the loop:

for (uint256 n = 0; n < totalTeachers; n++) {
usdc.safeTransfer(listOfTeachers[n], payPerTeacher);
}

This logic results in an overpayment to teachers, as every teacher receives the entire allocated amount instead of their share.

For example:

If bursary is 1000 USDC, TEACHER\_WAGE is 0.35 (35%), and there are 5 teachers, the intended payment per teacher should be 70 USDC. However, with the current logic, each teacher receives the full 350 USDC, leading to a total payout of 1750 USDC, exceeding the allocated bursary.

Impact

Excessive Funds Usage: The contract overpays teachers, which can deplete the bursary and disrupt the expected financial flows.

Financial Discrepancy: The principal may receive less than their allocated amount due to insufficient remaining funds.

System Instability: Repeated execution of this flawed logic may cause financial imbalance and undermine trust in the system.

Tools Used

Manual Code Review

Example-based Testing for Payment Logic

Recommendations

Update the calculation of payPerTeacher to divide the total teacher payment by the number of teachers:

uint256 totalTeacherPay = (bursary * TEACHER_WAGE) / PRECISION;
if (totalTeachers == 0) {
revert("No teachers found");
}
uint256 payPerTeacher = totalTeacherPay / totalTeachers;

Ensure proper validation for totalTeachers to avoid division by zero.

Write additional test cases to validate the correctness of payment distribution for both the principal and teachers.

Conduct a thorough review of similar payment logic in the codebase to identify any other potential issues.

Updates

Lead Judging Commences

yeahchibyke Lead Judge 3 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.