Oracle with Validation
Oracle with Validation is a Morpho-compatible oracle type designed to limit the impact of oracle provider failures such as compromise or manipulation. The Oracle with Validation cross-validates a primary oracle price against a validation oracle price before allowing any take to proceed, always returning the primary oracle's price but reverting if the two feeds diverge beyond a configured deviation threshold.
For example, a cbBTC collateral market with USDC loan token can use Chainlink BTC/USD as the primary oracle price and Redstone BTC/USD as the validation oracle price, with a 10% deviation threshold. As long as the two feeds stay within 10% of each other, the market behaves normally using the Chainlink oracle price. If one feed is manipulated or compromised and the two feeds diverge by more than 10%, the deviation check trips and all borrow, withdraw collateral, and liquidation actions are blocked until the discrepancy resolves.
This design is intended for liquid markets where multiple oracle providers or onchain sources track prices with high fidelity.
Price calls revert whenever the two feeds are outside the deviation limit. The revert also prevents liquidations from being executed during that time. A threshold that is too narrow can be dangerous. A narrow threshold trades direct manipulation risk for liquidation-availability risk. See Sizing MAX_ORACLE_DEVIATION for the bounds to respect.
Oracle architecture
The contract uses two independent oracle sources.
Primary oracle:
- The main price source, such as Chainlink.
- Its price is always returned to callers unless the deviation check against the validation oracle triggers.
- Must return a non-zero price.
Validation oracle:
- Secondary price source used purely for validation, such as a TWAP, Chronicle, or Redstone feed.
- Used to detect price manipulation or primary oracle failures.
- Deviation is checked against the primary oracle.
- Its price is never returned to callers and is never read by the Morpho market. It only gates whether the primary price is allowed through.
The absolute deviation is computed as . The maximum allowed deviation is
If , the price call reverts and the primary value is withheld.
Price validation
When price() is called, the contract runs these checks in order:
- Fetches the price from the primary oracle.
- If
validationCheckPausedistrue, returns the primary price immediately. - Otherwise, fetches the price from the validation oracle and computes the absolute deviation. Reverts with
ExcessiveOracleDeviationif it exceeds . - Returns the primary price.
If the primary oracle returns zero and the validation oracle returns nonzero, the deviation check reverts with ExcessiveOracleDeviation. If both return zero, price() returns zero to Morpho (Morpho handles the zero-price case).
Sizing MAX_ORACLE_DEVIATION
MAX_ORACLE_DEVIATION is expressed in 18 decimals, for example, 5e16 for 5%. It is immutable after deployment.
For Morpho markets, the deployer will typically want the deviation threshold to stay below the market's bad-debt buffer , where
is the collateral's maximum liquidation incentive factor. A liquidation seizes collateral worth , so it can clear at most of debt: the liquidation incentive uses part of the