According to the invariants, 60% of the bursary should remain after upgrade. However, there is no mechanism to ensure this happens. The contract distributes 35% to teachers and 5% to the principal but doesn't update the bursary value or transfer the remaining funds to the new implementation.
function graduateAndUpgrade(address _levelTwo, bytes memory data) public onlyPrincipal {
if (_levelTwo == address(0)) {
revert HH__ZeroAddress();
}
if (block.timestamp < sessionEnd) {
revert("Session has not ended yet");
}
for (uint256 i = 0; i < listOfStudents.length; i++) {
if (reviewCount[listOfStudents[i]] != 4) {
revert("Not all students have received 4 reviews");
}
}
for (uint256 i = 0; i < listOfStudents.length; i++) {
if (studentScore[listOfStudents[i]] < cutOffScore) {
listOfStudents[i] = listOfStudents[listOfStudents.length - 1];
listOfStudents.pop();
i--;
}
}
uint256 totalTeachers = listOfTeachers.length;
uint256 totalTeacherPay = (bursary * TEACHER_WAGE) / PRECISION;
uint256 principalPay = (bursary * PRINCIPAL_WAGE) / PRECISION;
uint256 remainingBursary = bursary - totalTeacherPay - principalPay;
bursary = remainingBursary;
if (totalTeachers > 0) {
uint256 payPerTeacher = totalTeacherPay / totalTeachers;
for (uint256 n = 0; n < totalTeachers; n++) {
usdc.safeTransfer(listOfTeachers[n], payPerTeacher);
}
}
usdc.safeTransfer(principal, principalPay);
_authorizeUpgrade(_levelTwo);
emit Graduated(_levelTwo);
}