Skip to content
Audit finding Intermediate

Loss of precision resulting in wrong value for price ratio

The price ratio in a swap periphery contract was computed by dividing two 18-decimal normalised prices, which loses precision. In the best case the division returns zero and causes a division-by-zero revert; in the worst case it returns a single-digit value, making fair reserve calculations incorrect.

Canto

Originally disclosed on Code4rena

Price ratio was calculated by division of price0 and price1. Both prices are normalized to 18 decimal points. Division at best case would return 0 which would cause division by zero revert. At worst case it returns single digit which will make calculations of fair reserves incorrect.

https://github.com/Canto-Network/lending-updates/blob/8f1e624a74ea67e63400209dded2bb716d92e472/src/Swap/BaseV1-periphery.sol#L573

STATUS: Mitigated

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 ratio was computed by dividing two already-scaled 18-decimal values without rescaling or multiplying by a precision factor first, so integer division truncated the result.

Impact

The contract could revert on a division by zero, or produce an incorrect price ratio that leads to wrong fair reserve calculations.

What the attacker needed

None

The fix

The text marks the issue as mitigated but does not describe the change; it should be fixed by scaling the numerator before division or using a fixed-point maths library.

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.

Smart contracts store numbers as whole numbers, so a fraction like 0.0004 is kept as a scaled integer. When you divide two such scaled numbers, the result is rounded down and can become zero or a tiny number. Here that rounding made the contract either crash or compute the wrong price ratio.

More from Canto

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.