In this contract there is risk of losing funds due to precision loss and all beneficiaries might not get equal share
Let us assume these values for calculation
value = 1000 USDC
beneficiaries = ["Alice", "Bob", "Charlie", "Dave"]
(4 total)
divisor = 4
(total beneficiaries)
multiplier = 3
(since multiplier = beneficiaries.length - 1
)
finalAmount = (value / divisor) * multiplier;
(1000/4)×3=250×3 = 750 USDC
The final amount will be 750 USDC
IERC20(assetToPay).safeTransfer(beneficiaries[i], finalAmount / divisor);
Transfer per beneficiary would be 750/4=187.5 USDC
But Solidity only supports integers, so 187.5
gets truncated to 187
.
msg.sender
(buyer) pays 750 USDC
Each beneficiary receives 187 USDC
Total distributed: 187 × 3 = 561 USDC
There is 3 micro USDC loss due to truncation which is as follows
750−561=189 micro USDC
i.e. Lost 189 micro-USDC (189 * 1e-6 USDC
), equivalent to 0.189 USDC
Beneficiaries are underpaid due to rounding off error and incurring loss for beneficiaries.
Tools Used
Manual Review
Use dynamic scaling we can achieve the results as follows. It will support both USDC and DAI and there would be no loss in token precision.
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.