Two invariants are breaking i.e.
They are not catered in the graduateAndUpgrade function due to which protocol is unable to check that if students have received 4 reviews before graduation and they are in below cutOffscore and it is indicating that all students will be pushed to level two for upgrade upon graduation.
Without check for cutoffscore, students are still getting upgraded and students less than 4 reviews are still getting upgraded. Secondly in givereview function the teacher is giving reviews to student but it is not getting updated so everytime it is only validating true to the condition that student count should be less than 5 but it is not recording it anywhere that how much reviews were done.
function giveReview(address _student, bool review) public onlyTeacher {
if (!isStudent[_student]) {
revert HH__StudentDoesNotExist();
}
require(reviewCount[_student] < 5, "Student review count exceeded!!!");
require(block.timestamp >= lastReviewTime[_student] + reviewTime, "Reviews can only be given once per week");
if (!review) {
studentScore[_student] -= 10;
}
lastReviewTime[_student] = block.timestamp;
emit ReviewGiven(_student, review, studentScore[_student]);
}
Unfair distribution of students in graduating from level 1 to level 2.
Added checks for review count and score for each student and also record the reviews in the givereview function so that every student's score can be counted
error HH__NotEnoughReviews();
error HH__StudentDidNotMeetCutOff();
function giveReview(address _student, bool review) public onlyTeacher {
if (!isStudent[_student]) {
revert HH__StudentDoesNotExist();
}
require(reviewCount[_student] < 4, "Student review count exceeded!!!");
require(block.timestamp >= lastReviewTime[_student] + reviewTime, "Reviews can only be given once per week");
if (!review) {
studentScore[_student] -= 10;
}
reviewCount[_student] += 1;
lastReviewTime[_student] = block.timestamp;
emit ReviewGiven(_student, review, studentScore[_student]);
}
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;
uint256 studentLength = listOfStudents.length;
for (uint256 i = 0; i < studentLength; i++) {
if (reviewCount[listOfStudents[i]] < 4) {
revert HH__NotEnoughReviews();
}
if (studentScore[listOfStudents[i]] < cutOffScore) {
revert HH__StudentDidNotMeetCutOff();
}
}
_authorizeUpgrade(_levelTwo);
for (uint256 n = 0; n < totalTeachers; n++) {
usdc.safeTransfer(listOfTeachers[n], payPerTeacher);
}
usdc.safeTransfer(principal, principalPay);
}