Hawk High

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

Teacher Wages Distribution issue

Vunlerability Details

The current implementation of graduateAndUpgrade incorrectly distributes 35% of the bursary to each teacher, rather than splitting 35% among all teachers. This causes the total payout to exceed 100% of the bursary, resulting in a failure due to insufficient funds.

Proof Of Concept

function test_Teacher_Wages_Distribution_Is_Wrong() public {
// Initializing new Teacher
address jack = makeAddr("Third_teacher");
// Adding Teachers
_teachersAdded();
vm.prank(principal);
levelOneProxy.addTeacher(jack);
// Adding Students
_studentsEnrolled();
// Starting A session
vm.prank(principal);
levelOneProxy.startSession(70);
// Assert that jack is added as a teacher
assertEq(levelOneProxy.getTotalTeachers(),3);
// Upgrading and Distributing wages
levelTwoImplementation = new LevelTwo();
levelTwoImplementationAddress = address(levelTwoImplementation);
bytes memory data = abi.encodeCall(LevelTwo.graduate, ());
vm.startPrank(principal);
// This will revert as contract give each teacher 35% and we have 3 teachers
// 35% * 3 = 105% so it will revert with insufficient funds error
vm.expectRevert();
levelOneProxy.graduateAndUpgrade(levelTwoImplementationAddress, data);
}

Recommendation

  • Transfer payPerTeacher instead of totalTeacherShare

uint256 totalTeacherShare = (bursary * TEACHER_WAGE) / PRECISION;
uint256 payPerTeacher = totalTeacherShare / listOfTeachers.length;
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.