Skip to content
Audit finding Advanced

Bug inside ABDKMathQuad library

The ABDKMathQuad library used by FairSideFormula has edge cases where conversions between UInt and Bytes16 produce small differences, and other operations may also misbehave. An attacker could potentially exploit these inaccuracies, though the report does not demonstrate a concrete exploit.

FairSide contest

Originally disclosed on Code4rena

The FairSideFormula library is using the ABDKMathQuad library underneath. According to the ABDKMathQuad README, the range of values is the following:

The minimum strictly positive (subnormal) value is 2^−16494 ≈ 10^−4965 and has a precision of only one bit. The minimum positive normal value is 2^−16382 ≈ 3.3621 × 10^−4932 and has a precision of 113 bits, i.e., ±2^−16494 as well. The maximum representable value is 2^16384 − 2^16271 ≈ 1.1897 × 10^4932.

Using Echidna, a fuzzing tool for smart contracts, I found some edge cases in which some of the operations do not work as expected. This is the test code I ran using echidna-test contracts/TestABDKMathQuad --contract TestABDKMathQuad. see issue for more details.

If we check in Remix, we can see that there is a small difference when converting from UInt to Bytes16 (and vice versa). This issue is probably the same with all the other operations.

Recommend using some fuzzing tool like Echidna to verify that there are no edge cases.

fairside-core (FairSide) acknowledged:

I am slightly mixed about this finding. We did employ fuzz tests during the audit we had gone through, and they were unable to pinpoint any issues in the value range we expect the curve to be utilized in. This is definitely a good suggestion and one we will assimilate. However, I am not sure how one would judge the severity of this.

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 rounding or precision errors in the ABDKMathQuad library when converting between integer and fixed-point representations at extreme values.

Impact

The inaccuracies could lead to incorrect calculations in the FairSideFormula, but the report does not show a concrete exploit and the project notes that fuzz tests did not find issues in the expected value range.

What the attacker needed

None

The fix

The project acknowledged the finding and said they will assimilate the suggestion to use fuzzing tools, but no specific fix is described.

How it was found

  1. Run the Echidna fuzzing tool on the test contract.
  2. Observe edge cases where operations do not work as expected.
  3. Check the conversion in Remix to see the small difference.

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 often use fixed-point maths libraries to handle decimal numbers. This report found that one such library gives slightly wrong answers for very large or very small numbers. The impact is unclear because no real attack was shown.

More from FairSide contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.