Validate a price before using it
By the end, explain the diagram in your own words, solve the case and justify the correction.
Prerequisites : Chainlink and the oracle problem · Ethereum accounts and transactions
Level 2 · Intermediate →Reading path · 13 / 35 · Intermediate
A price feed needs checks of asset, network, decimal scale and freshness.
The essentials
Data Feeds aggregate observations and expose results to applications, commonly through a proxy pointing to an aggregator. This separation can support upgrades without changing the address consumed by an application. It also means that administrative arrangements matter.
How it works
Publication may depend on a deviation threshold or heartbeat interval. A feed is not necessarily a tick-by-tick price stream. Consumers should check the exact asset, network, decimal scale and timestamp, and define what happens when data becomes stale or unsuitable.
What to watch
For example, treating an eight-decimal answer as an eighteen-decimal answer creates a severe valuation error even when observations are accurate. Multiple operators do not eliminate correlated data failures. On a Layer 2, applications may also need to account for sequencer downtime and a grace period before resuming sensitive actions.
Understand the details
A price feed is an interface to a specific reported value, not a universal market price. Integrations must confirm the network, feed address, base and quote assets, decimal scale and update time. Updates may depend on a time interval or a deviation condition, depending on the feed. A transaction can execute between two updates.
Boundaries and common mistakes
Freshness limits should match the application’s risk and feed configuration. Rejecting every small delay can stop a service unnecessarily; accepting arbitrarily old values can misprice collateral. Some L2 integrations also need to consider sequencer availability and recovery behavior. A fallback must have its own validation rules.
The mechanism at a glance
- Check network and pair
- Normalize decimals
- Check time and status
- Use or reject value
Apply the lesson to a case
A fictional feed returns 25000000000 with eight decimals. Its timestamp is two hours old, while this exercise’s application accepts at most thirty minutes. Prepare a validation table before calculating any collateral value. These are example limits, not recommended production settings.
The value is 250 quote units, but it fails the stated freshness rule. Correct decimal conversion does not rescue stale data. Record a controlled failure or a separately validated fallback instead of silently treating the number as current.
From a market price to a contract
Sources
Observations originate from selected markets and data providers. Market quality affects input quality.
Check your understanding
2 units of its quoted denomination, not 200 million. The denomination and update time still need checking.
Prepare a correction note
Describe the passage and the proposed correction. This creates a local note for you to share; it sends nothing. Do not include personal or confidential information.