Summary
LevelOne::graduateAndUpgrade function lacks the session over check.Principal can call graduateAndUpgrade before the session end,conflicting with the readme.md:At the end of the school session (4 weeks), the system is upgraded to a new one.
Vulnerability Details
The session can be graduateAndUpgrade any time instead of 4 weeks.
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);
}
Tools Used
foundry
Recommendations
function graduateAndUpgrade(address _levelTwo, bytes memory) public onlyPrincipal {
//session should has been started
+ if (inSession == false) {
+ revert();
+ }
//check the time 4 weeks
+ if (sessionEnd >= block.timestamp){
+ revert();
+ }
if (_levelTwo == address(0)) {
revert HH__ZeroAddress();
}
uint256 totalTeachers = listOfTeachers.length;
//@audit the share is not right
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);
}