A logical flaw in the removeBeneficiary
function allows unintended removal of the first beneficiary if an invalid address (one not in the beneficiaries
array) is passed as an argument.
The function _getBeneficiaryIndex
iterates over the beneficiaries
array to find the index of the given address. If the address is not found, the function does not explicitly return an invalid index, causing it to default to 0
. Consequently, when removeBeneficiary
is called with a non-existent beneficiary, the first beneficiary (index 0
) is mistakenly deleted.
If an invalid address is passed, the first beneficiary is erroneously removed.
This can lead to unintended removal of valid beneficiaries, potentially disrupting contract functionality.
Could allow malicious actors to exploit this flaw by tricking the owner into calling the function with an invalid address.
Foundry framework for testing
Solidity static analysis
Manual code review
The following Foundry test demonstrates the vulnerability:
For testing purposes, the following getter function was added in InheritanceManager.sol
to retrieve the list of beneficiaries:
Modify _getBeneficiaryIndex
to return an invalid index if the beneficiary is not found:
Before deleting a beneficiary, validate the returned index:
Implement proper error handling to prevent silent failures.
Add unit tests to cover edge cases, ensuring robustness against such logical flaws.
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.