Skip to content
Business logic Audit finding Intermediate

Incorrect implementation of arctan in the contract FairSideFormula

The arctan approximation in the FairSideFormula contract omitted absolute value operations, producing incorrect results for negative inputs. This could cause the calculateDeltaOfFSD function to mint or burn an incorrect number of FSD tokens.

FairSide contest

Originally disclosed on Code4rena

The current implementation of the arctan formula in the contract FairSideFormula is inconsistent with the referenced paper and could cause incorrect results when the input parameter is negative. The erroneous formula affects the function calculateDeltaOfFSD and the number of FSD tokens minted or burned.

The function _arctan misses two abs on the variable `a’. The correct implementation should be:

function _arctan(bytes16 a) private pure returns (bytes16) {
    return
        a.mul(PI_4).sub(
            a.mul(a.abs().sub(ONE)).mul(APPROX_A.add(APPROX_B.mul(a.abs())))
        );
}

Notice that _arctan is called by arctan, and arctan is called by arcs with ONE.sub(arcInner) provided as the input parameter. Since arcInner = MULTIPLIER_INNER_ARCTAN.mul(x).div(fS3_4) can be a large number (recall that x is the capital pool), it is possible that the parameter a is negative.

Recommend modifying the _arctan function as above.

fairside-core (FairSide) confirmed:

Fixed in PR#4.

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

Impact

The incorrect arctan calculation could lead to minting or burning an incorrect amount of FSD tokens when the input to _arctan is negative.

What the attacker needed

None

The fix

The _arctan function was fixed to apply abs to the variable a in two places, matching the referenced paper.

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.

A smart contract used a mathematical shortcut to compute arctan, but forgot to handle negative numbers correctly. This could make the contract calculate the wrong number of tokens to create or destroy when someone interacts with it.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from FairSide contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.