The calculation of vestedAmount
in the _calculateReleasableAmount
function uses integer division, which can lead to precision loss, especially with the provided constants:
VESTING_DURATION = 700 days
MIN_RELEASE_INTERVAL = 1 day
This results in:
Incorrect vesting amounts: Small amounts of tokens may not be vested correctly, especially during the early stages of the vesting schedule.
Loss of tokens: Beneficiaries may receive fewer tokens than they are entitled to due to rounding down in the division.
Cumulative discrepancies: Over time, the cumulative effect of precision loss could lead to significant discrepancies between the expected and actual vested amounts.
The _calculateReleasableAmount
function calculates the vestedAmount
as:
Due to integer division, the result is rounded down, leading to precision loss. For example:
If schedule.totalAmount = 1000
, timeFromStart = 1 day
, and VESTING_DURATION = 700 days
, the calculation is:
Due to integer division, this rounds down to 1 token
, resulting in a loss of 0.428 tokens
.
Deploy the contract and create a vesting schedule with the following parameters:
beneficiary
: A valid address.
category
: A valid category with sufficient allocation.
amount
: 1000 tokens.
startTime
: Current block timestamp.
duration
: 700 days (VESTING_DURATION
).
Wait for 1 day (timeFromStart = 1 day
).
Call the release
function.
Observe that the releasableAmount
is 1 token, even though the beneficiary should receive 1.428 tokens
.
Precision loss is highly likely to occur during the early stages of the vesting schedule (e.g., within the first few days or weeks).
The impact depends on the specific values of schedule.totalAmount
, timeFromStart
, and VESTING_DURATION
.
Manual Review
To mitigate precision loss, consider the following solutions:
Scale Up Values:
Multiply schedule.totalAmount
and timeFromStart
by a scaling factor (e.g., 1e18
) before performing the division, then scale down the result.
Example:
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.