The InheritanceManager.sol
is missing checks on duplicate beneficiary addresses thus allowing a beneficiary to be entered more than once; resulting in the duplicate beneficiary to recieve more funds than other beneficiaries breaking the protocols invariant "shared equally".
The InheritanceManager.sol
has two instances where checks for duplicate beneficiates could be implemented but are not.
1st Instance:
addBeneficiery
The InheritanceManager
provides a way for the owner to add beneficiaries using the function addBeneficiery
. The function currently directly adds the provided address into the array of beneficiaries without any checks for duplicate addresses.
2nd Instance:
withdrawInheritedFunds
Once the contract is in an inheritable state and the funds/assets are being distributed via the withdrawInheritedFunds
function, there is no check to see if there are any duplicate beneficiaries. Instead, the inheriticance is distributed by the number of beneficiaries and sent to each address regardless of the address apperaing more than once. The relevant code snippet is InheritanceManager.sol#L241
Both areas of code could have a check for duplicate beneficiaries. The 1st instance may be gas costly as the check would have to loop the 2nd instance would have been cheaper and still as effective.
Furthermore, there is no direct way for an owner to fetch the array of beneficiaries resulting in poor visibility and manageent and increasing the chance for errors. While thereotically the InheritanceManger::_getBeneficiaryIndex
could be used, it is not a feasible way to view as - quoting the documention - its intended purpose is "as a helper function for removeBeneficiary".
The impact of missing checks for duplicate beneficiaries is HIGH due to when the inheritance is distributed amongst the beneficiaries, the duplicate beneficiaries receives a higher share than the others which further breaks the protocols invariant of "entirely equally divided" which is refering to beneficiaries getting equal shares. There is a medium likelihood of owner accidentally adding a beneficiary more than once.
Manual Review
Foundry for testing
I have provided a Solidity test function to prove that the duplicate beneficiary address gets more funds than other beneficiaries.
Run using: forge test --mt testDuplicateAddressAndInheritance -vvv
3vs to see the console log messages displayed.
The code:
As the owner, beneficiaries are added. The benef_1
address is entered twice
The 90 day timer is completed
A beneficiary changes the contract state to be inheritable.
The funds are withdrawn
The balance of the duplicate beneficiary is compared to the balances of other beneficiaries to show that it is higher.
The recommend mitigation to fix this issue is to implement a check for duplicate beneficiary addresses.
The 1st instance - addBeneficiery
- may be gas costly as the check would have to loop seach time the function was called.
The 2nd instance - withdrawInheritedFunds
- would be a more gas efficient as it only runs once and it would still be effective but its logic may be more complex as it would involve removing the duplicate address.
An example of the code for a duplicate address check in the first instance:
Another recommendation is including a function for the owner to have better visibility into the array of beneficiaries in order to catch any beneficiaries entered more than once. However, the 1st mitigation is highly recommended.
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.