Skip to content

State Diffs by ZKsync: The Game Changer For Push Oracles

  • by

Understand the superpowers of ZKsync’s state diffs

1. Key Takeaways

  • Ethereum founder Vitalik Buterin said: “in 10 years, all rollups will be ZK and will commit blocks with finalized state roots to L1 every slot. It will take a lot of infrastructure and prover optimization to get there, but that’s the clear endgame.”
  • ZKsync is making unexpected strides in gaming by partnering with Pudgy Penguins for the Pudgy World game and in decentralized social platforms with Lens Protocol transitioning to the ZK chain. Additionally, former Activision Blizzard VP Michael Lee has been onboarded to lead the gaming expansion within the ecosystem.
  • By leveraging ZKsync, RedStone innovates on the State Diffs Oracle concept, launching a novel pilot program that introduces a completely reimagined Push Oracle onto the ZKsync Era and Elastic Chains.
Comparison of key results of State Diffs vs State Updates L2 technology

2. Scaling Ethereum To Billion Of Users With ZKsync

Ethereum is arguably the most decentralized blockchain, secured by tens of thousands of validators worldwide and backed by Ether, the second-largest crypto asset. It serves as a playground for crypto innovation, evolving into a robust and diverse ecosystem of Layer 2s. As the largest smart contracts network, Ethereum experienced exponential growth due to its unique characteristics and status as the ultimate settlement layer. However, this surge in adoption has strained the underlying layer, unable to keep up with the enormous computation demand. This is where Layer 2 technology comes into play.

Layer 2 refers to Ethereum scaling solutions that manage transactions outside the main chain while leveraging Ethereum’s robust decentralized security. Essentially, Layer 2 is a blockchain designed to enhance and extend Ethereum’s capabilities. One primary approach is Rollups, where transactions are processed off-chain, bundled together, and then submitted to the Layer 1 blockchain for finalization. One type of rollup is Zero-Knowledge Rollups, which utilize cryptographic primitives called validity proofs. One of the undisputed leaders in this field is ZKsync.

What are ZKsync and Matter Labs?

ZKsync is a suite of zero-knowledge (ZK) technology solutions that can be leveraged to create secure, censorship-resistant, privacy-preserving, and hyper-scalable blockchains. ZKsync is made available to developers, enterprises, and financial institutions through the ZK Stack Ethereum rollup framework, which enables the deployment of customizable ZK Chains. These ZK Chains form an interconnected network through the ZKsync 3.0 upgrade, called the Elastic Chain. The Elastic Chain enables native, trustless, and low-cost interoperability between the ZK Chains powered by ZK Stack. Era is the original mainnet chain in the Elastic Chain ecosystem with additional chains joining the ecosystem in 2024 and more launching in the near future.

ZKsync Lite: Feasibility Validation

ZKsync Lite is a user-centric zk rollup platform focused on fast, low-cost transactions. Using zero-knowledge proofs, it ensures quick, secure transactions and supports cross-chain transfers between Ethereum and other networks.

The main difference from the full ZKsync version is its limited operations (lacks smart contract functionality), which allow ZKsync Lite to offer faster and cheaper transactions.

ZKsync Era: The Scaling Powerhouse

ZKsync Era is a general-purpose ZK Rollup designed for the Ethereum blockchain, offering full EVM compatibility. It allows most Ethereum dApps to be deployed seamlessly, providing scalable and low-cost transactions through cryptographic validity proofs while maintaining Ethereum’s high-security standards. Computation and data storage are performed off-chain, significantly reducing fees, while guaranteeing the highest security level through undeniable cryptographic proof. This lightweight proof is stored on-chain, validating the computation without revealing any information beyond the validity of the operation itself. ZKsync Era also supports permissionless EMV-compatible smart contracts a standard Web3 API, and introduces features like native account abstraction, all without relying on third parties.

ZKsync: The Elastic Chain

The Elastic Chain is the latest evolution of the ZKsync framework: a modular, open-source stack for building custom ZK-powered Layer 2 and Layer 3 solutions, known as ZK Chains. Based on the code of ZKsync Era, the ZK Stack offers developers full autonomy to customize and control every aspect of their chains, from privacy to data availability.

Matter Labs is a leading research and development company focused on the creation of scaling solutions for Ethereum. Founded in 2019, Matter Labs is working on critical areas of innovation to scale Ethereum with advanced cryptography and zero-knowledge proofs. The company is a pioneer in zero-knowledge-proof technology, which it leverages to build blockchain infrastructure that enables fast, secure, and scalable transactions. With a commitment to privacy and decentralization, Matter Labs is driving the next wave of innovation in blockchain technology.

Key Features

Free: Developed under fully permissive MIT/Apache open-source licenses, building with Elastic Chain is available at no cost, encouraging contributions and utilization from the community.

Sovereign: Developers have complete ownership of the code and the freedom to tailor the chain to their specific needs.

Composable: Any chain built with the Elastic Chain can seamlessly plug into a unified and trustless network, offering frictionless interoperability for all ZK Stack chains. This setup boasts low latency and addresses liquidity fragmentation through a network of Asset Routers.

Modular: Customize every aspect of your ZK Chain, including the choice of sequencer, data availability layer, and tokenomics.

The Elastic Chain, introduced by ZKsync, is an ever-expanding, verifiable blockchain network secured by zk proofs and derived security from Ethereum L1. It consists of parallel instances of zkEVM connected via interoperability tools, all settling on the Ethereum Layer 1 mainnet. 

Using shared bridge contracts on L1 and native Asset routers ZK Chains solve many issues found in other architectures. These bridges ensure trustless validation, facilitate easy asset transfers by burning and minting, and rely on L1 as a single source of truth to prevent hard forks. To put it in perspective, a asset router between two ZK Stack rollups provides the same highest security properties of the base layer as the native, trustless bridge between Ethereum Mainnet and an L2. If vulnerabilities are discovered, coordinated governance on L1 allows for synchronized hard forks, similar to L1’s robust social layer response mechanisms.

ZKsync has positioned itself as a major Ethereum-first scaling solution, aligning closely with the Ethereum community by emphasizing general-purpose functionality, EVM compatibility, support for Solidity tools, vast contribution to the ETH gas burn, and open-source spirit.

Tell me more about this zk-magic!

The Matter Labs team prepared a great resource explaining Zero-Knowledge Proofs for beginners. Have a look at “ZK Proofs explained like I’m 5!

Comparing ZK Rollups and Optimistic Rollups

Comparing ZK Rollups and Optimistic Rollups

State Diffs: Efficiency Boost For Roll-ups

Not all L2s are created the same. Moreover, not all ZK rollups use the same underlying principles to benefit from Ethereum’s base layer security natively. 

Source: bartek.eth, L2Beat 

There are two main categories of ZK rollups in the Ethereum arena: those that upload cryptographic proofs of all executed transactions at the L2 layer, and those that only seed the outputs of executed transactions, known as state changes or State Diffs (Δ) to the base layer. One of the novel advantages of State Diffs-based rollups is their significant compression capabilities. For example, if one sends 2 transactions in the same ZKsync L1 batch, the second transaction modifies the same slot. This means both transactions result in just one L1 state change, reducing the L1 storage cost. Similarly, sending 100 transactions affecting the same L2 state in a single batch would cost nearly the same as modifying one slot on L1 (single L1 storage slot plus negligible L2 execution cost). This property creates a significant scalability unlock for applications that frequently update the same part of the global state, such as payment solutions, high-frequency trading, or oracle updates. 

Batch vs Block vs Transaction at ZKsync Era, Source

ZKsync Era vs Ethereum

3. What Are Oracles?

Oracles act as intermediaries between external data and smart contracts, rather than serving as data sources themselves. They retrieve, verify, and transmit data such as stock prices, token values, and asset prices. The challenge is to ensure that the data provided is reliable and resistant to manipulation while maintaining the trust and decentralization inherent in smart contracts. This involves avoiding reliance on a single source or central authority.

Push vs Pull Oracles and Why Gas Matters

Push oracles proactively provide data to smart contracts at predetermined intervals. The oracle operator, or other authorized parties, continuously pushes updates, such as price changes, to the blockchain. In contrast, pull oracles, also known as on-demand oracles, operate differently. They retrieve data from external sources only when prompted by a query from the smart contract, ensuring that data is fetched only when needed.

Oracles Case Study in DeFi

ZeroLend <> RedStone Lending Case Study

ZeroLend is a decentralized, non-custodial liquidity protocol that allows users to participate as liquidity providers or borrowers within the ZKsync Era and other L2s. It is a classic primitive essential for the robust functioning of any DeFi ecosystem. Let’s examine the case study of RedStone’s role within the ZeroLend system.

ZeroLend tracks loan health using two pivotal metrics: the Loan-to-Value (LTV) ratio and the liquidation threshold. For simplicity, this case study operates solely on the liquidation threshold.

For example, you borrowed $10,000 worth of wUSDM stablecoin against $18,000 worth of $STONE as collateral on the Manta Market. Both asset feeds are supplied by RedStone Oracles. With a liquidation threshold of 0.8 ($12,500), if your loan’s health factor hits this threshold, ZeroLend’s smart contract automatically sells enough collateral to cover the debt, including a liquidation penalty. Considering a 10% liquidation penalty: ZeroLend would sell $10,000 plus 10% of $10,000 ($1,000), i.e., $11,000 worth of your collateral. The accuracy of data provided by RedStone Oracles is essential for ZeroLend market operations.

Gearbox <> RedStone Pull Case Study

Gearbox is a composable leverage protocol that enables users to margin trade on DeFi primitives like Uniswap, leverage farm on Curve, leverage liquid stake on Lido, and use 10X more capital. Essentially, it combines lending and prime brokerage in one protocol. Gearbox has two user sides:

– Lenders deposit assets for passive, single-asset yield with no impermanent loss.

– Leverage users borrow these assets to create spot leverage positions for use in DeFi. That could be margin trading on Uniswap, etc.

However, these mechanisms require reliable, up-to-date financial data to ensure proper system flow. This is where RedStone feeds come in, providing Pull Model price feeds to gauge the value of collateral accurately.

Let’s put this into a real-life scenario: You deposit one ETH into Gearbox’s Ether.fi leverage farming vault. After selecting your preferred leverage ratio (higher leverage means higher passive returns but also higher liquidation risk), the protocol constantly evaluates the market value of your leveraged position against the Ether.fi’s smart-contract-backed collateral. This prevents it from ending up with so-called bad debt and ensures that users aren’t liquidated due to short-term market volatility, providing a great user experience. RedStone provides the real-time, accurate market data needed for Gearbox’s smart contracts to assess the value of leveraged weETH and multiple other assets accurately.

Source: Gearbox

4. State Diffs Oracles: All You Need To Know

Let’s combine the two points into one inference:

  1. State Diffs in ZK-based L2s, with their vast compression capabilities, exponentially increase throughput at minimal marginal cost. 
  2. In contrast, Push Oracles incur marginally increased costs each time data is proactively provided on-chain.

The conclusion? Oracles are an ideal use case for the powerful capabilities of State Diffs technology. Practically, it’s a complete reimagining of the economic viability of the Push Oracles model. It enables data feed updates in nearly one-second block times and requires payment for only one L1 storage slot each time L2 seeds a storage batch. This represents a frontier of innovation in on-chain oracle design.

DeFi With State Diffs Oracles

Now, close-to-one-second oracle updates allow DeFi applications to be more elegant, secure, and functional, paving the way for substantial growth in DeFi users on L2s. The best part? We’re not talking about a future we aspire to build. We’re talking about today.

In collaboration with ZKsync, RedStone Oracles has completed a pilot implementation of the first-of-its-kind State Diffs Oracle. RedStone Oracles delivers data on the ZKsync Era testnet every 2 seconds, using Websockets for integration, and the pilot is set for ETH/USD feed. Currently, one signer node attests to the data’s correctness, but we aim to decentralize this in the future to align with our crypto ethos. The most important aspect: what efficiency improvements have we observed during the pilot?

We observed a ~40% reduction in costs for subsequent price feed updates within the same ZKsync Era block L1 batch. This, by every means, represents a significant drop in costs for each sequential price update delivered to zkEra. This scale enables us to reimagine what’s possible across the DeFi landscape fully. See the RedStone State Diffs pilot implementation here.

5. What Does The Rest Of 2024 Bring?

One of the most anticipated events of 2024 for ZKsync has been the recent TGE of the $ZK token. This milestone is significant for any major project aiming to build a robust, decentralized community. With a total supply of 21 billion (echoing Bitcoin’s supply), the token is traded under the ticker $ZK. While the token generation event appears to be the final step for fair and decentralized distribution, much work must be done to unite the entire ZK community around the token.

ZKsync’s development has been robustly supported by Matter Labs, which is backed by high-profile investors such as Andreessen Horowitz, Dragonfly Capital, Blockchain Capital, Crypto.com Capital, Placeholder Capital, and 1kx. The project has successfully raised a total of $258 million in venture funding, along with an additional $200 million dedicated to an ecosystem fund. This strong funding support positions ZKsync as one of the largest web3 projects.

However, the token and funding are merely key milestones for the team led by Alex Gluchowski. ZKsync became the first L2 solution to adopt the new DA rails – the EIP-4844 blob format on Ethereum this year. EIP-4844, also known as Protodanksharding, introduces “blobs” to significantly reduce L2 data availability costs by making it much cheaper to post L2 data to Ethereum. The impact of this implementation is substantial. Data from prominent space data analyst 0xKofi revealed that, on average, weekly seeding of L2 data cost the protocol around $2,439,885 before the Denkun upgrade. Post-upgrade, these weekly costs have dropped to just $32,953—a roughly 99% decrease. This dramatic change in paid fees highlights the potential of EIP-4844 to make transactions on Ethereum significantly more cost-effective.

ZKsync is making unexpected strides in the gaming sector, marked by a partnership with Pudgy Penguins and the upcoming Pudgy World game, which will utilize zkEVM. Matter Labs is further strengthening its position in the gaming area with key integrations and  deployments including the launch of ZK Candy and ZTX launching CREATOR as a ZK Chain.. Gaming is not the only effort to massively increase activity across the ZK stack. Recently, Lens Protocol announced plans to transition one of the largest decentralized social platforms to ZK Stack L2, and Cronos zkEVM launched mainnet went live as a ZK Chain These initiatives highlight the significant effort to leverage the technology behind ZKsync, aiming to bring a substantial portion of social experiences on-chain while providing a great user experience and full sovereignty. 

6. Conclusions

Many refer to the Ethereum L2-centered roadmap as the bazaar of permissionless innovation, while ZK-based L2s are considered the endgame for Ethereum’s scalability. Due to their enormous compression capabilities, State Diffs ZK-based L2s are an ideal playing field for innovation within the DeFi tool stack, especially oracles. State Diffs Oracles have completely reimagined the Push Oracle Model, making it economically viable to provide data to smart contracts at close-to-one-second intervals. This unlocks the potential for truly new financial primitives on-chain. The first-of-its-kind ZKsync x RedStone State Diffs Oracle demonstrates that this is not a long-term fantasy but rather on the verge of becoming a Mainnet tool. We are extremely proud to be at the forefront of innovation, working with incredible partners like the ZKsync team to reshape the DeFi experience and scale it for mass adoption.

7. References

  1. https://ethereum.org/en/developers/docs/
  2. https://docs.ZKsync.io/
  3. https://ethereum.org/en/layer-2/
  4. https://docs.zerolend.xyz/
  5. https://dev.gearbox.fi/intro
  6. https://blog.getclave.io
  7. https://l2beat.com
  8. https://dune.com/niftytable/rollup-economics
  9. https://github.com/matter-labs/simple-oracle-benchmarking
  10. https://www.growthepie.xyz/
  11. https://l2fees.info/

8. About Authors

RedStone is a modular oracle delivering diverse, high-frequency data feeds to all EVM Layer1, Layer2, Rollup-as-a-Service networks and beyond, i.e., Starknet, Fuel Network, or TON. By responding to market trends and developer needs, RedStone can support assets that are not available elsewhere. The modular design allows for data consumption models adjusted to specific use cases, i.e., capital-efficient LSTfi.

Core contributors to the report:

  • Jakub Jaworski, Growth Lead at RedStone Oracles
  • Marcin Wilk, Analyst at RedStone Oracles
  • Marcin Kazmierczak, Co-Founder & COO at RedStone Oracles
  • Bayo Akins, Business Development Lead, Infrastructure, Matter Labs

Meet the RedStone Team at ETHWarsaw, register here 🇵🇱