The removeBeneficiary()
function in the InheritanceManager contract creates gaps in the beneficiaries array rather than maintaining a compact array structure. This leads to incorrect fund distribution during inheritance and potential loss of funds sent to the zero address.
The vulnerability exists in the removeBeneficiary()
function:
This function uses Solidity's delete
keyword, which sets the array element to its default value (address(0)) but doesn't resize the array or shift elements. The array remains the same length with a "gap" at the deleted index.
This causes two critical issues:
During fund distribution in withdrawInheritedFunds()
, the contract uses beneficiaries.length
as the divisor, including the zero addresses from deleted elements:
The contract then attempts to send funds to all addresses in the array, including address(0):
PoC Result:
Direct Loss of Funds: When beneficiaries are removed, a portion of inheritance funds equal to totalAssets / beneficiaries.length
will be sent to address(0) for each removed beneficiary, permanently locking those assets.
Incorrect Asset Distribution: Legitimate beneficiaries receive less than their fair share. For example, if 1 of 3 beneficiaries is removed, each remaining beneficiary receives only 33% of assets instead of the correct 50%.
Gas Waste: Transfer attempts to address(0) waste gas, and for ERC20 tokens will revert the entire transaction due to SafeERC20's receiver validation.
foundry
manual code review
Replace the removeBeneficiary()
function with one that maintains a compact array:
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.