Written by: Mike@Foresight Ventures
TL;DR
WebAssembly (Wasm for short) is a portable, high-performance binary instruction format that can run in web browsers. It is designed as a universal compilation target for multiple programming languages and can run on different platforms.
Blockchain is a decentralized distributed ledger technology that ensures data security and trustworthiness through the use of cryptography and consensus algorithms. Blockchain can be used for recording transactions, storing data, and executing smart contracts.
There are some relationships and application scenarios between Wasm and blockchain:
- Smart contracts: Wasm can serve as the execution environment for smart contracts, allowing contracts to run on different blockchain platforms. The high performance and portability of Wasm enable smart contracts to execute more efficiently and be used across platforms.
- Cross-chain interaction: Wasm can be used to implement cross-chain interaction functionality. By compiling the logic of different blockchains into Wasm code, the same logic can be executed on different blockchains, achieving cross-chain data transmission and interaction.
- Off-chain computation: Wasm can be used for computation outside the blockchain and submit the computation results to the blockchain. This can improve the efficiency and flexibility of computation while maintaining data security and trustworthiness.
- Data privacy: Wasm can be used to implement data privacy protection on the blockchain. By compiling the processing logic of sensitive data into Wasm code and executing it on the blockchain, data privacy can be protected while ensuring the verifiability of the computation.
In summary, Wasm and blockchain can be combined 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.

1. What is Web Assembly
WebAssembly is a highly efficient, lightweight instruction set standard developed by the W3C (World Wide Web Consortium), hailed as a disruptor for networking and high performance, supporting cross-browser execution. This means that we can compile different programming languages including C/C++, Go, Rust, etc. into a unified standard binary format and run it in the browser with near-native code efficiency as a replacement for JavaScript.
WebAssembly, or simply WASM, is memory-safe, platform-independent, and can be perfectly and efficiently mapped to all types of CPU architectures, with the following main advantages:
- Efficiency: WASM has a complete set of language features, and in fact, WASM is a small and fast-loading binary format, aiming to fully leverage the capabilities of hardware to achieve the execution efficiency of native languages.
- Safety: WASM runs in a memory-safe, sandboxed execution environment, and can even be implemented in existing JavaScript virtual machines. In the web environment, WASM will strictly adhere to the same-origin policy and browser security policies. When compiling WASM, the interface is relatively limited, and most WASM applications cannot access the network (because they do not support sockets), and can only support local databases. Many security issues arise from illegal memory access during execution, which can be avoided when compiling WASM.
- Compatibility: WASM is designed to be versionless, feature-testable, and backward-compatible in the web. WASM can be called by JavaScript, enter the JavaScript context, and can also call browser functions like a Web API. WASM can run not only in browsers, but also in non-web environments (such as Node.js, Deno, IoT devices, etc.). Traditional methods may require multiple compilations, while WASM only needs to be compiled once and can be run immediately, plug and play.

Additionally: The web is the only truly universal platform where your applications can be accessed on any device. This also allows you to maintain a single codebase, simplify updates, and ensure that all users can access your applications. WASM supports 64-bit and 32-bit integer operations, corresponding to CPU instructions one by one. By removing floating-point operations, determinism can be easily achieved, which is necessary for consensus algorithms. Supported by the LLVM compiler infrastructure project, this means that WASM can benefit from over a decade of compiler optimizations in LLVM. WASM is continuously developed by major companies such as Google, Apple, Microsoft, Mozilla, and Facebook, and is supported in the backends of browsers developed by these major companies.
The beauty of WASM is that it is like a magic engine that can run anywhere, without the need for downloading or installation, because it is in binary format. With just one click, web applications can run immediately when needed. It is more secure than downloading and running binary files directly, as the browser has built-in security mechanisms to prevent the code running in it from harming your system. Sharing web applications is also simple - links can be placed anywhere as clickable strings.

2. Why Do We Need Web Assembly
2.1 Web2
Due to the built-in features of browsers and the interactivity provided by the web, the web has evolved from static hypertext content and small script languages to a very powerful and popular platform, full of amazing applications and features. However, up to now, web applications are still mainly driven by the same scripting language (JavaScript), which was not originally designed to achieve these.
JavaScript was initially a simple scripting language designed to bring some interactivity to lightweight hypertext documents for web applications. Its design is easy to learn and write, and it does not aim for execution speed. Over the years, significant performance improvements in JavaScript parsing by browsers have brought about significant performance improvements.
With the faster execution speed of JavaScript, the range of things that can be executed in browsers has greatly expanded. New APIs have brought features such as interactive graphics, video streaming, offline browsing, and more. Meanwhile, more and more applications (previously limited to local applications) have begun to enter the web. Now you can easily edit documents and send emails in the browser, but in some areas, the performance of JavaScript is still a challenge. Think about the software you use besides the browser: games, video editing, 3D rendering, or music production. These applications require a large amount of computation and high performance. JavaScript is difficult to meet these high-performance requirements.
However, replacing JavaScript is not very practical, and it may even take decades to accomplish, because the entire Internet depends on it. Moreover, there are a lot of people constantly improving JavaScript. Indeed, compared to other languages, JavaScript is a bit lacking in some aspects such as null and ==, but these issues are not enough to replace the entire technology.
So, WebAssembly will not replace JavaScript, but that does not mean that no one will use WASM in the future. In fact, the use of WASM will become more and more widespread. Because WASM can bring powerful computing capabilities to web pages, such as image processing or games. With WASM, a web-based version of Photoshop can be created and run well, or a 3D game that runs at 60 frames per second or even higher in the browser. Games are particularly challenging because they need to simultaneously execute audio and video processing, as well as coordinate physical effects and AI. WASM has the ability to efficiently run games in the browser, opening up the possibility of bringing many other applications to the browser.


The above figure shows a comparison of the workflow between JavaScript and Wasm, and it can be seen that Wasm is much more concise compared to JavaScript.
**2.2 Web3**
**WASM VM**
In 2018, discussions began within the Ethereum ecosystem about using the WASM VM as a smart contract virtual machine because it was considered to have better performance than EVM. Gavin Wood, the inventor of EVM, has mentioned the feasibility of WASM replacing EVM, and Vitalik has also stated that Ethereum 2.0 will upgrade to Wasm contracts (eWASM) to meet more development needs. Now, the development of Wasm contracts has taken shape.
**2.3 How is EVM designed? Why is it inefficient?**
**Large Architecture Size**
Traditional computers' instruction sets only accept 32-bit or 64-bit inputs. EVM is different and very special; it is a 256-bit computer, intentionally designed this way to make it easier to handle Ethereum's hash algorithm, which explicitly produces 256-bit outputs.
However, the actual computer running EVM programs needs to split the 256-bit words into their native architecture to execute smart contracts, making the entire system very inefficient and impractical.
In addition, if you want to implement a complex algorithm similar to SHA256 using its basic OPCODES on Ethereum, you're in for a tough time! To address the high gas costs of running complex programs through the instruction set, Ethereum introduced the concept of precompiles, compiling programs into EVM and consuming fixed gas. A notable precompile is the Ethereum hash algorithm, as implementing this algorithm in the virtual machine would result in extremely expensive costs when calling the contract.
**Bulky Precompiles**
The problem with precompiles is that they continually increase the bulkiness and complexity of the virtual machine, without solving the core problem: the inefficient and crude design of the current instruction set and specification.
If we could define a new specification and instruction set that does not require precompiling these complex programs, but only needs to be efficiently implemented through basic instructions, then WASM comes into play.
**2.4 Comparison of EVM and WASM VM**
- **Speed:** WASM aims to provide faster execution speed than EVM. EVM may have efficiency issues in handling the compilation and execution of smart contracts, while WASM improves loading speed and processing capabilities by directly converting to compiled code.
- **Precompiles:** EVM relies on precompiled contracts to efficiently execute cryptographic calculations, but this may pose risks of hard forks. WASM eliminates the reliance on precompiled contracts, allowing developers to create efficient and fast smart contracts.
- **Transaction Costs:** With a faster Wasm virtual machine, transaction throughput is greatly increased, leading to significantly reduced contract deployment and transaction costs. Wasm contracts effectively address the high transaction fees and congestion issues on Ethereum.
The EWASM team is integrating WebAssembly into Ethereum to ensure a more efficient and simple execution layer, suitable for a fully decentralized computing platform. WASM has been adopted as a standard by many other projects, including Dfinity and EOS, to strengthen their execution layers.
**2.5 Stylus (Arbitrum)**
The Stylus project aims to improve the performance of smart contract execution on the Ethereum Layer 2 network Arbitrum by introducing the WebAssembly (WASM) virtual machine. Contracts can be executed faster than Solidity, while reducing gas costs. This makes it easier to build high-performance smart contracts on the Arbitrum network, currently supporting compilation in C, C++, and Rust.
**Custom Precompile Support:** Stylus also supports custom precompiles, allowing developers to deploy their own Rust or C++ precompiles on the Arbitrum network. This can help introduce new encryption algorithms or other specific features on-chain without waiting for on-chain upgrades.
**Interoperability with EVM:** Stylus achieves integration with the existing Ethereum ecosystem through interoperability with the Ethereum Virtual Machine (EVM). This means that Stylus contracts can interoperate with existing EVM contracts and share the same global state as EVM.
**Reentrancy Feature:** Unlike Cosmos wasm, the Stylus Rust SDK introduces a reentrancy feature and allows developers to enable it manually. This allows contracts to interoperate more flexibly, but developers need to carefully manage state to ensure security.
Based on the popularity of the Arbitrum ecosystem, Stylus may be the most meaningful integration of WASM, and it also benefits the competitiveness of Arbitrum in zkrollup.
**2.6 Gear (Polkadot)**
The Gear protocol is creating a technology that can be deployed as a Polkadot parachain, serving as a tool for hosting smart contracts. Like Polkadot, Gear also uses the Substrate framework, simplifying the process of creating different blockchains for specific applications. Substrate provides extensive features out of the box, allowing people to focus on creating custom engines on top of the protocol.
Previously, the cost of launching a blockchain was high, but Gear allows 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 in different languages such as Rust, C, C++, etc. Gear allows control over a fixed amount of memory for each program. Programs can only read and write in their own memory and cannot access the memory space of other programs. Each program has its own independent memory space and can process information in parallel on Gear nodes.
**2.7 CosmWasm (Cosmos)**
CosmWasm is a modern, powerful WebAssembly-based smart contract platform that can be easily integrated into Cosmos-SDK. One of the main advantages of CosmWasm is that contracts written with CosmWasm are tightly integrated with the native Inter-Blockchain Communication (IBC) protocol in the Cosmos ecosystem, allowing developers and users to enter a multi-chain future, currently only supporting Rust.
**Advantages of CosmWasm**
- **Security:** Enhances the security of smart contracts using the Rust language.
- **Cross-Chain Compatibility:** Supports the IBC (Inter-Blockchain Communication) protocol in the Cosmos ecosystem.
- **Performance:** In some cases, CosmWasm demonstrates higher efficiency and lower transaction costs compared to traditional EVM (Ethereum Virtual Machine).
- **Developer-Friendly:** The type safety and memory safety features of the Rust language reduce certain types of errors in smart contracts.
This concludes the translation of the provided text.**Challenges and Limitations**
1. **Learning Curve:** Rust, compared to more commonly used smart contract languages like Solidity, may have a steeper learning curve for beginners. CosmWASM needs to support more language compilations to have the potential for widespread adoption.
2. **Ecosystem and Tool Support:** While growing, the development tools and ecosystem of CosmWASM may still be relatively limited compared to mature smart contract platforms like Ethereum.
3. **Market Share and Recognition:** In the smart contract platform space, CosmWASM may not have high recognition compared to Ethereum, Binance Smart Chain, etc., affecting its ability to attract developers and users.
4. **Maintenance and Upgrade Challenges:** Although CosmWASM provides contract upgrade functionality, managing the maintenance and upgrades of smart contracts remains a complex task that requires careful handling to avoid security vulnerabilities.
5. **Compatibility Issues:** Projects accustomed to EVM or other smart contract environments may face compatibility challenges when migrating to CosmWASM.
**2.8 ZK-WASM**
In addition to the wasm virtual machine, there is a recent emerging technology called ZKWASM. The inventor, Delphinus Labs, has open-sourced the code for ZK-WASM on GitHub. ZKWASM allows developers to verify the correctness of previously executed computations without re-executing them. By leveraging ZKWASM, developers can flexibly build ZKP applications using various programming languages. These applications can seamlessly run in web browsers.
The concept of ZKWASM is derived from ZKSNARK, which is a hybrid of SNARG and zero-knowledge proofs. Typically, to use ZKSNARK, you need to write a program in an arithmetic circuit language or circuit-friendly language, such as Pinocchio, TinyRAM, Buffet/Pequin, Geppetto, xJsnark framework, ZoKrates, etc. This to some extent poses a barrier for existing programs to fully utilize the power of ZKSNARK. However, there is another way, not to use ZKSNARK at the source code level, but to use it at the bytecode level of the virtual machine, and then implement a virtual machine that supports ZKSNARK. Delphinus Labs has adopted the latter approach, integrating the entire WASM virtual machine into ZKSNARK circuits. As a result, existing WASM applications can run directly on ZKWASM without any modifications. Therefore, cloud service providers can prove to any user that the computation results are honest and do not leak any private information.
ZKWASM provides various use cases, such as allowing ZK proofs of some operations in the browser to be put on-chain, achieving verifiable blockchain operations in web pages. For example, oracles, off-chain computation, automation, bridging Web2 and Web3, and generating proofs for machine learning and data processing, and even games and social applications. With increasing adoption, ZKWASM will expand the possibilities of Web3 and bring Web2 developers into this transformative landscape.
Through Delphinus Lab's ZKWASM implementation, 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 landscape.
**Conclusion**
The future of the web's performance and the execution layer of smart contract platforms is bright. Not only will dApps have higher performance, but integrating WASM will also make it easier for those familiar with robust mainstream languages like Rust and Go to develop smart contracts, without needing to learn the various details of solidity or other blockchain development languages to develop useful applications on Ethereum. According to data from Evans Data Corporation, there are nearly 27 million developers worldwide. This number is steadily growing - it increased by about 3% last year and is expected to exceed 28.7 million by 2024. However, the number of developers on the blockchain is less than 30,000, accounting for about one-thousandth of the total number of developers. Although this number has been steadily increasing, learning new smart contract languages may still be a barrier for developers to enter the blockchain.
But more and more blockchains are starting 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 lowers the barrier for developers to enter the blockchain. Imagine in the near future, when Web2 developers want to try blockchain development, they can use their familiar Python, C++, JavaScript to develop large-scale applications on the blockchain, maximizing the value of decentralized networks, first by lowering the threshold for creators (developers), and then lowering the threshold for users, moving towards Mass Adoption.
Thank you to Maggie, Xinyou Ji (CMU) for their suggestions and guidance on this article.
**References**
- [https://blog.scottlogic.com/2022/06/20/state-of-wasm-2022.html](https://blog.scottlogic.com/2022/06/20/state-of-wasm-2022.html)
- [https://www.notion.so/18f67cee15c147dfae68b06269a455c0?pvs=21](https://www.notion.so/18f67cee15c147dfae68b06269a455c0?pvs=21)
- [https://wiki.polkadot.network/docs/learn-wasm](https://wiki.polkadot.network/docs/learn-wasm)
- [https://docs.arbitrum.io/stylus/stylus-gentle-introduction](https://docs.arbitrum.io/stylus/stylus-gentle-introduction)
- [https://medium.com/@gear_techs/introducing-gear-easy-to-use-polkadot-parachain-9ccd05437a9c](https://medium.com/@gear_techs/introducing-gear-easy-to-use-polkadot-parachain-9ccd05437a9c)
- [https://medium.com/cosmwasm/cosmwasm-for-ctos-f1ffa19cccb8](https://medium.com/cosmwasm/cosmwasm-for-ctos-f1ffa19cccb8)
- [https://www.cncf.io/wp-content/uploads/2023/09/The-State-of-WebAssembly-2023.pdf](https://www.cncf.io/wp-content/uploads/2023/09/The-State-of-WebAssembly-2023.pdf)
- [https://github.com/DelphinusLab/zkWasm](https://github.com/DelphinusLab/zkWasm)
免责声明:本文章仅代表作者个人观点,不代表本平台的立场和观点。本文章仅供信息分享,不构成对任何人的任何投资建议。用户与作者之间的任何争议,与本平台无关。如网页中刊载的文章或图片涉及侵权,请提供相关的权利证明和身份证明发送邮件到support@aicoin.com,本平台相关工作人员将会进行核查。