Skip to content

Latest commit

 

History

History
100 lines (71 loc) · 3.83 KB

File metadata and controls

100 lines (71 loc) · 3.83 KB

Jolly Mauve Parakeet

Medium

NoopAdiabatic6Lib returns incorrect fees

Summary

NoopAdiabatic6Lib does the same calculations as LinearAdiabatic6Lib, returns the same fees as LinearAdiabatic6Lib

Root Cause

According to the notice from this library

Library that that manages the no-op adiabatic fee algorithm

For the NoopAdiabatic6Lib, the purpose is to not adjust the fee dynamically based on market conditions. Therefore, this library should return a constant fee or bypass the fee adjustment mechanism. Instead of calling the AdiabaticMath6.linearFee, it could return a fixed fee, such as zero or a pre-configured static value

library NoopAdiabatic6Lib {
    /// @notice Computes the linear fee
    /// @param self The adiabatic configuration
    /// @param change The change in skew in asset terms
    /// @param price The price of the underlying asset
    /// @return The linear fee in underlying terms
    function linear(NoopAdiabatic6 memory self, Fixed6 change, UFixed6 price) internal pure returns (UFixed6) {
        return AdiabaticMath6.linearFee(self.linearFee, change, price);
    }

    /// @notice Computes the proportional fee
    /// @param self The adiabatic configuration
    /// @param change The change in skew in asset terms
    /// @param price The price of the underlying asset
    /// @return The proportional fee in underlying terms
    function proportional(NoopAdiabatic6 memory self, Fixed6 change, UFixed6 price) internal pure returns (UFixed6) {
        return AdiabaticMath6.proportionalFee(self.scale, self.proportionalFee, change, price);
    }
}

adiabatic/types/NoopAdiabatic6.sol#L22

library LinearAdiabatic6Lib {
 ...

    /// @notice Computes the linear fee
    /// @param self The adiabatic configuration
    /// @param change The change in skew in asset terms
    /// @param price The price of the underlying asset
    /// @return The linear fee in underlying terms
    function linear(LinearAdiabatic6 memory self, Fixed6 change, UFixed6 price) internal pure returns (UFixed6) {
        return AdiabaticMath6.linearFee(self.linearFee, change, price);
    }

    /// @notice Computes the proportional fee
    /// @param self The adiabatic configuration
    /// @param change The change in skew in asset terms
    /// @param price The price of the underlying asset
    /// @return The proportional fee in underlying terms
    function proportional(LinearAdiabatic6 memory self, Fixed6 change, UFixed6 price) internal pure returns (UFixed6) {
        return AdiabaticMath6.proportionalFee(self.scale, self.proportionalFee, change, price);
    }
...
}

adiabatic/types/LinearAdiabatic6.sol#L35

There is a similar Noop library where a fixed value is being returned NoopFiatReserve.sol

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

The makerFee is being calculated incorrectly because it is using NoopAdiabatic6, but it is not behaving as it is supposed to.

PoC

No response

Mitigation

Returns fixed or zero from that library like it described

    function linear(NoopAdiabatic6 memory self, Fixed6 change, UFixed6 price) internal pure returns (UFixed6) {
-        return AdiabaticMath6.linearFee(self.linearFee, change, price);
+        return self.linearFee;