Solana oracle risks: eight checks for protocol teams
Most oracle bugs on Solana come from the program trusting a price it should have rejected: too old, from the wrong feed or account, too uncertain, or read with the wrong exponent.
Before mainnet, check eight things: age, feed ID, account owner, confidence, exponent, how easy the source is to move, who picks the update, and what the program does when the feed fails.
Eight oracle checks before mainnet
| Risk | What goes wrong | What to do |
|---|---|---|
| 1. Stale price | The program acts on a price from minutes ago | Enforce a maximum age and reject older updates |
| 2. Wrong feed | A valid update for another asset is passed in | Check the feed ID on every read |
| 3. Fake account | An account not written by the oracle is accepted | Check the account owner (Anchor typed accounts do it) |
| 4. Wide confidence | The price is uncertain during volatility | Use the cautious side of the interval; pause above a threshold |
| 5. Exponent | Price is off by powers of ten | Apply the feed exponent and the token decimals in tests |
| 6. Thin source | A pool price is pushed for one block | Do not use a single pool spot price as an oracle |
| 7. Update choice | The user posts the update that suits them | Keep the age window short; consider delayed settlement |
| 8. Outage | No fresh price for hours | Decide in advance what pauses and who can resume |
The same checks apply to every price feed you read, whichever oracle network provides it.
Key takeaways
- An oracle is only as safe as the checks your program runs when it reads it.
- Reject old prices, prices for the wrong feed and accounts the oracle did not write.
- Use the confidence interval: value collateral on the low side, debt on the high side, and pause when it gets too wide.
- Never use one pool spot price as a price feed for lending or liquidations.
- Plan the outage: what pauses, who decides, and how you resume. Put oracle settings behind a multisig.
A lending market, perps exchange or vault does not see prices. It reads an oracle account and trusts what is inside.
Auditors spend time on these reads because a wrong price turns into a wrong liquidation, a bad trade or an empty vault in one transaction. This guide lists the checks that protocol teams should own, whichever oracle they use.
How a Solana program reads a price
On Solana the common pattern is a pull oracle. Someone, often the user or a keeper, posts a signed price update to an account, and the program reads that account in the same or a later transaction.
With Pyth, the program receives a PriceUpdateV2 account and asks for a price no older than a limit, for one feed ID:
// Anchor: the typed account checks that the Pyth receiver program owns it
pub price_update: Account<'info, PriceUpdateV2>,
// in the instruction
let maximum_age: u64 = 30; // seconds, your own limit
let feed_id: [u8; 32] = get_feed_id_from_hex(FEED_ID_HEX)?;
let price = price_update.get_price_no_older_than(&Clock::get()?, maximum_age, &feed_id)?;
// price.price, price.conf and price.exponent: value = price * 10^exponent
Pyth documents that such an account only guarantees a verified price for some feed at some point in time. Which feed and which time are your checks.
Price update accounts can be created, overwritten and closed by anyone, so the program must never assume it got the one it expected.
The eight checks
- Age: pick a maximum age that fits your product and enforce it on every read. A liquidation engine needs a tighter limit than a dashboard. Monitor the feed age too, not only the program.
- Feed ID: store the expected feed ID per market and compare it on every read. Without it, a valid update for a cheaper asset can be passed in.
- Owner: the account must be owned by the oracle program. Anchor typed accounts check this; in native Rust you write the check yourself.
- Confidence: Pyth publishes a confidence interval next to each price. Its docs suggest the lower bound to protect against a price pushed down and the upper bound against one pushed up, and pausing new activity when confidence divided by price passes a threshold.
- Exponent and decimals: price and confidence share one exponent. Convert once, in one helper, and test it against token decimals with real values.
- Source quality: a spot price from one AMM pool can be moved inside a single transaction, often with borrowed funds. Use a feed that aggregates many sources, and be careful with assets that trade thinly anywhere.
- Who picks the update: in a pull model the caller decides which valid update to post. Within your age limit they can choose the one that helps them most. A short window, a spread based on confidence, or delayed settlement reduce that edge.
- Failure mode: some feeds stop updating outside market hours, and any feed can go quiet. Decide which instructions stop when the price is stale or too uncertain, and which, such as repaying debt, should still work.
The SDK also lets you post partially verified updates to save transactions. Decide which verification level your program accepts, and say so in the audit scope.
Admin control over the oracle is part of the risk. If one key can change the feed ID, the maximum age or the confidence threshold, that key can set a price. Put these settings behind the same multisig and timelock as the upgrade authority.
What to test before launch
- Rejections: tests that pass an old update, an update for another feed and an account with the wrong owner, and expect each to fail.
- Extremes: a price near zero, a very wide confidence interval, and a sudden move of 50% between two reads.
- Math: the exponent conversion and rounding in collateral, debt and liquidation formulas, checked against hand-computed values.
- Pause path: which instructions stop when the oracle fails, and that users can still exit where you promised they can.
Add oracle freshness to your alerts, as described in our guide to Solana program monitoring and alerts, and write the stale-price case into your incident response plan.
Account checks for oracle accounts follow the same rules as any other account in the Anchor security checklist.
What to tell your auditor
List every price you read, the oracle and feed for each, your maximum age, how you use confidence, and what happens on failure. Put it in the scope so the review covers the reads and the admin settings, not only the math.
Our guide on how to write an RFP for a smart contract audit shows where it fits, and the Solana pre-launch security checklist covers the rest of launch week. To find a reviewer, browse the Solana smart contract audit providers we have checked.
Frequently asked questions
What is an oracle on Solana?
A service that brings off-chain data, usually asset prices, on-chain. The oracle network writes signed prices into accounts, and a Solana program reads those accounts and decides whether to trust them.
What is a stale price and how do I prevent it?
A price that was correct some time ago but not now. Set a maximum age that fits your product and reject older updates on every read. With Pyth, get_price_no_older_than takes that age and the expected feed ID.
How should a protocol use the Pyth confidence interval?
Pyth documents the lower bound as protection against a price pushed down and the upper bound against a price pushed up, and suggests pausing new activity when confidence divided by price passes a threshold you choose.
Can I use an AMM pool price as an oracle?
Not for lending, liquidations or anything that moves funds on the price. A single pool spot price can be moved inside one transaction. Use a feed that aggregates many sources.
What should happen when the oracle stops updating?
Decide before launch. Usually new borrowing, trading or liquidations that need a fresh price stop, while actions that reduce risk, such as repaying debt, keep working. Write it into the incident plan.
Need a review of your oracle integration? Tell us what you are launching. We suggest audit providers we checked by hand, with a reason for each. Free for teams. Get matched →
Looking for help with this? Browse Solana smart contract audit providers, or describe your project and get matched for free.
Originally published on Orivions.
Comments
No comments yet. Start the discussion.