Summary
Within LevelOne
contract function graduateAndUpgrade
, the wage distribution could breaking the invariant if there's more than 1 teachers.
Vulnerability Details
In the project description, it shows 35% for the teacher wages.
But based on the function below, EVERY single teacher could get 35% of the total bursary amount.
This will leads to funds broken.
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;
uint256 principalPay = (bursary * PRINCIPAL_WAGE) / PRECISION;
_authorizeUpgrade(_levelTwo);
for (uint256 n = 0; n < totalTeachers; n++) {
usdc.safeTransfer(listOfTeachers[n], payPerTeacher);
}
usdc.safeTransfer(principal, principalPay);
}
Proof of Concept
Within test file add the following
address alice;
address bob;
address zoe;
...
function _threeteachersAdded() internal {
vm.startPrank(principal);
levelOneProxy.addTeacher(alice);
levelOneProxy.addTeacher(bob);
levelOneProxy.addTeacher(zoe);
vm.stopPrank();
}
...
function test_graduate_with_three_teachers() public {
_threeteachersAdded();
_studentsEnrolled();
vm.prank(principal);
levelOneProxy.startSession(70);
levelTwoImplementation = new LevelTwo();
levelTwoImplementationAddress = address(levelTwoImplementation);
bytes memory data = abi.encodeCall(LevelTwo.graduate, ());
vm.startPrank(principal);
vm.expectRevert();
levelOneProxy.graduateAndUpgrade(levelTwoImplementationAddress, data);
}
Run with forge test -vvvv --match-test test_graduate_with_three_teachers
forge test -vvv --match-test test_graduate_with_three_teachers
[⠊] Compiling...
No files changed, compilation skipped
Ran 1 test for test/LeveOnelAndGraduateTest.t.sol:LevelOneAndGraduateTest
[PASS] test_graduate_with_three_teachers() (gas: 1197536)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 19.00ms (1.54ms CPU time)
Ran 1 test suite in 143.21ms (19.00ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
Impact
The contract will not able to pay out the wages and not able to hold the remaining money.
Tools Used
Manual review
Recommendations
Adding checks for how many teachers are available and divide the 35% of the bursary.
Not each one gets 35%