Skip to content
Audit finding Intermediate

Rounding errors will occur for tokens without decimals

The constant product pool's output calculation rounds down, causing significant precision loss for tokens with zero decimals. An attacker swapping small amounts of such tokens could lose a large percentage of their trade to rounding.

Sushi Trident contest phase 1

Originally disclosed on Code4rena

Some rare tokens have 0 decimals: https://etherscan.io/token/0xcc8fa225d80b9c7d42f96e9570156c65d6caaa25

For these tokens, small losses of precision will be amplified by the lack of decimals.

Consider a constant product pool with 1000 of token0 (with no decimals), and 1000 of token1 (also with no decimals). Suppose I swap n= 1,2,3,4 of token0 to token1. Then my output amount of token1 will be 0,1,2,3.

If token0/1 are valuable than I will be losing 100%, 50%, 33%, 25% of my trade to rounding. Currently there is no valuable token with 0 decimals, but there may be in the future.

Rounding the final getAmountOut division upwards would fix this.

maxsam4 (Sushi) commented:

Acceptable risk. We can’t do anything if the token itself doesn’t have decimals. We don’t create synthetic assets and fractionalize such tokens ourselves.

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

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 pool's output amount calculation rounds down instead of up, amplifying precision loss for tokens with zero decimals.

Impact

Traders could lose a significant percentage of their trade to rounding when swapping small amounts of zero-decimal tokens, but the team considers this an acceptable risk.

What the attacker needed

Token with zero decimals; small trade amount

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.

Some tokens have no decimal places, so they can only be traded in whole units. When a trading pool calculates how many tokens you get back, it rounds down, which can mean you lose a large chunk of your trade if the amounts are small. This report points out that for such tokens, the rounding error is much worse than for normal tokens.

More from Sushi Trident contest phase 1

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.