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

Intentional array out-of-bounds error used for access control causes excessive gas consumption

Description:

The InheritanceManager contract uses an unconventional and unsafe method for access control in the onlyBeneficiaryWithIsInherited modifier. Instead of using standard require statements with clear error messages, the modifier intentionally allows the execution to go out of bounds of the beneficiaries array to trigger a Panic error if the caller is not authorized.

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

The condition i < beneficiaries.length + 1 deliberately allows the loop to attempt accessing an element beyond the array bounds, which will trigger a Panic error (0x32 - Array access out of bounds).

Impact:

When a non-beneficiary calls a function with this modifier, the transaction will revert with a Panic error, which consumes all the gas allocated to the transaction. This is significantly worse than a standard require statement which returns unused gas.

Users who accidentally call restricted functions will pay maximum gas fees for failed transactions.

The error message "Panic(0x32)" is cryptic and does not communicate to the user why their transaction failed, making debugging difficult.

Recommended Mitigation:

Replace the current implementation with a standard, explicit access control mechanism:

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

Lead Judging Commences

0xtimefliez Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
0xtimefliez Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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