Rigoblock Documentation
  • Welcome
  • Introduction to RigoBlock
  • Contracts
    • Protocol
      • RigoblockPoolExtended
      • Core
        • constants
        • immutables
        • storage
        • actions
        • owner actions
        • abstract
        • fallback
        • initializer
        • state
        • storage accessible
      • Deps
        • Authority
          • authority docs
        • PoolRegistry
          • pool registry docs
      • Extensions
        • AGovernance
          • Solidity API
        • AMulticall
          • aMulticall docs
        • AStaking
          • aStaking docs
        • AUniswap
          • aUniswap docs
        • EUpgrade
          • eUpgrade docs
        • EWhitelist
          • eWhitelist docs
      • Proxies
        • proxy
          • proxy docs
        • proxy factory
          • proxyFactory docs
    • GRG Token
      • RigoToken
        • rigoToken docs
      • Inflation
        • inflation docs
      • ProofOfPerformance
        • pop docs
    • GRG Staking
      • GrgVault
        • grgVault docs
      • StakingProxy
        • stakingProxy docs
      • Staking
        • staking docs
    • Governance
      • Solidity API
  • Deployments
    • deployed contracts - V4
    • deployed contracts
    • v1.5.0
    • v1.4.2
    • v1.4.1
    • v1.3.0
    • v1.1.1
    • v1.1.0
  • Governance
    • Rigoblock Governance
    • Supported Applications
    • Token Whitelists
    • Supported Methods
      • Selectors - V4
      • Selectors - V3
  • Bug Bounty
    • Known Issues
  • Oracles and Price Feeds
Powered by GitBook
On this page
  • Overview
  • Key Features
  • Architecture
  • Block-Manipulation Resistance
  • Integration Guide
  • Using an Existing Price Feed
  • Automatic Backrunning
  • Oracle Deployments
  • Further Reading

Oracles and Price Feeds

Reliable Price Feeds for Token Prices

Overview

Oracles are essential for providing reliable price data to smart contracts in decentralized finance (DeFi). Our oracle system, built as a Uniswap V4 hook, delivers block-manipulation resistant price feeds for on-chain token pairs, across chains using consensus mechanisms like Proof of Stake (PoS), Proof of Authority (PoA), and sequencer-based systems (e.g., Ethereum L2s). Our oracle offers a robust, on-chain solution optimized for DeFi applications requiring secure and manipulation-resistant price data.

Key Features

  • Proof of Stake Resistance: Mitigates price manipulation across various consensus mechanisms by leveraging Uniswap V4 hooks and automatic backrunning.

  • On-Chain Price Feeds: Provides pricing data for on-chain token pairs, eliminating reliance on off-chain data sources.

  • Automated Backrunning: Executes backrunning within the hook to revert price manipulations, ensuring minimal user intervention.

  • Single Oracle per Trading Pair: Simplifies deployment with one oracle per trading pair, reducing complexity and attack vectors.

  • Truncated Geomean Oracles: Caps tick movement per block to limit manipulation, with safeguards for multi-block scenarios.

  • Full Range Liquidity: Uses maximum tick spacing and full range to ensure uniform liquidity, enhancing resistance to manipulation.

Architecture

The oracle system is built as a Uniswap V4 hook, capturing price observations at the start of each block and processing them to resist manipulation. Key components include:

  • Observation Storage: Records the last block’s price observation at the first transaction, capturing a non-manipulated state.

  • Automatic Backrunning: Protects against price manipulations within the same or subsequent blocks by executing backrunning transactions, limiting tick delta to ~2280 ticks per block.

  • Tick Spacing and Range: Configures pools with maximum tick spacing and full range for robust liquidity and manipulation resistance.

  • Manipulation Detection: Monitors tick deltas to detect and counteract manipulation attempts, increasing the cost of attacks.

Block-Manipulation Resistance

The oracle is designed to resist price manipulation in various consensus environments:

  • PoS Chains: Mitigates multi-block attacks by limiting tick movement and using backrunning to deter attackers, even when validators can predict block proposers.

  • PoA and Sequencer-Based Systems: Ensures price feed integrity in Ethereum L2s or other chains with centralized or semi-centralized block production.

  • Economic Deterrence: Automatic backrunning raises the financial cost of manipulation, making attacks economically unviable.

Integration Guide

Prerequisites

  • Familiarity with Uniswap V4 and its hook system.

  • Access to an Ethereum development environment (e.g., Hardhat, Foundry).

  • Choose an available deployment (listed at the end of this page).

Using an Existing Price Feed

To retrieve price data from an existing Uniswap V4 pool with liquidity and an attached oracle hook, call the observe method on the hook contract.

Example: Fetching Price Data (TWAP)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IOracleHook {
    function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
}

contract PriceFeedConsumer {
    IOracleHook public oracleHook = IOracleHook(ORACLE_HOOK_ADDRESS);

    function getLatestPrice() external view returns (int24 tick) {
        uint32[] memory secondsAgos = new uint32[](2);
        secondsAgos[0] = 0; // Latest observation
        secondsAgos[1] = 1; // Previous observation

        (int56[] memory tickCumulatives, ) = oracleHook.observe(secondsAgos);
        tick = int24((tickCumulatives[0] - tickCumulatives[1]) / 1); // Calculate average tick
        return tick;
    }
}
  • Query TWAP tick on Sepolia: Use the different of two tick points to extract the TWAP. Make sure you set a time delta appropriate for your application (5-minutes, 30-minutes).

  • Tick to Price: Convert the returned tick to a price using Uniswap’s tick-to-price formula.

Creating a New Price Feed

To create a new price feed for a token pair:

  • Initialize a Uniswap V4 Pool:

    • Initialize a new pool via the Uniswap V4 Pool Manager, using the oracle hook.

    • Set maximum tick spacing and full range liquidity (initialization will fail otherwise).

    • Be mindful about correctly setting the initial price, as otherwise the hook will need to get in par with other pools ≃ 10% per block (manually or via arbitrage) once liquidity is provided (10% per second on sub-second chains).

// Example: Initialize pool with oracle hook (simplified)
import "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";

contract PoolInitializer {
    IPoolManager public poolManager = IPoolManager(POSM_ADDRESS);
    address public oracleHook = ORACLE_HOOK_ADDRESS;

    function createPool(
        address token0,
        address token1,
        uint24 fee,
        int24 tickSpacing
    ) external {
        poolManager.initialize(token0, token1, fee, tickSpacing, oracleHook);
    }
}

Add Liquidity:

  • Provide liquidity to the pool to enable trading and price discovery (full range).

  • Your position will be modified via arbitraged if price feed tick is not in line with market.

Verify Oracle Functionality:

  • Call the observe method to confirm the oracle is providing price data.

  • Test manipulation resistance by simulating large swaps and verifying tick stability.

  • If you created the price feed, make sure you increase pair cardinality by calling the `increaseCardinalityNext` method in the BackGeoOracle contract, to increase its robustness (with a cardinality of 1, the extracted TWAP will only return the last stored tick, making it susceptible to manipulation).

Automatic Backrunning

The oracle hook automatically executes backrunning to counteract price manipulations, requiring no user intervention. The hook:

  • Monitors tick deltas during swaps.

  • Triggers backrunning if the tick delta exceeds ~2280 ticks per block.

  • Reverts manipulations by adjusting liquidity or executing counter-swaps within the same or next block.

This ensures the price feed remains robust without additional user setup.

Oracle Deployments

Mainnet Deployments

Testnet Deployments

Further Reading

PreviousKnown Issues

Last updated 9 days ago

The Backrunning Geomean Oracle has been selected as part of the Uniswap Foundation Security Fund (UFSF) Cohort 2. The smart contracts have been audited by . The audit report can be found in the .

->

->

->

->

->

->

->

Sepolia

33Audits
Github repository
Ethereum
0xB13250f0Dc8ec6dE297E81CDA8142DB51860BaC4
Arbitrum
0x3043e182047F8696dFE483535785ed1C3681baC4
Base
0x59f39091Fd6f47e9D0bCB466F74e305f1709BAC4
Bsc
0x77B2051204306786934BE8bEC29a48584E133aC4
Optimism
0x79234983dED8EAA571873fffe94e437e11C7FaC4
Polygon
0x1D8691A1A7d53B60DeDd99D8079E026cB0E5bac4
Unichain
0x54bd666eA7FD8d5404c0593Eab3Dcf9b6E2A3aC4
0xE39CAf28BF7C238A42D4CDffB96587862F41bAC4
RigoBlock Oracle Blog Post
Sepolia Oracle Hook
UFSF