Summary
The review tracking system is fundamentally broken as the reviewCount variable is never incremented when reviews are given.
Vulnerability Details
In the giveReview function, there's a check that limits students to less than 5 reviews, but the reviewCount counter is never incremented:
function giveReview(address _student, bool review) public onlyTeacher {
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]);
}
Below is the test case that demonstrates this vulnerability:
POC (PROOF OF CONCEPT)
Add this test in the LeveOnelAndGraduateTest.t:
function testBrokenReviewCount() public schoolInSession {
vm.warp(block.timestamp + 1 weeks + 1);
vm.startPrank(alice);
levelOneProxy.giveReview(clara, true);
vm.stopPrank();
vm.warp(block.timestamp + 1 weeks + 1);
vm.startPrank(alice);
levelOneProxy.giveReview(clara, true);
vm.stopPrank();
vm.warp(block.timestamp + 1 weeks + 1);
vm.startPrank(alice);
levelOneProxy.giveReview(clara, true);
vm.stopPrank();
vm.warp(block.timestamp + 1 weeks + 1);
vm.startPrank(alice);
levelOneProxy.giveReview(clara, true);
vm.stopPrank();
vm.warp(block.timestamp + 1 weeks + 1);
vm.startPrank(alice);
levelOneProxy.giveReview(clara, true);
vm.stopPrank();
vm.warp(block.timestamp + 1 weeks + 1);
vm.startPrank(alice);
levelOneProxy.giveReview(clara, true);
vm.stopPrank();
}
As we can see we can give any amount of reviews as the reviewCountnever increases.
Impact
Review counting system is broken
Students could receive unlimited reviews, violating the "one review per week" constraint
Makes it impossible to track if students have received exactly 4 reviews
Renders the reviewCount check pointless
Tools Used
Manual code review
Recommendations
Add the missing counter increment:
function giveReview(address _student, bool review) public onlyTeacher {
if (!isStudent[_student]) {
revert HH__StudentDoesNotExist();
}
require(reviewCount[_student] < 4, "Student already has 4 reviews");
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]);
}