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

onlyBeneficiaryWithIsInherited Modifier Out-of-Bounds

Summary

The onlyBeneficiaryWithIsInherited modifier in the InheritanceManager contract contains an out-of-bounds error, which causes transactions to revert unexpectedly when executed by a non-beneficiary. This issue prevents intended contract functionality and can disrupt inheritance transfers.

Vulnerability Details

modifier onlyBeneficiaryWithIsInherited() {
uint256 i = 0;
while (i < beneficiaries.length + 1) { // ❌ Out-of-bounds risk
if (msg.sender == beneficiaries[i] && isInherited) {
break;
}
i++;
}
_;
}
  • beneficiaries.length + 1 exceeds the array bounds, meaning if no match is found before the last iteration, it will cause an out-of-bounds error and revert the transaction.

  • Expected Behavior: The loop should iterate up to beneficiaries.length - 1.

  • Actual Behavior: The loop goes beyond the array size, triggering a "Panic: Index out of bounds" error.

Impact

  • The modifier loops through the beneficiaries array incorrectly using beneficiaries.length + 1.

  • This always causes an "index out of bounds" error when msg.sender is not a beneficiary.

  • As a result, valid function calls will fail, and no beneficiaries will be able to execute inheritance-related functions.

Tools Used

Manual Code

Recommendations

Fix the Modifier by Correcting the Loop Condition

while (i < beneficiaries.length) {

Safer Alternative: Use for Loop Instead

modifier onlyBeneficiaryWithIsInherited() {
bool isAllowed = false;
for (uint256 i = 0; i < beneficiaries.length; i++) {
if (msg.sender == beneficiaries[i] && isInherited) {
isAllowed = true;
break;
}
}
require(isAllowed, "Not a beneficiary or inheritance not active");
_;
}
Updates

Lead Judging Commences

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

Support

FAQs

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