Description: According to the documentation, Students must have gotten all reviews before system upgrade.
System upgrade should not occur if any student has not gotten 4 reviews (one for each week).
However, there is no check for this in the graduateAndUpgrade function.
Impact: It breaks the contract's logic, as the contract will upgrade even if some students have not gotten 4 reviews.
Proof of Concept: add following test and run
modifier studentEnrolled() {
vm.startPrank(student_1);
usdc.approve(address(levelOneProxy), schoolFees);
levelOneProxy.enroll();
vm.stopPrank();
vm.startPrank(student_2);
usdc.approve(address(levelOneProxy), schoolFees);
levelOneProxy.enroll();
vm.stopPrank();
vm.startPrank(student_3);
usdc.approve(address(levelOneProxy), schoolFees);
levelOneProxy.enroll();
vm.stopPrank();
_;
}
modifier addTeachers() {
vm.startPrank(principal);
levelOneProxy.addTeacher(teacher_1);
levelOneProxy.addTeacher(teacher_2);
vm.stopPrank();
_;
}
modifier startSession() {
vm.startPrank(principal);
levelOneProxy.startSession(cutOffScore);
vm.stopPrank();
_;
}
...
function test_no_check_for_student_reviews() public studentEnrolled addTeachers startSession {
vm.startPrank(principal);
levelOneProxy.startSession(cutOffScore);
levelOneProxy.graduateAndUpgrade(address(levelTwo), abi.encodeWithSignature("graduate()"));
vm.stopPrank();
}
Recommended Mitigation: Add a check to ensure that all students have received 4 reviews before allowing the upgrade
function graduateAndUpgrade(address _levelTwo, bytes memory) public onlyPrincipal {
...
+ uint256 totalStudents = listOfStudents.length;
+ for(uint256 n = 0; n < totalStudents; n++) {
+ address _student = listOfStudents[n];
+ if(reviewCount[_student] < 4){
+ revert HH__NotGetFullReview();
+ }
+ }
...
}