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

Out-of-Bounds Access Risk in `InheritanceManager::onlyBeneficiaryWithIsInherited` Modifier Due to Unbounded Loop

Summary

The InheritanceManager::onlyBeneficiaryWithIsInherited modifier uses an unbounded loop that iterates beyond the beneficiaries array bounds, risking out-of-bounds access, transaction reverts, and gas inefficiency. This introduces vulnerabilities in access control logic and exposes the contract to denial-of-service (DoS) attacks via gas exhaustion.

Vulnerability Details

The modifier’s while loop runs beneficiaries.length + 1 times, attempting to access beneficiaries[i] when i = beneficiaries.length. Since Solidity arrays are zero-indexed, this guarantees an out-of-bounds exception, causing the transaction to revert.

Additionally, looping over a dynamic-length array in modifiers is inherently gas-inefficient and risky, as large beneficiaries arrays could cause gas limits to be exceeded.

Impact

Medium Severity

Guaranteed Reverts: Transactions using this modifier will revert due to out-of-bounds access, breaking core functionality.

Access Control Bypass: If the loop is intended to validate msg.sender, legitimate beneficiaries may be denied access.

Gas Exhaustion: Unbounded loops waste gas and could lead to DoS during high network congestion.

Tools Used

Manual code review

Recommendations

Change the loop condition to i < beneficiaries.length to prevent out-of-bounds access:

while (i < beneficiaries.length) { ... }

Split the isInherited check from beneficiary validation to simplify logic:

modifier onlyBeneficiaryWithIsInherited() {
require(isInherited, "Inheritance not active");
require(isBeneficiary[msg.sender], "Unauthorized");
_;
}

Replace array iteration with a mapping for efficient beneficiary checks:

mapping(address => bool) public isBeneficiary;
modifier onlyBeneficiaryWithIsInherited() {
require(isBeneficiary[msg.sender] && isInherited, "Unauthorized");
_;
}

These changes eliminate the vulnerability while improving code readability and gas efficiency.

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!