Skip to content
Audit finding Intermediate

Incorrect precision assumed from RdpxPriceOracle creates multiple issues related to value inflation/deflation

LokiThe5th Follow with minhtrng, QiuhaoLi and 14 others

Originally disclosed on Code4rena

Submitted by LokiThe5th, also found by minhtrng, QiuhaoLi, Udsen (1, 2), 0xvj (1, 2), josephdara, kutugu, Evo, 0xTiwa, crunch, circlelooper, 0xPsuedoPandit, Jiamin, gjaldon (1, 2, 3, 4), Juntao, umarkhatab_465, hals (1, 2), eeshenggoh, 0xnev, T1MOH, and niki

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV2LiquidityAmo.sol#L372

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV2LiquidityAmo.sol#L381

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/perp-vault/PerpetualAtlanticVault.sol#L539

https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L1160

The RdpxEthPriceOracle, available in the audit repo here, provides the RdpxV2Core, the UniV2LiquidityAmo and the PerpetualAtlanticVault contracts the necessary values for rdpx related price calculations.

The issue is that these contracts expect the returned values to be in 1e8 precision (as stated in the natspec here, here and here). But the returned precision is actually 1e18.

This difference creates multiple issues throughout the below contracts:

Contract | Function | Effect |

rdpxV2Core.sol | getRdpxPrice() | Returns an 1e18 value when 1e8 expected |

| calculateBondCost() | Deflates the rdpxRequired |

| calculateAmounts() | Inflates the rdpxRequiredInWeth |

| _transfer() | Inflates rdpxAmountInWeth and may cause possible underflow |

UniV2LiquidityAmo | getLpPriceInEth() | Overestimates the lp value |

ReLp.sol | reLP() | Inflates min token amounts |

PerpetualAtlanticVault.sol | getUnderlyingPrice() | Returns 1e18 instead of 1e8 |

| calculatePremium() | Inflates the premium calculation |

Proof of Concept

The RdpxEthPriceOracle.sol file can be found here

It exposes the following functions used in the audit:

These two functions provide the current price denominated in ETH, with a precision in 1e18, as confirmed by their respective natspec comments:

    /// @dev Returns the price of LP in ETH in 1e18 decimals
    function getLpPriceInEth() external view override returns (uint) {
    ...

    /// @notice Returns the price of rDPX in ETH
    /// @return price price of rDPX in ETH in 1e18 decimals
    function getRdpxPriceInEth() external view override returns (uint price) {

But, in the contracts from the audit repo, the business logic (and even the natspec) assumes the returned precision will be 1e8. See below:

In the RdpxV2Core contract the assumption that the price returned from the oracle is clearly noted in the natspec of the getRdpxPrice() function:

  /**
   * @notice Returns the price of rDPX against ETH
   * @dev    Price is in 1e8 Precision
   * @return rdpxPriceInEth rDPX price in ETH
   **/
  function getRdpxPrice() public view returns (uint256) {
    return
      IRdpxEthOracle(pricingOracleAddresses.rdpxPriceOracle)
        .getRdpxPriceInEth();
  }

In UniV2LiquidityAmo the assumption is noted here:

  /**
   * @notice Returns the price of a rDPX/ETH Lp token against the alpha token
   * @dev    Price is in 1e8 Precision
   * @return uint256 LP price
   **/
  function getLpPrice() public view returns (uint256) {

And it has business logic implication here:

  function getLpTokenBalanceInWeth() external view returns (uint256) {
    return (lpTokenBalance * getLpPrice()) / 1e8;
  }

In PerpetualAtlanticVault it is noted here:

  /**
   * @notice Returns the price of the underlying in ETH in 1e8 precision
   * @return uint256 the current underlying price
   **/
  function getUnderlyingPrice() external view returns (uint256);

And the business logic implications in this contract are primarily found in the calculatePremium function, where the premium is divided by 1e8:

  function calculatePremium(
    uint256 _strike,
    uint256 _amount,
    uint256 timeToExpiry,
    uint256 _price
  ) public view returns (uint256 premium) {
    premium = ((IOptionPricing(addresses.optionPricing).getOptionPrice(
      _strike,
      _price > 0 ? _price : getUnderlyingPrice(),
      getVolatility(_strike),
      timeToExpiry
    ) * _amount) / 1e8);
  }

From the audit files it’s clear that the assumption was that the returned price would be in 1e8, but this is Dopex’s own RdpxPriceOracle, so was likely a simple oversight which slipped through testing as a MockRdpxEthPriceOracle was implemented to simplify testing, which mocked the values from the oracle, but only to a 1e8 precision.

Recommended Mitigation Steps

For price feeds where WETH will be token B, it is convention (although not a standard, as far as the reviewer is aware), that the precision returned will be 1e18. See here.

As the sponsor indicated that the team might move to Chainlink oracles, it is suggested to modify the RdpxV2Core, PerpetualAtlanticVault, UniV2Liquidity and the ReLp contracts to work with the returned 1e18 precision, assuming that the keep the token pair as rdpx/WETH.

psytama (Dopex) confirmed and commented:

The issue is in the oracle contract which returns 1e18.

Alex the Entreprenerd (Judge) commented:

Seems like the Warden grouped a bunch of consequences down to the root cause of the oracle precision.

I’ll need to determine how to group / ungroup findings as there seem to be multple impacts but a single root cause.


The original report as published on Code4rena, by LokiThe5th. 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.

What is known

A high-severity security bug in Dopex. Code4rena made it public on 29 December 2023. Found in the 2023-08-dopex audit contest (finding H-07), also found by 16 other wardens.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

More by LokiThe5th

View all

9 more disclosed reports, best first.

More from Dopex

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.