Hawk High

First Flight #39
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Missing Zero Address Check in giveReview Function

Summary

The giveReview function in the LevelOne contract doesn't validate that the _student parameter is not the zero address (0x0) before proceeding with operations. While there's a check for whether the address is a registered student, an explicit zero address check would provide an additional layer of validation.

Vulnerability Details

function giveReview(address _student, bool review) public onlyTeacher {
if (!isStudent[_student]) {
revert HH__StudentDoesNotExist();
}
// Zero address check missing
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]);
}

While the function includes a check that the address is a registered student (isStudent[_student]), which would typically catch zero address issues, explicit validation is a defensive programming best practice.

Impact

The vulnerability has low severity because:

  1. The existing check if (!isStudent[_student]) would likely catch any zero address inputs, as address(0) shouldn't be a registered student

  2. The function is protected by the onlyTeacher modifier, limiting who can call it

  3. No direct fund transfers occur in this function

Tools Used

manual review

Recommendations

Add an explicit zero address check at the beginning of the function:

function giveReview(address _student, bool review) public onlyTeacher {
if (_student == address(0)) {
revert HH__ZeroAddress();
}
if (!isStudent[_student]) {
revert HH__StudentDoesNotExist();
}
// Rest of the function remains the same
}

This follows the same validation pattern used in other functions in the contract and maintains code consistency.


Updates

Lead Judging Commences

yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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