Summary
The reviewCount is not incremented in the giveReview function.
Vulnerability Details
In the code below after a student is given a review, the reviewCount is never updated.
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]);
}
Impact
The conditions to gradaute and upgrade will never be met since no student has the requirement amount of reviews.
Tools Used
Manual review
Recommendations
In the code below I have added reviewCount[_student]++; which will increment the number of reviews after a successful review.
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;
reviewCount[_student]++;
emit ReviewGiven(_student, review, studentScore[_student]);
}