Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Invalid

Duplicate addresses in beneficiaries array causes unfair asset distribution

Description:

The addBeneficiary() function allows adding the same address multiple times to the beneficiaries array without any duplication checks:

function addBeneficiary(address _beneficiary) external onlyOwner {
beneficiaries.push(_beneficiary);
_setDeadline();
}

If the owner accidentally enters two or more identical addresses, this lack of duplicate checking will affect critical functions throughout the contract, particularly those related to asset distribution and inheritance activation.

Impact:

1) This leads to unfair asset distribution in the withdrawInheritedFunds function:

  • An address that appears multiple times in the array receives multiple shares

  • For example, if an address is added twice to a three-address array, it receives 2/3 of all assets

  • The distribution is based on raw array positions rather than unique beneficiaries:

function withdrawInheritedFunds(address _asset) external {
// ...
uint256 divisor = beneficiaries.length; // Counts duplicates
uint256 amountPerBeneficiary = ethAmountAvailable / divisor;
for (uint256 i = 0; i < divisor; i++) {
address payable beneficiary = payable(beneficiaries[i]);
(bool success,) = beneficiary.call{value: amountPerBeneficiary}("");
// ...
}
}

2) Issues with the inherit function:

  • A contract with a single unique beneficiary added multiple times incorrectly activates multi-beneficiary mode

  • This prevents proper ownership transfer that should occur with a single beneficiary:

function inherit() external {
// ...
if (beneficiaries.length == 1) {
owner = msg.sender; // Single ownership transfer
_setDeadline();
} else if (beneficiaries.length > 1) {
isInherited = true; // Shared inheritance mode
}
// ...
}

Recommended Mitigation:

Add duplicate checking to addBeneficiary()

function addBeneficiary(address _beneficiary) external onlyOwner {
+ // Check for duplicates
+ for (uint256 i = 0; i < beneficiaries.length; i++) {
+ require(beneficiaries[i] != _beneficiary, "Beneficiary already exists");
+ }
beneficiaries.push(_beneficiary);
_setDeadline();
}

Consider using a mapping for more efficient beneficiary tracking:

+ mapping(address => bool) public isBeneficiary;
function addBeneficiary(address _beneficiary) external onlyOwner {
+ require(!isBeneficiary[_beneficiary], "Beneficiary already exists");
beneficiaries.push(_beneficiary);
+ isBeneficiary[_beneficiary] = true;
_setDeadline();
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.