code-423n4 / 2023-08-dopex-findings

3 stars 3 forks source link

Potential rug-pull vector by changing Oracle address #694

Open code423n4 opened 1 year ago

code423n4 commented 1 year ago

Lines of code

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

Vulnerability details

Impact

setPriceingOracleAddress allows to change the address of the oracles. By setting a malicious oracles, the price manipulation is possible.

Malicious admin can change the address of the oracle to manipulate the current prices of the assets in the protocol. While rug-pull vectors which straightforwardly allows to withdraw all the funds from the protocol are nothing new in the DeFi ecosystem - this attack vector is slightly different. Instead of withdrawing the funds, malicious admin manipulates the price of the assets inside the protocol - to his advantage. One of the example of this attack vector happened very recently: 25th August 2023 - https://twitter.com/PeckShieldAlert/status/1694946221788729440 . Thus I've decided to report this issue as separate finding and evaluated it as Medium.

Even if the DEFAULT_ADMIN_ROLE is trustworthy, having a rug-vector in the contract may have a negative impact on the protocol's reputation. Multiple online tools reports contract with rug-pulls vector as a high-risk: (e.g.: https://twitter.com/RugDocIO/status/1411732108029181960). Even this function had been created with good intentions, it's often associate with rug pull, especially that rug pulls are not uncommon in DeFi. Rug pull vectors increases a risk for investors to lose their hard earn money, thus it has a negative impact on the smart contract's reputation.

Similar findings which had been classified at Code4rena as Medium:

Having this function available is not only a huge red flag for the Investors, but it is also huge centralization risk. The DEFAULT_ADMIN_ROLE is being set in constructor and it's a single EOA.

Having a single EOA as a single DEFAULT_ADMIN_ROLE role is a large centralization risk and a single point of failure. A single private key may be taken in a hack, or the sole holder of the key may become unable to retrieve the key when necessary.

User with DEFAULT_ADMIN_ROLE role holds a lot of power within the contract. Compromise of account with this role puts the contract's integrity at risk.

The very similar issue had been evaluated during a previous Code4rena audit as an issue with Medium severity:

Moreover, it's crucial to notice, that such a important function - as setPriceingOracleAddress does not implement any timelock mechanism, which would give protocol's users a change to properly react in case of emergency.

Proof of Concept

File: contracts/core/RdpxV2Core.sol

  function setPricingOracleAddresses(
    address _rdpxPriceOracle,
    address _dpxEthPriceOracle
  ) external onlyRole(DEFAULT_ADMIN_ROLE) {
    _validate(_rdpxPriceOracle != address(0), 17);
    _validate(_dpxEthPriceOracle != address(0), 17);

    pricingOracleAddresses = PricingOracleAddresses({
      rdpxPriceOracle: _rdpxPriceOracle,
      dpxEthPriceOracle: _dpxEthPriceOracle
    });

    emit LogSetPricingOracleAddresses(pricingOracleAddresses);
  }

Since RdpxV2Core inherits from AccessControl - there's a grantRole() function available which allows to create more than one user with DEFAULT_ADMIN_ROLE role. This increases the risk, since in a group of accounts (with DEFAULT_ADMIN_ROLE role), the more users, the higher the risk is that one of them will become malicious or will become a victim to a hack (e.g. got their private key stolen) - due to previously mentioned centralization risk.

Tools Used

Manual code review

Recommended Mitigation Steps

Critical admin functions should be protected by timelock - to give users a chance to react when something malicious would be happening.

Severity Evaluation

Assessed type

Rug-Pull

bytes032 commented 1 year ago

Over inflated

c4-pre-sort commented 1 year ago

bytes032 marked the issue as low quality report

c4-judge commented 1 year ago

GalloDaSballo changed the severity to QA (Quality Assurance)