code-423n4 / 2024-03-dittoeth-findings

0 stars 0 forks source link

Financial losses for users possible due to inaccurate liquidations or redemptions. #195

Closed c4-bot-9 closed 6 months ago

c4-bot-9 commented 7 months ago

Lines of code

https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/facets/PrimaryLiquidationFacet.sol#L135 https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/facets/PrimaryLiquidationFacet.sol#L47-L90 https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/facets/PrimaryLiquidationFacet.sol#L47-L90 https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/facets/PrimaryLiquidationFacet.sol#L122-L143

Vulnerability details

Reliance on a single price oracle for critical functions, such as liquidations and redemptions, makes it vulnerable to oracle manipulation or unreliability, potentially leading to financial losses for users.

Issue Description

  • If the oracle price is manipulated or becomes stale, the liquidate function may make incorrect decisions based on the inaccurate price data.
  • This can lead to scenarios where:
  • Undercollateralized positions are not liquidated properly, allowing them to remain open and potentially putting the protocol at risk.
  • Sufficiently collateralized positions are incorrectly liquidated, causing unwarranted losses for users.
  • If the conversion from ETH or LSTs to dETH is not handled accurately, it could lead to discrepancies in user balances.
  • Improper storage or management of deposited funds in Vault and Bridge contracts could result in fund loss.

Impact

Proof of Concept

Let's see a scenario of how reliance on a single oracle in the DittoETH protocol can lead to incorrect liquidations and potential financial losses for users.

  1. Alice opens a short position with an initial collateral ratio of 200% (2x collateralization) on the DittoETH protocol.
  2. The current market price of the asset is $100, and the oracle provides the same price to the protocol.
  3. The liquidation threshold for short positions is set to 150% collateral ratio.
  4. An attacker manipulates the oracle price feed, causing it to report an incorrect price of $150 to the protocol, while the actual market price remains at $100.

PoC Steps:

  1. The attacker manipulates the Oracle price feed, causing it to report an incorrect price of $150 to the protocol.

  2. The liquidate function is called for Alice's short position.

  3. Inside the liquidate function, the _setLiquidationStruct function is invoked to retrieve the oracle price and calculate the collateral ratio.

  4. The LibOracle.getPrice(asset) function returns the manipulated price of $150, which is used to calculate the collateral ratio.

  5. Due to the manipulated oracle price, the calculated collateral ratio for Alice's position falls below the liquidation threshold of 150%, even though the actual market price hasn't changed.

  6. The liquidate function proceeds with the liquidation process, incorrectly liquidating Alice's sufficiently collateralized position.

  7. Alice suffers unwarranted financial losses as a result of the incorrect liquidation.

Code Snippet:

function _setLiquidationStruct(address asset, address shorter, uint8 id)
    private
    returns (MTypes.PrimaryLiquidation memory)
{
    // ...
@>  m.oraclePrice = LibOracle.getPrice(asset); // Retrieves the manipulated price of $150
@>  m.cRatio = m.short.getCollateralRatio(m.oraclePrice); // Calculates the collateral ratio using the manipulated price
    // ...
}

Impact:

Tools Used

Manual Audit

Recommended Mitigation Steps

Assessed type

Oracle

c4-pre-sort commented 7 months ago

raymondfam marked the issue as insufficient quality report

c4-pre-sort commented 7 months ago

raymondfam marked the issue as primary issue

raymondfam commented 7 months ago

Check the LibOracle. It already has fallback to a Uniswap TWAP.

c4-judge commented 6 months ago

hansfriese marked the issue as unsatisfactory: Invalid