Tokens with lower number of decimals can result in postponed linear vesting for user
The vesting contract calculates vested amounts using integer division, which rounds down to zero for tokens with few decimals and long vesting periods. This can postpone the start of linear vesting for users by several days, potentially causing financial loss if the token price drops during that delay.
Submitted by pashov
In the _baseVestedAmount of VTVLVesting.sol we see the following code
uint40 finalVestingDurationSecs = _claim.endTimestamp - _claim.startTimestamp; // length of the interval
uint112 linearVestAmount = _claim.linearVestAmount * truncatedCurrentVestingDurationSecs / finalVestingDurationSecs;
Let’s look at truncatedCurrentVestingDurationSecs as just the duration passed from the start of the vesting period for the PoC (this doesn’t omit important data in this context).
Now think of the following scenario:
We have a token $TKN that has 6 decimals (those are the decimals of both USDT & USDC). We want to distribute 10,000 of those tokens to a user vested over a 10 year period.
10 years in seconds is 315360000 ****(this is finalVestingDurationSecs)
This means that we will distribute 10,000 * 10^6 = 10 000 000 000 fractions of a token for 315360000 seconds, meaning we will distribute 310 fractions of a token each second - this is linearVestAmount
Now, since finalVestingDurationSecs is so big (315360000) it will almost always round linearVestAmount to zero when dividing by it, up until
_claim.linearVestAmount * truncatedCurrentVestingDurationSecs becomes a bigger number than 315360000, but since _claim.linearVestAmount is 310 we will need the current vesting duration to be at least 1 017 290 seconds which is 12 days postponed vesting. 12 days in a moving market can make a big difference if the user was expecting the tokens to start vesting from the first day.
Impact
Unexpected postponing of vesting can result in waiting times for users to receive their must-be-vested tokens. This period can be used by other token holders to dump the token and decrease the price of it, resulting in a loss of capital for the vesting receiver.
Recommended Mitigation Steps
Enforce the contract to work with only 18 decimal tokens with a require statement in the constructor.
0xean (judge) decreased severity to Medium and commented:
Downgrading to Medium, there are a lot of external factors presented here by the warden to line up to a loss of funds.
lawrencehui (VTVL) acknowledged, but disagreed with severity and commented:
I acknowledge the warden’s concern of the rounding, but I think the result of loss of funds is one of the extreme edge cases. I would suggest instead of restricting only to 18 decimal tokens (which is impractical as we would also want to include USDC and USDT for vesting too!), I would implement the rounding checking in the frontend UI and prompt user of potential delay caused by rounding / truncation as described in this issue.
Given that smart contracts can be interacted with in any number of ways (etherscan, programmatically, etc), I don’t think the mitigation negates the risk entirely and am going to stick with the Medium severity here. The wardens demonstrates clearly the way in which this can happen. While it may be a bit outside of the normal vesting schedule expected, I do think it’s valuable to understand the bounds of the math you have employed here.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely integer division truncation in the vested amount calculation, which rounds down to zero when the numerator is smaller than the denominator.
Impact
Vesting may be postponed by several days, and during that time other holders could sell tokens and lower the price, causing a loss for the vesting recipient; the judge noted many external factors are needed for an actual loss.
What the attacker needed
Token with fewer than 18 decimals; long vesting duration; small linear vest amount
The fix
The contract should be restricted to 18-decimal tokens, or the frontend should warn users about rounding delays, though the judge noted that contract interactions can bypass frontend warnings.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A vesting contract releases tokens to a user gradually over time. Because the contract uses whole-number maths, small token amounts divided over a long period can round down to zero, so the user receives nothing for the first few days or weeks. This report shows that with tokens that have few decimal places, the delay can be significant.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.