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

Uninitialized Return Value in InheritanceManager::_getBeneficiaryIndex Leads to Incorrect Beneficiary Removal

Summary

The _getBeneficiaryIndex function in the InheritanceManager contract fails to handle the case where a beneficiary does not exist in the beneficiaries array. If the beneficiary is not found, it implicitly returns 0 due to Solidity’s default behavior for uninitialized variables, which can lead to the incorrect removal of the beneficiary at index 0 in the removeBeneficiary function.

Vulnerability Details

f the _beneficiary address is not found in the beneficiaries array, the loop completes without assigning a value to _index. In Solidity, uninitialized local variables default to 0. As a result, the function returns 0 even when the beneficiary does not exist.

This function is called by removeBeneficiary:

function removeBeneficiary(address _beneficiary) external onlyOwner {
uint256 indexToRemove = _getBeneficiaryIndex(_beneficiary);
delete beneficiaries[indexToRemove];
}

When _getBeneficiaryIndex returns 0 for a non-existent beneficiary, delete beneficiaries[0] removes the first beneficiary in the array, regardless of whether it matches the intended _beneficiary.

Impact

f the owner attempts to remove a non-existent beneficiary, the contract will mistakenly delete the beneficiary at index 0. This could lead to unintended loss of inheritance rights for a legitimate beneficiary.

Tools Used

Manual code review

Recommendations

Modify _getBeneficiaryIndex to explicitly check if the beneficiary exists and revert if it does not, preventing unintended behavior in removeBeneficiary.

function _getBeneficiaryIndex(address _beneficiary) public view returns (uint256 _index) {
for (uint256 i = 0; i < beneficiaries.length; i++) {
if (_beneficiary == beneficiaries[i]) {
_index = i;
+ return _index;
}
}
+ revert("Beneficiary not found");
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
0xtimefliez Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Appeal created

freesultan Submitter
4 months ago
0xtimefliez Lead Judge
4 months ago
0xtimefliez Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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