Author: Mike@Foresight Ventures
WebAssembly is a portable, high-performance binary instruction format that runs in a web browser. It is designed as a general-purpose compilation target that can be used in a wide range of programming languages and can run on different platforms.
Blockchain is a decentralized distributed ledger technology that ensures the security and trustworthiness of data through the use of cryptography and consensus algorithms. Blockchain can be used for applications such as recording transactions, storing data and executing smart contracts.
There are some relationships and application scenarios between Wasm and blockchain:
Smart Contracts: Wasm can be used as an execution environment for smart contracts, enabling the contracts to run on different blockchain platforms.Wasm’s high performance and portability allow smart contracts to be executed more efficiently and can be used across platforms.
Cross-chain interaction: Wasm can be used to realize the function of cross-chain interaction. By compiling the logic of different blockchains into Wasm code, the same logic can be executed on different blockchains, realizing cross-chain data transmission and interaction.
Off-chain computing: Wasm can be used to perform calculations outside the blockchain and submit the results to the blockchain. This can improve the efficiency and flexibility of the calculation while maintaining data security and trustworthiness.
Data Privacy: Wasm can be used to enable data privacy protection on the blockchain. By compiling the processing logic for sensitive data into Wasm code and executing it on the blockchain, it is possible to protect the privacy of the data while ensuring the verifiability of the computation.
In short, Wasm and blockchain can be combined with each other to provide more efficient, secure and flexible blockchain applications and services. the portability and high performance of Wasm make it one of the important technologies in the blockchain field.
WTF is it ?
WebAssembly has the following main advantages:
- Efficiency: WASM has a complete set of language features. It is essentially a compact, fast-loading binary format, aimed at fully harnessing hardware capabilities to achieve the efficiency of native languages.
Web is the only truly universal platform, allowing your applications to be accessed on any device. This also allows you to maintain a single codebase, simplifying updates and ensuring access for all users. WASM supports 64-bit and 32-bit integer operations, directly corresponding to CPU instructions. By removing floating-point operations, determinism can be easily achieved, which is essential for consensus algorithms. Supported by the LLVM compiler infrastructure project, WASM benefits from over a decade of compiler optimizations by LLVM. It’s continuously developed by major companies like Google, Apple, Microsoft, Mozilla, and Facebook, with browser backends from these companies supporting WASM compilation.
The beauty of WASM lies in its versatility: it runs anywhere without the need for downloads or installations, as it’s a binary format. With just a click, Web applications can run immediately as needed, safer than downloading and running binary files directly due to built-in browser security mechanisms. And sharing Web applications is as simple as sharing a clickable link.
Why We Need WebAssembly ?
In 2018, discussions started within the Ethereum foundation about using WASM VM as a smart contract virtual machine because it was felt that it had better performance than EVM. Gavin Wood, the inventor of EVM, had expressed the feasibility of WASM replacing EVM, and Vitalik had also said that Ether 2.0 would be upgraded to Wasm Contracts (eWASM) in order to meet more development needs. Today, the development of Wasm contracts has taken shape.
How is EVM designed? Why is it inefficient?
Traditional computers operate with instruction sets that accept either 32-bit or 64-bit inputs. The EVM, however, is uniquely and specially a 256-bit computer, deliberately designed this way to more easily process Ethereum’s hash algorithms, which inherently produce 256-bit outputs.
However, computers running EVM programs must break down these 256-bit words to fit their native architecture to execute smart contracts, making the whole system very inefficient and impractical.
Moreover, if you wish to implement a complex algorithm like SHA256 using Ethereum’s basic OPCODES, it would be quite a challenge! To address high gas costs arising from running complex programs via the instruction set, Ethereum introduced the concept of precompiles, which compiles programs into the EVM at a fixed gas cost. An important precompile is Ethereum’s hashing algorithm, as implementing this algorithm in the VM would incur exorbitant costs when contracts invoke it.
The problem with precompiles is that they continuously increase the VM’s bulkiness and complexity, without addressing the core issue: the inefficiency and crudeness of the current instruction set and standards.
What if we could define a new standard and instruction set that eliminates the need for precompiling these complex programs, and instead efficiently implement them through basic instructions? This is where WASM comes into play.
EVM vs WASM Comparison:
- Speed: WASM aims to provide faster execution speeds than EVM. EVM may face efficiency issues in processing and executing smart contracts, while WASM enhances loading speed and processing capacity by directly translating into compiled code.
- Precompiles: EVM relies on precompiled contracts for efficient cryptographic computation, which can risk hard forks. WASM, on the other hand, eliminates dependency on precompiled contracts, allowing developers to create efficient and fast smart contracts.
- Transaction Costs: Faster Wasm virtual machine, resulting in a significant increase in transaction throughput, then the contract deployment and transaction costs can also be significantly reduced. It can be said that Wasm contracts are a good solution to the problem of high transaction costs and transaction congestion on Ether.
The EWASM team is integrating WebAssembly on Ethereum to ensure that Ethereum’s execution layer is more efficient and straightforward, suitable as a fully decentralized computing platform. Many other projects, including Dfinity and EOS, have also adopted WASM to strengthen their execution layers.
The Stylus project enhances smart contract execution on the Ethereum layer-2 network, Arbitrum, by introducing the WebAssembly (WASM) virtual machine. Contracts can execute faster than Solidity, while also reducing gas costs. This makes building high-performance smart contracts on the Arbitrum network more accessible, currently supporting compilation from C, C++, and Rust.
Custom Precompile Support: Stylus also supports custom precompiles, allowing developers to deploy their own Rust or C++ precompiles to the Arbitrum network. This can introduce new cryptographic algorithms or other specific functionalities on-chain without waiting for a network upgrade. For instance, tensor computation precompiles could be introduced to reduce inference costs, potentially aiding on-chain machine learning.
Interoperability with EVM: Stylus achieves integration with the existing Ethereum ecosystem through interoperability with the Ethereum Virtual Machine (EVM). This means Stylus contracts can interoperate with existing EVM contracts and share the same global state.
Reentrancy Function: Unlike Cosmos wasm, the Stylus Rust SDK has introduced reentrancy functionality, allowing developers to enable it manually. This grants contracts more flexibility in interoperability, but developers must manage state cautiously to ensure security.
With the popularity of the Arbitrum ecosystem, Stylus might be the most meaningful WASM integration yet, also benefiting Arbitrum’s competitiveness in zkrollups.
The Gear protocol is developing a technology deployable as a Polkadot parachain, which will serve as a platform for hosting smart contracts. Like Polkadot, Gear also utilizes the Substrate framework. This simplifies the process of creating different blockchains for specific applications. Substrate offers extensive, ready-to-use features, allowing people to focus on creating custom engines on top of the protocol.
Previously, starting a blockchain was costly, but Gear enables dApp developers to focus on their projects rather than building and operating an entire blockchain from scratch.
The main engine of the Gear protocol is the smart contract module. In the case of Gear, any smart contract is a WebAssembly program compiled from different languages like Rust, C, C++, etc. This lowers the entry barrier for developers from outside the crypto world, as they can build smart contracts in a familiar environment. It makes experimenting with smart contract programming languages more accessible for developers.
The smart contract architecture of Gear uses the actor model under the hood and provides:
- Persistent memory for immutable programs.
- Asynchronous message processing.
- A minimal, intuitive, and sufficient API surface for the blockchain context.
- Actor model, where smart contracts are seen as actors, enabling easier communication between them.
Gear could significantly simplify and speed up the development of smart contracts, potentially attracting more developers to the Polkadot ecosystem.
CosmWasm is a modern, powerful smart contract platform based on Wasm, which can be easily integrated into Cosmos-SDK. This demonstrates one of the key advantages of CosmWasm: contracts written in CosmWasm are natively and tightly integrated with the IBC (Inter-Blockchain Communication) protocol, allowing developers and users to enter a multi-chain future. Currently, it only supports Rust.
Advantages of CosmWasm
- Security: Enhancing the security of smart contracts through the use of the Rust language.
- Cross-chain Compatibility: Supported by the IBC (Inter-Blockchain Communication) protocol in the Cosmos ecosystem.
- Performance: Demonstrated higher efficiency and lower transaction costs than traditional EVM (Ethereum Virtual Machine) in several cases.
- Developer-friendly: The type safety and memory safety features of the Rust language can reduce certain types of errors in smart contracts.
Challenges and Limitations
- Learning Curve: For beginners, the learning curve of Rust can be steeper compared to more commonly used smart contract languages like Solidity. CosmWasm needs to support more language to gain more popularity.
- Ecosystem and Tool Support: While growing, the development tools and ecosystem for CosmWasm may still be somewhat limited compared to mature smart contract platforms such as Ethereum.
- Market Share and Popularity: Compared to Ethereum, Binance Smart Chain, and other smart contract platforms, CosmWasm might have lower recognition, affecting its ability to attract developers and users.
- Maintenance and Upgrade Challenges: Although CosmWasm offers contract upgrade features, the maintenance and upgrade management of smart contracts remains a complex task, requiring careful handling to avoid security vulnerabilities.
- Compatibility Issues: For projects accustomed to the EVM or other smart contract environments, transitioning to CosmWasm might pose compatibility challenges.
Another emerging technology other than WASM VM, ZKWASM, has had its code open-sourced on GitHub by its creator, Delphinus Labs. ZKWASM allows developers to verify the correctness of computations without re-execution. By using ZKWASM, developers can flexibly use various programming languages to build ZKP (Zero-Knowledge Proof) applications. These applications can run seamlessly in web browsers.
The concept of ZKWASM stems from ZKSNARK, which is a hybrid of SNARG (Succinct Non-interactive Argument of Knowledge) and zero-knowledge proofs. Normally, to use ZKSNARK, you need to write a program in an arithmetic circuit language or a circuit-friendly language, such as Pinocchio, TinyRAM, Buffet/Pequin, Geppetto, xJsnark frameworks, ZoKrates, etc. This can pose a barrier to leveraging the power of ZKSNARK for existing programs. An alternative method, instead of using ZKSNARK at the source code level, is to use it at the bytecode level of a virtual machine, then implement a ZKSNARK-supported virtual machine. Delphinus Labs has adopted the latter approach, embedding the entire WASM virtual machine into the ZKSNARK circuit. This enables existing WASM applications to run directly on ZKWASM without any modifications. As a result, cloud service providers can prove to any user that computations are done honestly, without leaking any private information.
ZKWASM provides a variety of use cases, such as enabling on-chain ZK proof of operations within a browser, making web operations blockchain-verifiable. It’s also applicable in oracles, off-chain computations, automation, bridging Web2 and Web3, generating proofs for machine learning and data processing, and even in gaming and social applications. As adoption rates increase, ZKWASM will expand the possibilities of Web3 and bring Web2 developers into this transformative landscape.
Through Delphinus Lab’s implementation of ZKWASM, developers can harness the power of zero-knowledge proofs to enhance the security and privacy of their applications, paving the way for a more trustworthy and decentralized digital world.
The future is bright for both web performance and the execution layer of smart contract platforms. Not only will dApps have higher performance, but the integration of WASM will also make it easier for those familiar with mainstream languages like Rust and Go to develop smart contracts, rather than needing to learn the various details of blockchain development languages like Solidity to develop useful applications on Ethereum. According to Evans Data Corporation, there are nearly 27 million developers worldwide. This number is steadily increasing — growing by about 3% last year and expected to surpass 28.7 million by 2024. However, the number of developers on blockchain is less than 30,000, about one thousandth of the total number of developers, and while this number is steadily increasing, learning new smart contract languages might still be a barrier for developers entering the blockchain space.
Special thanks to Maggie Wu, Xinyou Ji(CMU), Sinka Gao(Delphinus Labs) for providing advice and guidance on this article.
Mike Jin@Foresight Ventures
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.