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

Improper Beneficiary Removal Leading to Fund Loss

Summary

The removeBeneficiary function in the InheritanceManager contract does not properly remove a beneficiary from the beneficiaries array. Instead of shifting elements or replacing the removed address properly, it leaves a gap by setting the beneficiary’s slot to address(0). This can cause fund misallocation when inheritance distribution occurs, potentially leading to lost funds if a share is mistakenly sent to address(0).

Vulnerability Details

  • The function removeBeneficiary(address _beneficiary) is intended to remove a specific beneficiary from the beneficiaries array.

  • However, it only deletes the entry at the specified index, leaving an empty slot (address(0)) instead of properly restructuring the array.

  • When the withdrawInheritedFunds function calculates fund distribution, it includes this empty slot in the division, potentially allocating a portion of funds to address(0), burning them permanently.

  • The issue arises due to the following logic:

function removeBeneficiary(address _beneficiary) external onlyOwner {
uint256 indexToRemove = _getBeneficiaryIndex(_beneficiary);
delete beneficiaries[indexToRemove]; // Leaves a gap instead of shifting elements
}
  • This results in:

  1. An incorrect array length assumption during fund splitting.

  2. A portion of the inheritance is being sent to address(0), effectively burning funds.

Impact

  • Loss of funds: A share of the inheritance can be mistakenly sent to address(0), permanently removing it from circulation.

  • Unequal fund distribution: Remaining beneficiaries do not receive the full intended inheritance, leading to disputes or financial losses.

  • Unexpected contract behavior: The contract does not function as expected, violating core inheritance logic.

Tools Used

Foundry &b Manual Review

Recommendations

To fix this issue, update removeBeneficiary to properly remove an address by shifting elements instead of just deleting them:

function removeBeneficiary(address _beneficiary) external onlyOwner {
uint256 indexToRemove = _getBeneficiaryIndex(_beneficiary);
uint256 lastIndex = beneficiaries.length - 1;
if (indexToRemove != lastIndex) {
beneficiaries[indexToRemove] = beneficiaries[lastIndex]; // Move last element to removed index
}
beneficiaries.pop(); // Remove last element
}

This will

  • It prevents gaps by replacing the removed beneficiary with the last element.

  • It correctly updates the array length, preventing division miscalculations in inheritance distribution.

  • It ensures funds are distributed properly without sending any to address(0).

Updates

Lead Judging Commences

0xtimefliez Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Incorrect removal from beneficiary list causes funds to be send to 0 address

Support

FAQs

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