从基础 TWAP 看 Crypto-Native 预言机未来

Foresight VenturesОпубліковано о 2022-09-10Востаннє оновлено о 2022-09-10

Анотація

在未来,一个完美的预言机需要完全来自链上的可验证数据源(那么就是基于 TWAP)且支持多链,以及通过 ZK 或完全链上可信计算进行数据获取和处理。

Oracle 原理与问题

区块链的数据来源有两个:一个是链上数据(如地址持有的 ETH 的数量),另一个是链下数据(如 ETH 现在在交易所的价格)。要获取后者,就需要预言机将这个数据告诉给合约。

为什么互联网也需要有 「网下」 数据,但没有预言机问题呢?因为区块链上的数据需要经过共识,因此预言机上传上来的数据也需要是可信的,而互联网 (Web2) 上的数据其实本身都是中心化的。

预言机所需要解决的是从数据源到处理到喂价的信任问题,通常不是数据本身的问题。

链下 Oracle

预言机的信任问题包含了数据源与数据获取与喂价, 针对它们分别有以下解决方案:

a) 数据源: 可信联盟 / 去中心化网络

我认为数据源可信是预言机信任问题最重要的一个点,但是这些数据很多都是链下的,链下的数据其实是无法证明是完全可信的,就像你无法证明 ETH 的价格一定是某个值一样。 无论是采用可信联盟还是去中心化预言机网络,都无法生成一个完全没有套利空间或者 OEV 的价格。

唯一能解决数据源可信问题的就是在未来如果流动性和经济活动大部分都聚集在链上,而不是交易所的时候,去完全采用链上预言机 (Uniswap TWAP),这样可以保证数据源是 「Crypto-native」 和完全可信可验证的。

b) 数据获取与喂价: 可信计算

Town Crier 使用 SGX 来保证数据的获取可信; Empiric 使用 StarkNet 上的合约来保证数据的获取和计算可信,且数据源会直接讲价格数据发送到 StarkNet 上的其他合约中,从而达到第一手数据,保证数据源的可信度; Redstone 通过 SmartWeave 智能合约让任何人都可以成为数据处理者,且使用 Arweave 存储价格数据从而保证数据可信和可以在事后被验证; Chainlink 使用 Chainlink 网络的链上聚合合约来计算出数据结果,再发送到区块链上。

任何应该上链的应用最终都会被上链,这样才能满足区块链透明化,可验证,无需准入门槛,去中心化的特点。

完全链上化的价格预言机会彻底解决数据源和数据获取与喂价问题,让 DeFi 应用给所有人带来经济活动上的自由。

TWAP(Time-Weighted Average Price)

TWAP 是 Uniswap 所推出的价格预言机。 它的数据源完全来自 Uniswap 协议自身的交易数据,数据的获取和处理也是完全在链上进行,开发者也可以直接在链上使用 Uniswap TWAP 进行代币价格计算。

TWAP 的原理是基于每个区块的最后一笔 tx 时的代币价格,结合区块时间,计算出协议整个历史中一个代币的价格总和,从而使用时可以重新计算出一个平均价格。

使用最后一笔 tx 时的价格,是为了让攻击者的攻击成本不可预测,从而增加预言机安全性。 因为就算攻击者在一个区块的最后一笔交易中控制了价格,他也无法预知下一个区块中的相关活动的排序等信息。 根据链上分析,这种跨区块的攻击还没有发生过。(剧透一下,PoS 好像就不一定,后文会说)。

加入时间的变量,是为了进一步增加攻击成本,通过牺牲对即时价格的反映,保持价格的整体稳定性和安全性。

Uniswap V2 TWAP

V2 TWAP 的使用可以是直接拿到一个时间段内的总价变化,除以设定的时间段 t,就可以得出一个平均价格,作为代币的价格。 每隔一段时间(不一定是 t,可以用滑动窗口算法,延迟就更小),则重新获取最新时间段内的价格。

对于 TWAP 来说,时间参数越长,更新越慢,但安全性越高,因为价格操纵的成本基本上就是时间区间内在每个区块上套利和发送交易的开销。

Uniswap V3 TWAP

V2 TWAP 是用时间段内的总价 (price * time),V3 是时间段内的总 tick (tick * time)。

V2 中我们提到了要每隔一段时间去重新获取价格,这可能就需要 Keeper 的参与,Uniswap V3 解决了这个问题。

V3 直接通过一个可定义长度(视需求和网络时间戳行为不同而定)的数组来存储区块时间戳和总 tick,当合约产生 Swap 等交互时,这个数组就会被更新,无需 Keeper 的主动触发。

除此之外,使用时还需要把 tick 转换成价格,稍微比 V2 难用一点。

TWAP 的限制

既然 TWAP 那么好用,那么可信且可验证,完全去中心化,那为什么 Chainlink 被如此广泛采用呢?

写本文的动机其实就是看到了推特上有人说,Euler Finance 从 TWAP 切换到 Chainlink 是一种升级(注意此人 ID… = =)。

他称 TWAP 是非常不安全的,因为 PoS 之后可以进行多区块的预言机操控,这个其实是可以完全被解决的。

相比之下,我认为 TWAP 完全去中心化和完全链上操作的优点会比 Chainlink 好很多,在长期看来,如果没有显著的需求上的差别(比如你要把天气数据搬到链上),那么最好的选择还是 TWAP。

TWAP 和 Chainlink 的对比如下:

TWAP 被全面碾压,但我个人认为,去中心化和安全性是 1,而其他的因素是 0,完全链上化是一种趋势。 任何人都可以做一条比以太坊快非常多,便宜非常多,支持更多语言的智能合约平台,但却无法杀死以太坊。

PoS 后 TWAP 的风险

ChainLinkGod 所说的 PoS 网络中对 TWAP 预言机的攻击问题,Euler Finance 的工程师自己就知道潜在解决方案,Uniswap 的工程师也考虑到了。

PoS 后,因为出块者可预测了,所以更容易结合以下方式进行多区块攻击:

大 Validator 可能被连续分配区块

通过 Flashbot 来发送 Private tx

Multi-block bundle

PoW 和 PoS 的不同情况下,针对 V3 ETH/USDC 交易对的 30 分钟时间窗口 (144 个区块)的 TWAP,要操纵价格造成 30% 的波动,需要以下成本:

PoW: 23.7 万亿美元

PoS(连续控制窗口内 2 个区块情况下): 23.7 万亿美元

PoS(连续控制窗口内 3 个区块情况下): 95 亿美元

PoS(连续控制窗口内 5 个区块情况下): 1.03 亿美元

控制越多区块,操纵的成本就显著地越低,那么解决方案是啥呢?

暂时性解决 PoS 后 TWAP 的操纵风险的方法是:

选择更大的时间窗口

选择流动性更好的池子。

完全解决 PoS 后 TWAP 的操纵风险的方法是:

用 Median 而不是 Average。

这样操纵者就需要控制超过半数的区块,才能操纵价格,对比上面的情况,就需要控制 73 个区块,这个数字应该大到无法表述了。

未来的预言机

我认为在未来,一个完美的 预言机」 需要:

完全来自链上的可验证数据源(那么就是基于 TWAP),且支持多链。

通过 ZK 或完全链上可信计算进行数据获取和处理。

但是这些可能就需要处理以下几个现存或将会出现的小问题:

满足种类,精度,时效性需求的链上数据(当然 Chainlink 等一样有价格延迟的问题,而且本身就是为了数据安全性而牺牲时效性)

彻底解决 TWAP 数据源价格操纵(更深的池子,更大的窗口,使用中位数而不是平均数)

整个预言机信任短板的消除(多签?网络去中心化程度?不靠谱的 Fisherman 机制?)

数据的跨链获取与喂价,多链场景中链上数据的可信传输

数据源多样性(比如只用 Uniswap V2 或者 V3 不太好)

可信环境下执行的 Keeper(如果需要的话)

我相信在未来,越来越多的经济活动会发生在链上,越来越多的价格数据和交易对会存在于 DEX 上,Uniswap 也就可以提供更好的 TWAP,也就会有其他方案能基于 TWAP 实现我设想中的完美预言机,最终达成一个 100% 去中心化的金融系统。

Пов'язані матеріали

Micron Shuts Up the Bears, Makes India's 'Buffett' Regret: Sold Too Early, Missed Out on $2 Billion

Indian value investor Mohnish Pabrai, a disciple of Warren Buffett, revealed his costly mistake of selling shares in Micron Technology too early. He initially invested in 2017, holding it for six years and building a position as large as 77% of his portfolio, based on a thesis that the memory chip industry would consolidate into a stable oligopoly of Samsung, SK Hynix, and Micron. However, he sold his entire stake in September 2023, fearing oversupply after Samsung announced production expansion. Shortly after his exit, demand for high-bandwidth memory (HBM) surged with the rise of AI, and Micron's stock price skyrocketed over 15 times in two years. Pabrai estimates this premature sale cost him roughly $20 billion in potential gains. He expressed similar regret over selling his investment in SK Hynix too soon, stating he violated his own principle of holding companies forever. Reflecting on these errors, Pabrai emphasized his core investment checklist principles: avoiding leverage, focusing on the durability of a company's competitive moat, and assessing management's character. Despite these personal trading missteps, his long-term view on the remaining memory chip leaders remains bullish, advising current holders not to sell as "the party is just getting started." He concluded by sharing his philosophical outlook, prioritizing character over wealth, and his goal to donate his entire fortune before his passing.

marsbit3 хв тому

Micron Shuts Up the Bears, Makes India's 'Buffett' Regret: Sold Too Early, Missed Out on $2 Billion

marsbit3 хв тому

Mihoyo's Next Protagonist Is Her, Who Plays the Piano

Mihoyo, widely recognized for its hit game Genshin Impact, has long harbored a grander ambition: creating a virtual world where one billion people would want to live. While its character design is unparalleled, the company recognizes a fundamental limitation—these beloved virtual characters are not truly "alive." Their dialogue and actions are pre-scripted. This drive for authentic "living" characters has guided Mihoyo's strategic investments in cutting-edge fields like brain-computer interfaces, AI (including an early investment in MiniMax), and nuclear fusion. Following the release of ChatGPT in late 2022, co-founder Cai Haoyu stepped down from management to lead a new overseas AI venture, Anuttacon, focused on creating AI-driven virtual beings. Mihoyo's path has involved experimentation and iteration. Anuttacon's early project, *Whisper of the Stars*, showcased real-time AI conversation but revealed limitations in underlying language models. The team subsequently focused its resources on developing a sophisticated "emotional" large language model, distinct from purely utilitarian AI. Co-founder Liu Wei (Dawei) announced plans to invest up to 100 billion RMB in this AI pursuit. The first tangible product of this vision is *BSide: Olivia Lin*, a free Steam application featuring a piano-playing virtual companion. Unlike typical AI chatbots demanding constant interaction, Olivia Lin operates on a slower, more deliberate rhythm—responding to letters, playing user-submitted melodies, and serving as a desktop presence. This design emphasizes "lifelikeness" over exhaustive conversation, strategically working around current technological constraints while building a sense of authentic connection. The company's journey traces back to its name, "miHoYo," where "mi" pays homage to the virtual singer Hatsune Miku. For nearly two decades, fans have loved Miku, a character unaware of their devotion. Mihoyo's ultimate goal, now backed by massive investment and AI research, is to bridge that gap—to create virtual beings that can truly know they are loved.

marsbit21 хв тому

Mihoyo's Next Protagonist Is Her, Who Plays the Piano

marsbit21 хв тому

Citrini Research: Taking Stock of 5 Major Investment Themes Overshadowed by the AI Trade

Citrini Research identifies five under-the-radar investment themes potentially overshadowed by the dominant AI trade. With capital and analyst attention overwhelmingly focused on AI infrastructure, these overlooked areas present alpha opportunities as market dynamics shift. **Theme 1: Airlines** – Despite strong fundamentals, stocks like Delta and United have been penalized for 18 months due to macro concerns (tariff-inflation, oil prices), not profitability. A rebound is expected as these headwinds fade, aided by trends like premiumization and the 2026 World Cup. **Theme 2: Senior Housing** – A pure demographic play. The U.S. population over 80 is projected to grow 56% in the next decade, drastically outpacing supply. This creates a compelling need for facilities, benefiting REITs like Welltower and operators like Brookdale. **Theme 3: Live Events & Entertainment** – "Being there" is becoming a luxury. This sector has outperformed even tech over the past decade. Companies like TKO Group (WWE/UFC), Cinemark, and IMAX are capitalizing on demand for premium, in-person experiences. **Theme 4: Exchange Competition** – CME Group's ~98% monopoly in U.S. interest rate derivatives faces its first real challenge from FMX Futures Exchange. Backed by major Wall Street banks, FMX offers lower fees and margin savings. While CME's deep liquidity remains an advantage, FMX provides a competitive alternative. **Theme 5: Fintech Recovery** – Heavily sold off in 2026, fintech stocks like SoFi, Robinhood, and Upstart are showing signs of a rebound based on improving fundamentals—SoFi's stablecoin launch, Robinhood's transformation into a "financial super app," and Upstart's renewed AI lending narrative—rather than a change in sector outlook. The report advises maintaining some AI exposure but diversifying into these neglected "small themes" where mispricing exists due to a simple shortage of investor attention.

marsbit57 хв тому

Citrini Research: Taking Stock of 5 Major Investment Themes Overshadowed by the AI Trade

marsbit57 хв тому

21Shares Mid-Year Key Report: Bitcoin's Four-Year Cycle Remains Intact, Stablecoins and Tokenization Emerge as New Growth Engines

21Shares Mid-Year Report 2026: Bitcoin Cycle Intact, Stablecoins & Tokenization Emerge as New Engines This mid-year review assesses progress against 21Shares' ten predictions for 2026. While the overarching shift from narrative to fundamentals holds, performance varies. Key findings show Bitcoin's four-year cycle remains evident despite market maturation. Global crypto ETP AUM has declined to ~$140B, lagging the $400B target, though product innovation continues. Stablecoin supply surpassed $320B, demonstrating non-cyclical demand but falling short of the $1T forecast due to slower regulatory clarity. DeFi TVL, stalled at ~$140B, was hindered by major security incidents. Corporate crypto treasuries hold ~1.28M BTC ($100B), with consolidation pressuring weaker players. Prediction markets are on track, with $57.5B volume already surpassing half the $100B annual target. AI agent infrastructure is ready, but adoption is early. Ethereum L2 consolidation is underway, with the top 5 capturing nearly 90% of activity. Compliant token launches have a platform but lack mainstream volume. Tokenized RWAs total ~$31B on public chains, but institutional pipeline growth is strong. In summary, fundamentals like stablecoins, tokenization, and prediction markets are advancing, but targets require faster adoption or price appreciation. The market is maturing, yet cyclical patterns persist.

marsbit1 год тому

21Shares Mid-Year Key Report: Bitcoin's Four-Year Cycle Remains Intact, Stablecoins and Tokenization Emerge as New Growth Engines

marsbit1 год тому

Торгівля

Спот
Ф'ючерси
活动图片