Foresight Ventures: WASM — Engine of Big Era

Foresight Ventures
13 min readNov 7, 2023

Author: Mike@Foresight Ventures

TL;DR

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, commonly referred to as WASM, is a high-efficiency, lightweight instruction set standard developed by the World Wide Web Consortium (W3C). It’s hailed as a disruptor for the internet and high-performance computing, supporting cross-browser execution. This means that various programming languages including C/C++, Go, Rust, and others can be compiled into a unified standard binary format. This binary format can then run in browsers with almost native code efficiency, serving as an alternative to JavaScript.

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.
  • Security: WASM operates in a memory-safe, sandboxed execution environment, even within existing JavaScript virtual machines. In the web environment, WASM strictly adheres to the same-origin policy and browser security policies. Most WASM applications, however, can’t connect to the network (as socket support is lacking) and only support local databases. Many security issues stem from illegal memory access during execution, which WASM can avoid during compilation.
  • Compatibility&Portability: WASM is designed in the Web to be version-less, feature-testable, and backwards compatible. WASM can be invoked by JavaScript, integrated into the JavaScript context, and call browser functions like Web APIs. WASM not only runs in browsers but also in non-web environments (such as Node.js, Deno, IoT devices, etc.). Traditional methods might require multiple compilations, whereas WASM needs only one, making it plug-and-play.

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 ?

Generally

The Web evolved from static hypertext content and small script languages to a powerful and popular platform filled with amazing applications and features. However, Web applications have been primarily driven by the same scripting language (JavaScript) so far, although JavaScript was never intended for these purposes.

Originally a simple scripting language for lightweight hyper-textual content on the Web, JavaScript was designed to be easy to learn and write, not for speed. Significant improvements in JavaScript parsing by browsers over the years have led to considerable performance boosts.

As JavaScript’s execution speed improved, the range of tasks performable in browsers expanded greatly. New APIs enabled interactive graphics, video streaming, offline browsing, and more. More applications traditionally confined to local software began moving to the Web. Today, you can easily edit documents and send emails in a browser, but in some areas, JavaScript’s performance remains a challenge. Think about the software you use outside browsers: gaming, video editing, 3D rendering, or music production. These applications require extensive computing and high performance, which JavaScript struggles to meet.

Replacing JavaScript is impractical, possibly taking decades, as the entire internet depends on it. Plus, there’s a large community constantly improving JavaScript. Indeed, compared to other languages, JavaScript has certain shortcomings, like with null and == operations, but these aren’t enough to abandon the entire technology.

Thus, WebAssembly won’t replace JavaScript, but that doesn’t mean WASM won’t become increasingly widely used. In fact, WASM’s usage is expected to grow, bringing powerful computing capabilities to web pages, such as for image processing or gaming. With WASM, you can create a web version of Photoshop running smoothly, or a 3D game in a browser running at 60 frames per second or higher. Games, particularly, are challenging because they need to manage audio and video processing, physical effects, and AI simultaneously. WASM’s ability to run games efficiently in browsers opens the door to bringing many other applications to the Web.

The comparison between the JavaScript and WASM workflows above demonstrates that WASM is much more straightforward than JavaScript.

Web3

WASM VM

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?

Oversized Architecture

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.

Bulky Precompiles

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.
  • Flexibility and Interoperability: Wasm extends the family of languages available to smart contract developers by supporting the development of complex business logic written in any of Wasm’s high-level languages (e.g., Rust, C++, JavaScript, etc.), which means that you can write smart contracts in any language you’re familiar with, including the most mature Rust-based ink!, or AssemblyScript-based Ask! AssemblyScript-based Ask!

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.

Stylus (Arbitrum)

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.

Gear (Polkadot)

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 (Cosmos)

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

  1. Security: Enhancing the security of smart contracts through the use of the Rust language.
  2. Cross-chain Compatibility: Supported by the IBC (Inter-Blockchain Communication) protocol in the Cosmos ecosystem.
  3. Performance: Demonstrated higher efficiency and lower transaction costs than traditional EVM (Ethereum Virtual Machine) in several cases.
  4. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Compatibility Issues: For projects accustomed to the EVM or other smart contract environments, transitioning to CosmWasm might pose compatibility challenges.

ZK-WASM

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.

Conclusion

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.

But as more blockchains begin to support Web Assembly as the bytecode for compiled smart contracts, WASM brings not only efficiency, interoperability, and a wide range of applications to the blockchain, but also the key to liberating developers, lowering the barrier to entry into the blockchain. Imagine, in the near future, when Web2 developers want to try blockchain development, they could use familiar languages like Python, C++, and Javascript to develop large-scale applications on the blockchain, maximizing the value of decentralized networks. By first lowering the threshold for creators (developers) and then for users, we step towards Mass Adoption.

References

https://blog.scottlogic.com/2022/06/20/state-of-wasm-2022.html

https://homeless20.notion.site/Blockchain-WASM-Chapter-Arbitrum-18f67cee15c147dfae68b06269a455c0

https://wiki.polkadot.network/docs/learn-wasm

https://docs.arbitrum.io/stylus/stylus-gentle-introduction

https://medium.com/@gear_techs/introducing-gear-easy-to-use-polkadot-parachain-9ccd05437a9c

https://medium.com/cosmwasm/cosmwasm-for-ctos-f1ffa19cccb8

https://www.cncf.io/wp-content/uploads/2023/09/The-State-of-WebAssembly-2023.pdf

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.

Website: https://www.foresightventures.com/

Twitter: https://twitter.com/ForesightVen

Medium: https://foresightventures.medium.com

Substack: https://foresightventures.substack.com

Discord: https://discord.com/invite/maEG3hRdE3

Linktree: https://linktr.ee/foresightventures

--

--

Foresight Ventures

Foresight Ventures is a blockchain technology-focused investment firm, focusing on identifying disruptive innovation opportunities that will change the industry