Beginner FriendlyFoundryDeFiOracle
100 EXP
View results
Submission Details
Severity: medium
Valid

Vulnerability in Oracle Usage Leading to Potential Price Manipulation

Vulnerability Details

The ThunderLoan protocol uses an oracle system to determine the price of tokens in WETH for the purpose of calculating fees during deposits, redemptions, and flash loan operations. Specifically, the OracleUpgradeable contract fetches the price from a TSwapPool via the getPriceInWeth function:

function getPriceInWeth(address token) public view returns (uint256) {
address swapPoolOfToken = IPoolFactory(s_poolFactory).getPool(token);
return ITSwapPool(swapPoolOfToken).getPriceOfOnePoolTokenInWeth();
}

This design presents several vulnerabilities:

  • Single Source Oracle: The oracle relies on a single liquidity pool for price information, which could be inaccurate due to low liquidity or deliberate price manipulation.

  • Oracle Manipulation Risk: An attacker may exploit the market by manipulating the TSwapPool price right before a transaction that relies on the oracle.

  • Lack of Validity Checks: The contract does not verify if the returned pool address is a contract or has the expected interface.

  • No Oracle Diversification: The use of a single oracle source increases the risk of price manipulation.

Impact

If an attacker successfully manipulates the oracle's reported price, they could:

  • Pay less fee for a flash loan than they should, reducing protocol revenue.

  • Artificially inflate the value of the collateral during a deposit, allowing them to mint more asset tokens than is fair.

  • Decrease the value of the collateral during redemption, causing the protocol to release more underlying tokens than appropriate.

This could lead to financial loss for the protocol and its users, erosion of trust in the protocol's reliability, and potentially the protocol's insolvency if the funds in the pool are drained due to the manipulation.

Recommendations

To mitigate the risks identified, the following recommendations should be implemented:

  • Decentralized Oracle Networks: Integrate with a decentralized oracle network like Chainlink to obtain price feeds. This will make manipulation much more difficult due to the higher liquidity and aggregation of multiple data sources.

  • Validity Checks: Implement checks to ensure that the pool returned by the IPoolFactory is a valid and properly functioning contract.

  • Oracle Diversification: Use multiple independent oracles and take the median or a weighted average of their responses to obtain price data. This reduces the impact of any single oracle being manipulated.

  • Slippage Protection: Add mechanisms to protect against large price swings or slippage. Consider using TWAPs (Time Weighted Average Prices) to compare against the current price, which can serve as a reference to detect and prevent manipulation.

  • Continuous Monitoring and Circuit Breakers: Continuously monitor oracle prices for anomalies and consider implementing circuit breakers that pause operations if price deviations exceed a certain threshold.

By implementing these recommendations, ThunderLoan can significantly increase the security and reliability of its pricing mechanisms, thereby protecting itself and its users from potential manipulation and losses.

Updates

Lead Judging Commences

0xnevi Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

weak oracle

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.