The buyOutEstateNFT
function contains a vulnerability due to performing division before multiplication when calculating finalAmount
. This can lead to precision loss and incorrect fund distribution, especially when dealing with small values or uneven divisions..
https://github.com/CodeHawks-Contests/2025-03-inheritable-smart-contract-wallet/blob/main/src/InheritanceManager.sol#L263C1-L277C6
The vulnerability arises in the following line of code:
Here, value
is divided by divisor
(the number of beneficiaries) before being multiplied by multiplier
(which is beneficiaries.length - 1
). Since Solidity performs integer division, any remainder from the division is discarded, leading to precision loss. This can result in incorrect calculations, especially when value
is not perfectly divisible by divisor
.
For example:
If value = 100
and divisor = 3
, then value / divisor = 33
(remainder 1
is discarded).
Multiplying 33
by multiplier
(e.g., 2
) gives 66
, which is less than the expected 66.666...
.
This issue affects the fairness of fund distribution among beneficiaries and could lead to financial discrepancies.
Precision Loss: The division before multiplication discards remainders, leading to incorrect calculations.
Financial Discrepancies: Beneficiaries may receive less than their fair share of funds.
Manual Code Review: Identified the division before multiplication issue.
To mitigate this issue, the calculation should be reordered to perform multiplication before division. This ensures that precision is preserved as much as possible. Here's the corrected code:
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.