Foresight Ventures: Crypto-Native Oracle TWAP

0. Oracle Introduction

Blockchains have two sources of data: on-chain data (e.g. the amount of ETH held by an address), and off-chain data (e.g. the current price of ETH on the exchange). To get the latter, the oracle needs to tell this data to the smart contract.

1. Off-chain Oracle

The trust problem of the oracle consists of data source and data processing and feeding, and the following solutions are available for each of them:

a) Data Source: Trusted Party / Decentralized Network

I think the most important point of the oracle’s trust issue is the trustworthiness of the data source, but a lot of this data is off-chain, and there is no way to prove that the off-chain data is completely trustworthy, just like you can’t prove that the price of ETH on certain exchange must be a certain value. Neither a trusted party nor a decentralized network of oracle can generate a price with no arbitrage or OEV at all.

b) Data Processing and Feeding: Trusted Computing

Town Crier uses SGX to ensure that the data processing is credible; Empiric uses contracts on StarkNet to ensure that the data processing and calculation is credible, and the data source sends price data directly to the oracle contract on StarkNet to make it first-hand data, to ensure the credibility of the data source; Redstone’s SmartWeave contracts allow anyone to be a data processor and use Arweave to store price data so that it is trusted and can be verified later; Chainlink uses the Chainlink network’s on-chain aggregation contracts to calculate data results and send them to the blockchain.

2. TWAP (Time-Weighted Average Price)

TWAP is an oracle from Uniswap. Its data source comes entirely from the Uniswap protocol’s own trading data. The data is obtained and processed entirely on chain. Developers can use Uniswap TWAP directly on chain for token price calculations.

3. Uniswap V2 TWAP

V2 TWAP can be used by directly getting the total price change over a time period and dividing it by a set time period t to get an average price as the token price. At regular intervals (not necessarily t, you can use the sliding window algorithm, which has a smaller delay on price change), the price is retrieved for the latest time period.

4. Uniswap V3 TWAP

V2 uses the total price (price * time) in the time period, V3 uses the total tick (tick * time) in the time period.

5. TWAP’s Limitation

If TWAP works so well, is so trustworthy and verifiable, and is completely decentralized, then why is Chainlink so widely adopted?

6. After the Merge, TWAP’s risk

The problem of attacks on TWAP oracle in PoS networks, as described by ChainLinkGod, has also been considered by Uniswap engineers and Euler Finance’s engineers.

  • Private tx sent via Flashbot
  • Multi-block bundle
  • PoS (with 2 blocks in a continuous control window): $23.7 trillion
  • PoS (with 3 blocks in a continuous control window): $9.5 billion
  • PoS (with 5 blocks in a continuous control window): $103 million
  1. choose a pool with better liquidity.

7. Next-gen Oracle

I think in the future, a perfect “oracle” is needed:

  • Data processing and processing via ZK or full on-chain trusted computing.
  • Complete solution to TWAP data source price manipulation (deeper pools, larger windows, use median instead of average)
  • Elimination of trust shortcomings across the oracle (multi-sig? Nakamoto coefficient? Unreliable Fisherman mechanism?)
  • Cross-chain access and feeding of data, and trusted transmission of data on the chain in multi-chain scenarios
  • Data source diversity (e.g., using only Uniswap V2 or V3 is not good)
  • Keeper execution in trusted environment (if keepers needed)

About Foresight Ventures

Foresight Ventures is dedicated to backing the disruptive innovation of blockchain for the next few decades. We manage multiple funds: a VC fund, an actively-managed secondary fund, a multi-strategy FOF, and a private market secondary fund, with AUM exceeding $400 million. Foresight Ventures adheres to the belief of “Unique, Independent, Aggressive, Long-Term mindset” and provides extensive support for portfolio companies within a growing ecosystem. Our team is composed of veterans from top financial and technology companies like Sequoia Capital, CICC, Google, Bitmain and many others.

Related Links




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Foresight Ventures

Foresight Ventures


Foresight Ventures is a blockchain technology-focused investment firm, focusing on identifying disruptive innovation opportunities that will change the industry