It is expected to delete only valid beneficiaries. However, if the owner provides an incorrect address or makes a duplicate call with the same address, the first beneficiary will be deleted.
The InheritanceManager::removeBeneficiary
function utilizes the helper function InheritanceManager::_getBeneficiaryIndex
, which receives an address and returns its corresponding index in the beneficiaries
array. However, if no item matches the provided address, no value will be assigned to _index
, so the default value of uint256 (0)
will be returned. Since index 0 corresponds to the first beneficiary, this results in the unintended deletion of the first beneficiary.
Add this new getter function on InheritanceManager.sol
Add the following test on InheritanceManagerTest.t.sol
The first beneficiary will be deleted, losing their inheritance rights.
Foundry
It is highly recommended to use a mapping(address => bool)
to store the beneficiaries, as it is more performant and gas-efficient:
However, if using a for
loop to find the beneficiary's index, you should verify whether index 0 corresponds to the intended address. If not, the function should revert:
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.