Summary
Logical & Functional Issues
Vulnerability Details
Incorrect Beneficiary Removal Logic
Impact
The function removeBeneficiary()
deletes an entry from the array but does not shift remaining elements. This leaves a gap and can cause unexpected behavior.
Tools Used
* @dev removes entries from beneficiaries in case inheritance gets revoked or
* an address needs to be replaced (lost keys e.g.)
* @param _beneficiary address to be removed from the array beneficiaries
*/
function removeBeneficiary(address _beneficiary) external onlyOwner {
uint256 indexToRemove = _getBeneficiaryIndex(_beneficiary);
delete beneficiaries[indexToRemove];
}
Recommendations
Fix removeBeneficiary()
to shift array elements properly
function removeBeneficiary(address _beneficiary) external onlyOwner {
uint256 indexToRemove = _getBeneficiaryIndex(_beneficiary);
require(indexToRemove < beneficiaries.length, "Invalid beneficiary");
beneficiaries[indexToRemove] = beneficiaries[beneficiaries.length - 1];
beneficiaries.pop();
}