Unnecessary precision loss in `_recipientBalance()`
The vesting balance calculation in `_recipientBalance()` divides before multiplying, causing unnecessary precision loss. An attacker could exploit this to receive slightly less than the correct vested amount, though the text does not claim a direct theft or gain.
Source: https://github.com/sherlock-audit/2022-11-nounsdao-judging/issues/70
Found by
WATCHPUG
Summary
Using ratePerSecond() to calculate the _recipientBalance() incurs an unnecessary precision loss.
Vulnerability Detail
The current formula in _recipientBalance() to calculate the vested amount (balance) incurs an unnecessary precision loss, as it includes div before mul:
balance = elapsedTime_ * (RATE_DECIMALS_MULTIPLIER * tokenAmount_ / duration) / RATE_DECIMALS_MULTIPLIER
This can be avoided and the improved formula can also save some gas.
Impact
Precision loss in _recipientBalance().
Code Snippet
https://github.com/sherlock-audit/2022-11-nounsdao/blob/main/src/Stream.sol#L341-L344
Tool used
Manual Review
Recommendation
Consdier changing to:
balance = elapsedTime_ * tokenAmount_ / duration
Discussion
eladmallel
Fix PR: https://github.com/nounsDAO/streamer/pull/7
jack-the-pug
Fix confirmed!
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 the formula performs integer division before multiplication, which discards remainders and reduces precision.
Impact
The precision loss means recipients may receive slightly less than the correct vested amount; the text does not claim any direct theft or gain.
What the attacker needed
None
The fix
The formula should be changed to multiply before dividing, as shown in the recommendation, and the fix was confirmed.
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.
When a smart contract calculates how much money someone has earned over time, it does maths with whole numbers. If it divides too early, it can lose small fractions, like getting 99 cents instead of 99.5 cents. This report says the contract does the division before the multiplication, so the final amount is slightly too low.