Technical

What is Solidity “2.0”?

December 9, 2024
Maciej Kalka
linkedin logo

Smart contracts in Solidity have been fundamental to the Ethereum ecosystem, giving developers the ability to build decentralized applications and powering everything from DeFi protocols to NFT marketplaces. However, as dApps evolve and real-world use cases expand, two major limitations have become increasingly apparent.

The first challenge lies in connecting blockchain with “real world” data. Smart contracts need to interact with traditional web services and process both public and private web-data. Without this connection to web2 data sources, dApps remain isolated from the systems that power most of the digital world. The second limitation stems from the increasingly fragmented Ethereum ecosystem. With the rise of Layer 2 solutions, assets and data are spread across multiple chains. Nonetheless, smart contracts face two significant constraints: they remain chain-specific, and can only access current-state data. A contract deployed on Ethereum can't verify a balance on Optimism, interact with data on Base, or even check what a user's balance was last month.

Enter vlayer's "Solidity 2.0" - a paradigm shift transforming what’s possible with Solidity smart contracts. Through four new "superpowers" - Time Travel, Teleport, Web Proofs, and Email Proofs. With vlayer, developers can now build dApps that seamlessly integrate with both web2 and web3, all while keeping Solidity's familiar simplicity.

Understanding vlayer's New Programming Paradigm

Zero Knowledge Proofs (ZKPs) introduced a programming model that splits execution into two parts: Prover and Verifier. In blockchain applications, Provers typically handle heavy computations off-chain, while Verifiers (running as smart contracts) efficiently verify the computations' correctness on-chain. While this paradigm has shown great promise, its adoption has been limited by complex development environments and steep learning curves.

Solidity for Everything

For the first time ever, vlayer enables developers to write both Provers and Verifiers in pure Solidity. This isn't just a convenience - it's a fundamental shift in how we develop zero-knowledge applications. Instead of learning specialized languages or dealing with complex cryptographic circuits, developers can leverage their existing Solidity knowledge to build sophisticated applications.

Let's explore how this works in practice. Here's a simple example that verifies historical NFT ownership.

The Prover Contract

Key aspects to understand:

  • This is a standard Solidity contract that can be compiled with familiar tools, such as Forge
  • It inherits from a base Prover contract to gain access to “superpowers” – special capabilities engineered at vlayer
  • The execution happens off-chain on a vlayer node

Contract returns proof() which will be required by the Verifier smart contract

The Verifier Contract

A few points to note:

  • Like the Prover, this is standard Solidity code
  • Unlike Prover, it is intended to execute on-chain
  • The onlyVerified modifier ensures proofs come from the correct Prover contract. Function arguments must exactly match the Prover's return values
  • The Prover contract must be deployed (even though execution is off-chain) to serve as a source of truth

Smart Contracts’ New Superpowers

Traditional smart contracts in Ethereum have a powerful core capability: they can access the entire state of the blockchain. This means any contract can call any other contract on the chain, which has enabled the creation of composable DeFi protocols, NFT marketplaces, and other innovative applications.

However, as we mentioned earlier – this power comes with significant limitations. Let’s take a closer look at how we address those with vlayer.

Time Travel: Looking into the Past

Traditional smart contracts are locked in the present - they can't access historical data. This makes it impossible to perform seemingly simple tasks like calculating a user's average balance over time or reviewing their past interactions with a protocol.

Time Travel changes this fundamentally. Here is a real life function that calculates the average balance over a significant number of blocks:

Teleport: Breaking Chain Boundaries

The fragmentation of the Ethereum ecosystem has created a need for cross-chain communication. Teleport makes this seamless by allowing contracts to query data across different chains. 

Here's how it looks in practice:

This is a Prover contract, which calculates the aggregated cross-chain balance of a given account. Specifically, it checks the aggregated USDC balance on Ethereum, Base, and Optimism for predefined block numbers.

Web and Email Proofs: Bridging with Web2

While Time Travel and Teleport expand what's possible within web3, Web and Email Proofs create secure bridges to traditional web services. These features enable smart contracts to verify and act on data from trusted web sources and email communications.

Let’s take a look at a code snippet containing a Web Proof:

The first thing to highlight in the snippet is that the contract, as expected, inherits from Prover. The verify function used in line 3 is a precompile added to the Prover execution. Another precompile used in lines 4 and 5 of this contract is JSON precompile, used for parsing JSON. 

Thanks to including the verify function as a precompile to a Prover, execution is private in the sense that the input data is not published on-chain. Also, execution is much cheaper than what you could achieve on the chain. 

The Email Proofs functionality works in a similar manner.

It’s Time to Build!

This new programming paradigm, while powerful, is designed to feel natural to Solidity developers. It extends what's possible while maintaining the familiarity and security practices that have made Solidity successful.

Want to explore more possibilities with vlayer's Solidity 2.0? Check out our three-part Verifiable Data Report series, or, better yet, dive into our documentation and start building.

The barrier to entry for zero-knowledge dApps has never been lower. It's time to build!

Share the article
linkedin logo