Hawk High

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

`reviewCount` mapping value is not updated in the `giveReview()` function after review has been given.

Summary

reviewCount mapping value is not updated in the giveReview() function after review has been given. The value is supposed to be increased by 1 after every successful review weekly and should be 4 by the end of the session but the value is not recorded in the mapping reviewCountand therefore all students' reviewcount remains 0.

Vulnerability Details

As the Value of reviewCountis not updated after giving review, it remains 0 and the system upgrade cannot occur because students must have their 4 reviews, one for each week, before System upgrade occur therefore breaking the protocol's invariant.

Impact

The system upgrade cannot happen as the reviewCountis not increased and students must have 4 reviews before the upgrade can occur.

poc

The test below passes and proves that the review count is not updated for the students after the teacher has given them a review. it remains 0 before and after the review therefore breaking our invariant.

function test_reviewCountDoesNotUpdate_poc() public {
_teachersAdded();
_studentsEnrolled();
vm.startPrank(principal);
levelOneProxy.startSession(70);
vm.stopPrank();
vm.warp(block.timestamp + 1 weeks);
uint256 reviewCountBefore = levelOneProxy.getReviewCount(harriet);
console2.log("Review count before review:", reviewCountBefore);
vm.startPrank(bob);
levelOneProxy.giveReview(harriet, false);
vm.stopPrank();
uint256 reviewCountAfter = levelOneProxy.getReviewCount(harriet);
console2.log("Review count after review:", reviewCountAfter);
assert(reviewCountAfter != reviewCountBefore + 1);
assert(reviewCountAfter == reviewCountBefore);
}

Tools Used

Manual review

Recommendations

Increase the reviewCountof each student that is given a review by adding the lines of code in the giveReview()function as shown below;

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;
}
+ // Increase the review count by 1
+ reviewCount[_student] += 1;
// Update last review time
lastReviewTime[_student] = block.timestamp;
emit ReviewGiven(_student, review, studentScore[_student]);
}
Updates

Lead Judging Commences

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

reviewCount not updated

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

yeahchibyke Lead Judge 3 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.