The removeBeneficiary
function in the InheritanceManager
contract improperly removes beneficiaries by simply deleting the entry at the specified index without reordering the array. This creates holes (zero addresses) in the beneficiaries
array which causes multiple serious issues throughout the contract's functionality.
The current implementation of removeBeneficiary
uses the delete
operator:
This simply sets the value at indexToRemove
to address(0)
, leaving a gap in the array rather than properly removing the element. Additionally, there's no check that _beneficiary
actually exists in the array before attempting removal.
The related _getBeneficiaryIndex
function has its own issues:
This function will return 0
for beneficiary in the array that have been remove.
This vulnerability leads to several critical issues:
Ineffective Access Control: Functions that use the onlyBeneficiaryWithIsInherited
modifier will incorrectly allow access to anyone when there are gaps in the array, as the modifier will trigger an out-of-bounds error and execution will halt before the protected code can run.
Fund Distribution Problems: The withdrawInheritedFunds
function distributes funds equally among all elements in the beneficiaries array. If some elements are address(0)
due to improper removal, funds will be sent to the zero address and permanently lost.
Incorrect Accounting: Functions like buyOutEstateNFT
calculate payments based on the length of the beneficiaries array, not the actual number of valid beneficiaries, leading to incorrect payment calculations.
Silent Failures: Attempting to remove a non-existent beneficiary will silently set element 0 to address(0)
, potentially removing a legitimate beneficiary without warning.
Manual code review
Implement a proper array removal algorithm that maintains array integrity:
Fix the _getBeneficiaryIndex
function to properly handle non-existent beneficiaries:
Add checks in functions like withdrawInheritedFunds
to skip zero addresses:
Consider adding events to track beneficiary management:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.