Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Invalid

Out-of-Bounds Array Access in "onlyBeneficiaryWithIsInherited" Modifier

Summary

The onlyBeneficiaryWithIsInherited modifier contains an off-by-one error in its loop condition, which leads to an out-of-bounds array access. This can cause the contract to revert unexpectedly, preventing valid beneficiaries from executing restricted functions.

Vulnerability Details

In the following code:

modifier onlyBeneficiaryWithIsInherited() {
uint256 i = 0;
while (i < beneficiaries.length + 1) { // Incorrect condition
if (msg.sender == beneficiaries[i] && isInherited) {
break;
}
i++;
}
_;
}

The condition (i < beneficiaries.length + 1) is incorrect because:

  • THis array is zero-indexed (as i = 0), meaning the last valid index is beneficiaries.length - 1.

  • When i = beneficiaries.length, the code attempts to access beneficiaries[i], which does not exist, causing a revert due to an out-of-bounds error.

Impact

Function Execution Failure: Any function using this modifier may revert unexpectedly, preventing even valid beneficiaries from executing their transactions.

Security Risk: This issue can be exploited to intentionally block contract operations by keeping an empty beneficiary list or controlling execution flow.

Tools Used

Manual review

Recommendations

Fixed out-of-bounds error by changing while (i < beneficiaries.length + 1) to while (i < beneficiaries.length)

Updates

Lead Judging Commences

0xtimefliez Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!