Crypto & Web3 · Explainer
Blockchain oracles: architecture and risks
In decentralized finance, what decides whether a loan gets liquidated is a number: the price reported by the oracle. Understanding where that number comes from and how it can be distorted explains a large share of attacks on DeFi protocols.
- Author:
- Redação Token & Tech
- Responsible editor:
- Daniel Ferreira
- Translation:
- Redação Token & Tech
Published · 8 min read
Originally published in Brazilian Portuguese.
Translated from the Portuguese original with AI assistance.
Also available in: Português
Key points
- A DeFi protocol does not know the price of anything on its own. It reads an oracle, which may be the price on a decentralized exchange, a time-weighted average (TWAP) or a network of several operators.
- Relying on the spot price of a single pool is risky: with a flash loan, someone can distort it for an instant and borrow more than they should.
- A manipulated price is not the only risk. A delayed or frozen price, caused by congestion or a network outage, can also trigger wrong liquidations or fail to trigger the right ones.
A lending protocol in decentralized finance (DeFi) accepts one token as collateral and releases another as a loan. To know how much it can lend, and when to liquidate the collateral, it needs to know what the token is worth right now. The contract has no way of finding that out on its own.
The one who tells it is the oracle: the service that brings data from outside into the smart contract. The general concept, and the case of physical assets such as gold and real estate, is covered in Oracles: how a physical asset reaches the blockchain. The focus here is different: the architecture of the price oracles used in DeFi and the attacks that exploit their weaknesses. If you are new to the sector, start with DeFi: what decentralized finance is.
Why the contract cannot fetch the price itself
Every computer on a blockchain runs the same contract and must reach the same result. According to NIST, the US standards institute, that is why contracts cannot query the internet directly: external data has to come in as a parameter, through oracles (NIST, NISTIR 8202).
The Ethereum documentation sums up the consequence: if the oracle delivers wrong data, the contract executes correctly on a wrong input. This is the so-called oracle problem (ethereum.org, Oracles).
How an oracle is built
The Ethereum documentation describes two usage patterns:
- Continuous publication (feed): the oracle updates a value, such as the price of ETH in dollars, and contracts read that value when they need it.
- Request and response: the contract asks for a specific piece of data, the oracle fetches it off-chain and returns the answer in a later transaction. Whoever asks pays for the lookup.
In a decentralized price feed, the chain usually has four links. The documentation of Chainlink, one of the oracle networks cited by ethereum.org, describes its model this way (Chainlink, Decentralized Data Model):
- Data sources: providers and markets where prices come from.
- Independent operators: each queries the sources and publishes a value.
- Aggregator contract: gathers the responses and forms a single value. If it does not receive a minimum number of responses, the value is not updated.
- Consumer contract: the DeFi protocol, which reads the aggregated value.
The same documentation explains when the value changes: a new round starts when the off-chain price moves away from the recorded value by more than a deviation threshold, or when a maximum time interval has passed since the last update, the so-called heartbeat. Whichever happens first triggers the update.
Decentralized networks also use economic mechanisms. Ethereum.org mentions operators staking tokens as collateral, with penalties for those who deviate from the majority, and reputation based on track record. It also notes a limit: these incentives do not prevent an operator from simply copying the others without verifying anything.
Three ways to get a price
| Price source | How it works | Main weakness |
|---|---|---|
| Spot price from a decentralized exchange | The contract reads the current price of a liquidity pool | Can be distorted by a single large trade |
| Time-weighted average price (TWAP) | The contract uses the average of prices over a window | More expensive to manipulate, but reacts with a lag |
| Decentralized oracle network | Several operators query several sources and the value is aggregated | Depends on source quality and update frequency |
Newsroom summary based on ethereum.org, the Uniswap documentation and the Chainlink documentation.
Attack 1: distorting the price with a flash loan
A flash loan is an uncollateralized loan that exists only within a single transaction: if the amount and fee are not repaid by the end of it, everything is reverted as if it never happened (Aave, Flash Loans). It gives anyone, for a few seconds, access to a lot of capital.
Ethereum.org describes how this becomes an attack (ethereum.org, smart contract security):
- The attacker takes out a flash loan.
- They use the money to buy a large amount of a token in a pool, which pushes that pool’s price up.
- In the same transaction, they deposit the token as collateral in a lending protocol that reads the price from that pool.
- The protocol sees inflated collateral and releases a larger loan than it should.
- The attacker repays the flash loan and keeps the difference. The loss stays with the protocol.
According to the same page, attacks of this kind have already cost protocols millions. The OWASP list of smart contract risks places price oracle manipulation among its top items, as we showed in how to investigate the security of a DeFi protocol.
Why a time average helps, and what it costs
The decentralized exchange Uniswap built a mechanism for this into version 2 of its protocol (Uniswap, v2 documentation). Each pool records the price at the start of each block, before that block’s trades, and accumulates this value weighted by time. A contract can read the accumulator at the start and end of a period and compute the TWAP (time-weighted average price).
The documentation makes three useful observations:
- If a lot of value depends on the price of a single block, the profit from an attack tends to exceed the cost.
- With a TWAP, the cost of manipulation grows roughly in proportion to the pool’s liquidity and the length of the time window.
- Small pools and short windows remain vulnerable, and factors such as network congestion can make the attack cheaper.
In the newsroom’s assessment, the price of protection is lag. A one-hour average resists a distortion lasting seconds better, but it is also slow to reflect a real, sharp market drop. Whoever chooses the window is choosing between two risks.
Attack 2: manipulating the sources, not the oracle
An oracle network that queries several sources solves the single-pool problem. It does not solve the case in which the sources themselves are easy to move.
The Mango Markets case illustrates the point. According to the complaint by the US Commodity Futures Trading Commission (CFTC), on October 11, 2022 a trader opened large leveraged positions tied to the price of the MNGO token and then bought large amounts of that token on three exchanges that fed the platform’s oracle. The price reported by the oracle allegedly rose more than 13-fold in about 30 minutes. With the inflated positions as collateral, he allegedly withdrew more than US$ 110 million, draining most of other users’ deposits (CFTC, January 9, 2023).
The legal outcome shows the issue is not simple. In May 2025, a federal judge in New York overturned the criminal convictions obtained in 2024, finding, among other things, that the case had been brought in the wrong venue and that it had not been proven that the defendant made false statements on a platform with no rules prohibiting that use (The Block, May 24, 2025). From a technical standpoint, however, the mechanism described is the same: a price from a thinly traded source, deliberately moved, accepted as truth by the contract.
Chainlink itself gives this warning in its documentation: assets with high market risk, such as illiquid ones, are the most vulnerable to manipulation, and it is up to the protocol developer to monitor and mitigate that risk (Chainlink, Developer Responsibilities).
Risk 3: delayed or frozen price
An oracle also fails when it stops. A stale price can be as dangerous as a false one: it can prevent liquidations that should happen or allow trades at values that no longer exist.
The Chainlink documentation points to some causes (Chainlink, Selecting Quality Data Feeds):
- Network congestion or outage: a feed’s performance depends on the blockchain it runs on. During congestion, the update frequency can drop.
- Single source: some feeds depend on just one provider. The documentation recommends controls to detect delayed, missing or unexpected values.
- Extreme events: attacks, stablecoin depegs or failures of blockchain bridges can push the price of a “wrapped” asset away from the original asset.
On layer-2 networks (the rollups explained in how rollups work), there is a specific case: if the sequencer, the component that orders transactions, goes down, updates stop. The documentation suggests that the protocol check this status and wait for a grace period after it comes back, to avoid mass liquidations at outdated prices.
How protocols usually defend themselves
The measures below appear in the cited documentation. The description is informational, not a recommendation of any protocol or provider.
- Do not rely on the spot price of a single pool. Ethereum.org points to decentralized oracle networks and TWAPs as the basic defenses.
- Check the age of the data. The contract can reject a price whose last update is older than expected.
- Limits and circuit breakers. Chainlink describes circuit breakers, mechanisms that monitor frozen prices, sharp swings or out-of-range values and can pause the contract.
- Caution with illiquid assets, which are the easiest to move.
Note that pausing a contract requires someone to have the power to do so. That power is itself a risk, as we explain in smart contracts with admin keys. And the choice of oracle involves a trade-off already pointed out by the Bank for International Settlements (BIS): decentralizing as much as possible brings complexity and loss of efficiency, while centralizing reintroduces parties that must be trusted (BIS, Bulletin 76).
Questions for understanding a protocol’s oracle
- Where does the price come from? A pool, a time average or an oracle network? From how many sources?
- Do the assets accepted as collateral have enough liquidity on the sources that feed the oracle?
- What does the contract do if the price stops updating? Is there a data-age check?
- Are there circuit breakers or a pause, and who can trigger them?
- Did the audit cover the oracle integration, and not just the core code? See the limits of a review in smart contract audits.
Depositing funds in DeFi protocols carries the risk of total loss, including from oracle failure, without the protection of a deposit guarantee fund.
Key takeaways
- The smart contract blindly trusts the price it receives. A DeFi protocol’s security depends on how that price is obtained, aggregated and updated.
- The spot price of a single pool is the classic target of flash loan attacks. Time averages and multi-source networks make the attack more expensive, but not impossible, especially with illiquid assets.
- A stale price is also a risk. Ask what the protocol does when the oracle stops, and who has the power to pause the system.
Sources
- NISTIR 8202 – Blockchain Technology Overview, National Institute of Standards and Technology (NIST). Published October 1, 2018 · Accessed October 8, 2026
- Oracles, ethereum.org. Accessed October 8, 2026
- Smart contract security, ethereum.org. Accessed October 8, 2026
- Flash Loans, Aave (documentação oficial). Accessed October 8, 2026
- Oracles (Uniswap v2 concepts), Uniswap Labs. Accessed October 8, 2026
- Decentralized Data Model, Chainlink (documentação oficial). Accessed October 8, 2026
- Selecting Quality Data Feeds, Chainlink (documentação oficial). Accessed October 8, 2026
- Developer Responsibilities: Market Integrity and Application Code Risks, Chainlink (documentação oficial). Accessed October 8, 2026
- The oracle problem and the future of DeFi (BIS Bulletin No 76), Bank for International Settlements (BIS). Published September 7, 2023 · Accessed October 8, 2026
- CFTC Charges Avraham Eisenberg with Manipulative and Deceptive Scheme to Misappropriate Over $110 million from Mango Markets, a Digital Asset Exchange (Release 8647-23), Commodity Futures Trading Commission (CFTC) (US). Published January 9, 2023 · Accessed October 8, 2026
- U.S. judge overturns fraud convictions of Mango Markets exploiter Eisenberg, determining improper venue, The Block. Published May 24, 2025 · Accessed October 8, 2026
Educational content. Not investment advice. This article is educational and informative. It is not a personalized recommendation to buy, sell or hold any asset. Crypto-assets and tokenized assets carry risks, including total loss; rules vary by jurisdiction.