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

Residual losses due to non-exact divisions in `InheritanceManager:withdrawInheritedFunds` and `InheritanceManager:buyOutEstateNFT`

Summary

The functions withdrawInheritedFunds and buyOutEstateNFT perform exact divisions, and if the division isn't exact, some funds can remain in the smart contract.

Recommendations

Use more sophisticated libraries for calculations or mitigate as follows.
In this case, we send the residual to the first in the list:

function withdrawInheritedFunds(address _asset) external {
if (!isInherited) {
revert NotYetInherited();
}
uint256 divisor = beneficiaries.length;
if (_asset == address(0)) {
uint256 ethAmountAvailable = address(this).balance;
uint256 amountPerBeneficiary = ethAmountAvailable / divisor;
+ uint256 remainder = ethAmountAvailable % divisor;
for (uint256 i = 0; i < divisor; i++) {
address payable beneficiary = payable(beneficiaries[i]);
+ uint256 amountToSend = amountPerBeneficiary + (i == 0 ? remainder : 0);
(bool success, ) = beneficiary.call{
value: amountToSend
}("");
require(success, "something went wrong");
}
} else {
uint256 assetAmountAvailable = IERC20(_asset).balanceOf(
address(this)
);
uint256 amountPerBeneficiary = assetAmountAvailable / divisor;
uint256 remainder = amountPerBeneficiary % divisor;
for (uint256 i = 0; i < divisor; i++) {
uint256 amountToSend = amountPerBeneficiary + (i == 0 ? remainder : 0);
IERC20(_asset).safeTransfer(
beneficiaries[i],
amountToSend
);
}
}
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge 3 months ago
Submission Judgement Published
Validated
Assigned finding tags:

buyOutNFT has wrong denominator

truncation of integers

Support

FAQs

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