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.
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.