Skip to content
Audit finding Intermediate

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.

WatchPug Follow

Originally disclosed on Sherlock

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:

Solidity
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:

Solidity
balance = elapsedTime_ * tokenAmount_ / duration

Discussion

eladmallel

Fix PR: https://github.com/nounsDAO/streamer/pull/7

jack-the-pug

Fix confirmed!

The original report as published on Sherlock, by WATCHPUG. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by WatchPug

View all

197 more disclosed reports, best first.

More from NounsDAO

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.