Summary
In InheritableManager.sol
_getBeneficiaryIndex
will always return the 0 index for addresses that aren't in the beneficiaries
array, causing the wrong address to be removed when removeBeneficiary
is called
Vulnerability Details
The issue is here:
function _getBeneficiaryIndex(address _beneficiary) public view returns (uint256 _index) {
for (uint256 i = 0; i < beneficiaries.length; i++) {
if (_beneficiary == beneficiaries[i]) {
_index = i;
break;
}
}
}
There's no functionality that handles the situation where the address is not in the `beneficiaries` array, as such the default uint256 value would be returned i.e 0
POC
Add the below test to `InheritableManagerTest.t.sol`
function testWrongIndexDeleted() public {
address zeroIndex = makeAddr("zeroIndex");
address firstIndex = makeAddr("firstIndex");
address rando = makeAddr("rando");
vm.startPrank(owner);
im.addBeneficiery(zeroIndex);
im.addBeneficiery(firstIndex);
assertEq(zeroIndex, im.beneficiaries(0));
im.removeBeneficiary(rando);
vm.stopPrank();
address newZeroindex = im.beneficiaries(0);
assertEq(newZeroindex, address(0));
}
Impact
The beneficiary at the 0th index would be removed unfairly
Tools Used
Manual review, foundry test suite
Recommendations
function _getBeneficiaryIndex(address _beneficiary) public view returns (uint256 _index) {
for (uint256 i = 0; i < beneficiaries.length; i++) {
if (_beneficiary == beneficiaries[i]) {
_index = i;
+ return _index;
- break;
}
}
+ revert("Address is not beneficiary");
}