Skip to content
Audit finding Intermediate

ABDKMath64 performs multiplication on results of division

A fixed-point maths library performed division before multiplication, so Solidity's integer truncation could discard precision from the intermediate result. An attacker could not directly exploit this, but callers relying on the library could compute slightly wrong values.

AlleyCat Follow

Originally disclosed on Code4rena

Submitted by AlleyCat

https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/libraries/ABDKMath64x64.sol#L626

https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/libraries/ABDKMath64x64.sol#L629

https://github.com/code-423n4/2022-04-mimo/blob/main/core/contracts/libraries/ABDKMath64x64.sol#L630

Solidity could truncate the results, performing multiplication before division will prevent rounding/truncation in solidity math.

Recommended Mitigation Steps

Consider ordering multiplication first.

m19 (Mimo DeFi) acknowledged


The original report as published on Code4rena, by AlleyCat. 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 expression divides two values and then multiplies the result, so integer truncation in the division step loses precision that a later multiplication cannot recover.

Impact

Calculations using this library could return slightly inaccurate values due to truncation; the report does not show a concrete exploit.

What the attacker needed

Contract code calls the affected library function

The fix

The order of operations should be changed so multiplication happens before division.

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.

Solidity, the language smart contracts are written in, only works with whole numbers, so any fraction is simply cut off. If you divide first and multiply afterwards, that cut-off fraction is lost and the final answer can be slightly wrong. Doing the multiplication first keeps more precision before the division happens.

More from Mimo DeFi contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.