The project expects that removed beneficiaries do not impact the inheritance and withdrawal mechanisms. However, the length of the beneficiaries array does not decrease after a removal, causing an incorrect count that disrupts fund distribution. Additionally, this issue makes it impossible to revert to the personal backup scenario.
The InheritanceManager::removeBeneficiary function replaces the beneficiary's address with a zero address but does not decrease the beneficiaries.length count.
For example, if three users are added and the first user is removed, beneficiaries.length will still be equal to 3 and beneficiaries[0] will be a zero address.
Since beneficiaries.length never decreases, it becomes impossible to reach the condition beneficiaries.length == 1 again. As a result, the owner cannot revert to the personal backup scenario.
Since withdrawInheritedFunds uses beneficiaries.length as a divisor, the calculated amountPerBeneficiary will be incorrect, and funds will also be sent to the zero address, because there is no address verification inside the for loops.
Paste the following test into InheritanceManagerTest.t.sol. This test will pass, but user2 and user3 should have received 3e18.
This test can be pasted into the same document and will demonstrate that it is impossible to revert to the personal backup scenario again.
Funds can be lost due to being sent to an unintended address, with no possibility of recovery.
The owner can never revert to the personal backup scenario if multiple beneficiaries are added, even after removing all but one.
Foundry
Introduce a counter variable for valid beneficiaries. When InheritanceManager::addBeneficiery is called, the counter should increase by 1; when InheritanceManager::removeBeneficiary is called, the counter should decrease by 1.
This counter should:
Be used as the divisor in InheritanceManager::withdrawInheritedFunds.
Determine conditions in InheritanceManager::inherit.
To prevent funds from being sent to zero addresses, implement a zero-address check inside the for loops before transferring any funds.
A better approach would be to store beneficiaries in a mapping while maintaining a counter to track the number of valid beneficiaries.
Using mappings allows:
Each beneficiary to withdraw their share independently.
Improved performance and gas efficiency.
Avoiding a scenario where a single beneficiary bears the high gas cost of the loops alone.
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.