Professional Documents
Culture Documents
An Overview of DeFi Price Oracles
An Overview of DeFi Price Oracles
An Overview of DeFi Price Oracles
What is an Oracle?
Oracles are the middlemen that bridge the gap between real-world (off-chain)
services and blockchain (on-chain) protocols. Oracles retrieve off-chain data
and post this data to the blockchain for smart contract consumption. They
also relay messages and instructions from a smart contract to off-chain
external systems. In addition, oracles must also ensure that the data that they
provide is accurate and resistant to manipulation.
A high-level accuracy – The price oracle values should reflect the current
data.
Timeliness – The data from the price oracle should provide accurate data on a
timely basis, preferably every block.
MakerDAO’s price oracles failed during Black Thursday, March 12, 2020, as
high gas prices prevented the Medianizer from updating prices on a timely
basis. ETH fell 43% that day and when MakerDAO’s price oracles were
finally able to update prices, the large price changes led to massive
liquidations where entire vaults were emptied. GlassNode has a really great
write-up detailing the different failure points of MakerDAO on Black
Thursday.
Uniswap v3 is expected to roll out May 5 for Ethereum and May 12 for
Optimism. The team claims it will utilize the same time-weighted average
pricing (TWAP) oracles from v2 with the following upgrades:
A liquidity accumulator is also tracked so users can decide which pools have
the most reliable TWAP.
Users who want a Uniswap v3 price would call the accumulator and take the
values at t1 and t2and calculate the weighted geometric mean price via the
following equation.
The new improvements to the TWAP allow for cheaper calculations for
moving averages and for outlier analysis. The liquidity accumulator also
allows smart contracts to determine which oracles are trustworthy based on
their liquidity. This should reduce the volatility of Uniswap’s price oracles
and reduce mispricings in the smart contracts that utilize them.
Compound uses a mix of off-chain and on-chain price sources for their
oracles. Authorized price sources (“reporters”) can be centralized exchanges,
DeFi protocols, applications, and OTC trading desks. The aggregator contract
receives prices from reporters and verifies them before calculating the median
value. The median value is then published to the Compound market. The
aggregator’s verification logic checks if the new price is within an upper and
lower bound anchor price provided by the anchor contract. If the new price is
outside of those bounds, then the new price is discarded and the reference
price is not updated. Compound holders control the administrators which set
and change the parameters of the aggregator - minimum number of reporters
required to update a price, the address of the anchor contract, and tolerance
rate to determine the upper and lower bounds. Compound holders also dictate
the collateral factor, source of the oracle, and any interest rate model
adjustments.
Synthetix Oracles (On-chain centralized)
The Coinbase price oracle uses the Coinbase Pro API as the source of the
price data. Anyone can publish the prices on-chain since the data is signed
with Coinbase’s private key. This enables users to verify the data authenticity
using Coinbase’s public key. Coinbase also implements an off-chain filter to
reject extreme data points that deviate from the expected volatility range of
prices. It also uses the Compound open oracle’s ‘anchor’ contract as an on-
chain check. If the price of the oracle is too far away from the anchor price, it
is rejected and not pushed to the blockchain.
Index pricing – Index platforms (e.g. Set) use oracles to retrieve the prices of
the index components.
Conclusion
Each oracle, on-chain or off-chain, has its own benefits and weaknesses.
Whether or not Ethereum price oracles will suffer another Black Thursday
MakerDAO meltdown is still yet to be determined. When evaluating oracles,
it helps to keep in mind the following attack vectors:
51% attack: Does a single entity own or a group collude to control a majority
of nodes? The majority can then control which price feeds are used and what
data is considered the absolute truth.
Mirroring attack: Can an oracle node share its data to other nodes that it
controls? False information can spread easily like a game of telephone.
Data manipulation: Are the oracles receiving data from trusted sources?
External data providers could be sending manipulated or bad data.
Liveliness issue: Are the oracles or nodes pushing data on-chain in a timely
manner? Oracle or node updates could be halted either intentionally or
unintentionally causing devastating effects to the smart contracts that depend
on them.