Smart contract oracles protect DeFi protocols from price manipulation attacks: make the protocols safe, and are their most significant dependency simultaneously. Thus, choosing an oracle is a critical decision in the design of a protocol. StarkNet is a ZK-rollup on the Ethereum chain that solves the “scaling” problem of Ethereum in a highly-efficient manner. The network was released in November 2021, and in a short life of around 10 months, it has given birth to multiple projects from the DeFi space, NFTs, and even gaming (a whole list of projects building on StarkNet can be found
here ). Though the scaling problem of Ethereum can probably be solved with L2 solutions built on top of the secure layer of the Ethereum mainnet, the problem of permissionlessly getting off-chain data on chain persists.
The two largest oracles building on StarkNet are
Right now, both Empiric and Stork provide price data for some of the most prominent cryptocurrencies (BTC, ETH, DAI, etc). Along with that, Empiric Network has plans to make data like weather data in a specific place or the outcome of a sports match available. Meanwhile, the Stork team is also interested in equity prices (i.e. stocks), NFTs, and other asset classes. Once these are added, non-price-related feeds might also get added by Stork as well. The wide diversity of information made available by these oracles is very helpful for the ecosystem.
Since only price data is available as of this writing, I set out to do an exploratory data analysis on the data sent by these oracles on the Starknet testnet and compare the quality (and quantity) for both.
Some basic facts to note are:
Stork is an oracle with on-chain price computation. This means that median prices are calculated on StarkNet based on price quotes provided by individual publishers rather than being aggregated off-chain
Allowlisted publishers can publish and sign data on-chain
Right now 2 publishers are live publishing price updates on the testnet (Dexterity - a financial firm in crypto - and the other is Stork)
Has 5 price tickers available (a more updated list can be found
The median time between price updates was 180 seconds
Now, let’s get to the exciting part - the numbers 🤓. I analyzed the price published for BTC and ETH on the Stork contract between July 31, 2022, and August 12, 2022.
As we can see from the graph above, the price range for BTC in the given timeframe was $2403 (i.e. there are no discrepancies in the range of data). However, in some cases, there are large intervals between updates (up to 4 hours) according to the dataset. The dataset was an offline record of transactions that were sent as transactions to the network. Since this record is not supposed to be saved by Stork (there is no use case for this), the data isn’t supposed to be reliable.
Hence, I analyzed the on-chain frequency of transactions on the contract that was shared by Vlad. The on-chain transactions revealed a more optimistic observation. The longest time difference between two updates was 3000 seconds, and these updates probably coincided with the downtimes of the StarkNet network itself. Most of the updates were in the range of 2-3 minutes. A distribution plot of the differences can be found below:
The Stork team is actively adding new publishers in the coming weeks as of this writing. I believe that once more publishers are added, the updates will easily become more frequent, and the downtimes will not be that long.
The Empiric oracle seems more mature and provides 20+ price feeds, including both spot and options (full list here:
Allowlisted publishers can publish data on-chain (Empiric Network, CMT, Gemini, FTX, CEX, BitStamp, Coinbase, Kraken, Binance, Bitfinex, Coingecko)
Has 17 price tickers available (list
The median time between two price updates for the empiric publisher was 93 seconds
The median time between two price updates when considering all publishers was less than 5 seconds
We got the following results upon analyzing Empiric for the price of BTC between July 31, 2022, and August 12, 2022. The price range for BTC was 2468, and the maximum downtime was for 7 minutes, with most of the updates taking less than one minute (see stats below)
It might be surprising that some updates had less than 5 seconds of gap between them. This is probably due to the number of publishers sending the transactions with the updated prices. Empiric’s cofounder, Jonas, mentioned during our interaction that specific mechanisms could be implemented to explicitly favor timing coordination among publishers, and the updates may remain at small intervals. Stork can indeed implement this mechanism in the future once they have a more extensive network of publishers.
Since the price updates for Empiric also mentioned the source of the data, I looked at the actual closeness of the data to real-time prices (from the CoinGecko API) at 5-minute intervals.
An example of the data retrieved from Empiric is given below for a clearer understanding. The source is the actual source of price (market-maker, AMM, etc.) of the asset, while the publisher is the entity that sends the transaction on-chain.
By taking only the updates from the empiric set as publisher and coingecko as the source, we saw that the price was within -0.002 % of the price returned by CoinGecko API at 5-minute intervals over around 24 hours. I could not run a similar analysis on the Stork data since the data we received from Stork did not have the sources of data segregated and instead had an aggregated price feed.
It is very important to understand that a larger number of publishers on the Empiric network gives it the upside of having more frequent updates published. The bottleneck, however, is the block frequency of the StarkNet network itself. The data we analyzed above is the history of transactions sent and the corresponding timestamp of the transaction being sent. However, they get added to a block whenever a new block is created and published (which takes around 3 mins today).
By taking only the updates from the empiric set as publisher and coingecko as the source, we saw that the price was within -0.002 % of the price returned by CoinGecko API at 5-minute intervals over around 24 hours. I could not run a similar analysis on the Stork data since the data we received from Stork did not have the sources of data segregated and instead had an aggregated price feed.
It is very important to understand that a larger number of publishers on the Empiric network gives it the upside of having more frequent updates published. The bottleneck, however, is the block frequency of the StarkNet network itself. The data we analyzed above is the history of transactions sent and the corresponding timestamp of the transaction being sent. However, they get added to a block whenever a new block is created and published (which takes around 3 mins today).
As mentioned in this post, Stork and Empiric only enable allowlisted publishers (mostly high-volume market makers and exchanges) to publish the latest price to the respective smart contracts. I am sure both teams are working on a truly permissionless way of proving the price of an asset. However, right now, the centralized nature of the data being published is to be expected from projects at a nascent stage. Empiric recently
The most prominent example available today is Chainlink. Anyone is allowed to stake some assets, spin up a node, and start sharing their knowledge about the off-chain (IRL) world. However, only certain entities can publish data to the official Chainlink price feeds (
Moreover, since both Empiric and Stork oracles are decentralized in the way that the originator of the price update transaction always is the publisher (who has the private key to their public wallet), any malicious attempts to skew the price reflected by the oracle will only result in reputation loss. Any oracles on StarkNet can implement simple aggregation modes like the median of most recent updates to prevent a single source from skewing the data. Both Stork and Empiric employ these and similar techniques.
It is a big “if“ to assume that the updates remain just as frequent once these oracles move to the mainnet. On StarkNet, the computation cost is infinitesimal, yet the storage cost is relatively high. Hence any updates to the storage of the network may cost higher than expected once moved to the mainnet. However, another interesting fact is that overwriting the same storage slot multiple times in a single block will not result in high storage costs. Hence you only pay storage fees while updating the value - if it stays the same, you pay nothing. The cost would still be of a single write since the final value of the slot is sent to Ethereum Mainnet as calldata. Due to these reasons, StarkNet may issue batching rebates in the future for multiple overwrites of the same storage slot.
As the computational effort required to verify STARK proofs is
Yet another approach for further improvement is the possibility of moving to
Resources
The link to Colab notebooks containing all the results of DA mentioned in the blog post can be found below: