Summary
In file LevelOne.sol
function removeTeacher()
It didn't check if the current session in true
and if the teacher is the last teacher within the session.
Vulnerability Details
In the removeTeacher()
function, it missing checks if this is the last teacher available during the session is on.
function removeTeacher(address _teacher) public onlyPrincipal {
if (_teacher == address(0)) {
revert HH__ZeroAddress();
}
if (!isTeacher[_teacher]) {
revert HH__TeacherDoesNotExist();
}
uint256 teacherLength = listOfTeachers.length;
for (uint256 n = 0; n < teacherLength; n++) {
if (listOfTeachers[n] == _teacher) {
listOfTeachers[n] = listOfTeachers[teacherLength - 1];
listOfTeachers.pop();
break;
}
}
isTeacher[_teacher] = false;
emit TeacherRemoved(_teacher);
}
On the other side, there's a notYetInSession
check for the addTeacher()
function.
This is business logic issue.
function addTeacher(address _teacher) public onlyPrincipal notYetInSession {
if (_teacher == address(0)) {
revert HH__ZeroAddress();
}
if (isTeacher[_teacher]) {
revert HH__TeacherExists();
}
if (isStudent[_teacher]) {
revert HH__NotAllowed();
}
listOfTeachers.push(_teacher);
isTeacher[_teacher] = true;
emit TeacherAdded(_teacher);
}
Impact
There could be no teacher during a session is on
Proof of Concept
Add the following test into test/LeveOnelAndGraduateTest.t.sol
function test_confirm_remove_teacher_during_session() public {
vm.startPrank(principal);
levelOneProxy.addTeacher(alice);
levelOneProxy.addTeacher(bob);
levelOneProxy.startSession(70);
vm.stopPrank();
vm.startPrank(principal);
levelOneProxy.removeTeacher(alice);
levelOneProxy.removeTeacher(bob);
vm.stopPrank();
assert(levelOneProxy.getTotalTeachers() == 0);
assert(levelOneProxy.getSessionStatus() == true);
}
Tools Used
Manual review
Recommendations
Considering adding checks in removeTeacher()
function
or