Hawk High

First Flight #39
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Valid

Review count not update on LevelOne::giveReview

Summary

The function LevelOne::giveReview validates the number of reviews a student has received but it does not update the review count after a review is given. This means that students can keep receiving reviews.

Vulnerability Details

The missing update of the review count is located in the LevelOne::giveReview function.

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");
// where `false` is a bad review and true is a good review
if (!review) {
studentScore[_student] -= 10;
}
// Update last review time
lastReviewTime[_student] = block.timestamp;
emit ReviewGiven(_student, review, studentScore[_student]);
}

Impact

Since there is no update of the review count, students can keep receiving reviews. This can lead to students receiving more than 4 reviews in one school session. This is a violation of the documentation and can lead to unexpected results. (There is an other vulnerability that allows students to receive 5 reviews in one school session, I discribed it in a other finding)

Tools Used

Manually reviewed the code and the documentation.

Recommendations

The review count should be updated after a review is given. This can be done by adding the following line of code after the review is given:

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");
// where `false` is a bad review and true is a good review
if (!review) {
studentScore[_student] -= 10;
}
+ // Update review count
+ reviewCount[_student] += 1;
// Update last review time
lastReviewTime[_student] = block.timestamp;
emit ReviewGiven(_student, review, studentScore[_student]);
}
Updates

Lead Judging Commences

yeahchibyke Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

reviewCount not updated

`reviewCount` for students is not updated after each review session

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.