ConnextPriceOracle.getPriceFromDex()
is vulnerable to price manipulation
#104
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Lines of code
https://github.com/code-423n4/2022-06-connext/blob/main/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L99-L115
Vulnerability details
Impact
Getting price data from an oracle can be tricky. There are a lot of pitfalls. One of them is to compute price data using the token balances of a DEX pair. It's very easy to manipulate the price since that approach relies on the price at a single moment. The attacker can take a flash loan, use it to prop up the price of an asset, and thus manipulate the price of the pair within the same transaction. Since they can do it within the same transaction there's virtually no risk for them
Instead of computing the price data through token balances, you should properly integrate the oracle of whatever DEX you want to use. In the case of Uniswap, you're supposed to use the
observe()
function. You get the price by observing the data over multiple blocks. That makes the price manipulation for the attacker way more difficult. They are exposed to other bots that will use the arbitrage opportunity which will put the price back to its original value.Proof of Concept
ConnextPriceOracle computes the price through the token balances:
Tools Used
none
Recommended Mitigation Steps
Properly integrate the DEX oracle or remove it altogether and rely on Chainlink.
The text was updated successfully, but these errors were encountered: