Hawk High

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

Incorrect Teacher Payment Calculation in `graduateAndUpgrade` Function

Summary

The graduateAndUpgrade function in LevelOne.sol incorrectly calculates teacher payments, attempting to pay each teacher 35% of the bursary instead of dividing the 35% share among all teachers, potentially leading to excessive payouts and depletion of the protocol's funds.

Vulnerability Details

According to the project invariants, teachers should collectively receive 35% of the bursary as their wages, shared among all teachers. However, in the graduateAndUpgrade function, the payment per teacher is calculated as:

uint256 payPerTeacher = (bursary * TEACHER_WAGE) / PRECISION;

where TEACHER_WAGE = 35 and PRECISION = 100, meaning each teacher is paid 35% of the entire bursary. The function then transfers this amount to each teacher in a loop:

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

This results in a total payout of 35% * totalTeachers, which could far exceed the intended 35% allocation. For example, with 5 teachers, the function attempts to pay 175% of the bursary, violating the invariant and risking depletion of funds.

Impact

  • Impact: High
    This vulnerability directly puts funds at risk, as it can lead to excessive payouts that deplete the bursary, potentially causing the transaction to revert or leaving insufficient funds for the principal's 5% wage and the 60% reserve for LevelTwo. This severely disrupts the protocol's financial integrity and functionality.

  • Likelihood: High
    Exploitation is straightforward and automatic whenever graduateAndUpgrade is called with multiple teachers, as the incorrect calculation is embedded in the function's logic. No malicious intent is required, making it highly likely to occur during normal operation.

Tools Used

  • Manual code analysis

Recommendations

Correct the teacher payment calculation to divide the 35% share among all teachers. Suggested code modification:

function graduateAndUpgrade(address _levelTwo, bytes memory) public onlyPrincipal {
if (_levelTwo == address(0)) {
revert HH__ZeroAddress();
}
uint256 totalTeachers = listOfTeachers.length;
uint256 payPerTeacher = totalTeachers > 0 ? (bursary * TEACHER_WAGE) / PRECISION / totalTeachers : 0;
uint256 principalPay = (bursary * PRINCIPAL_WAGE) / PRECISION;
_authorizeUpgrade(_levelTwo);
for (uint256 n = 0; n < totalTeachers; n++) {
usdc.safeTransfer(listOfTeachers[n], payPerTeacher);
}
usdc.safeTransfer(principal, principalPay);
}

This ensures the total teacher payout equals 35% of the bursary, divided equally among all teachers, and prevents excessive fund transfers.

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.