WebAssembly (Wasm) is a portable, high-performance binary instruction format that can run in web browsers. It is designed as a universal compilation target that can be used with multiple programming languages and 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 recording transactions, storing data, and executing smart contracts, among other applications.
There are several relationships and application scenarios between Wasm and blockchain:
In summary, the combination of Wasm and blockchain provides more efficient, secure, and flexible blockchain applications and services. The portability and high performance of Wasm make it an important technology in the field of blockchain.
WebAssembly is an efficient and lightweight instruction set standard developed by the World Wide Web Consortium (W3C). It is hailed as a disruptor for the web and high-performance computing, supporting cross-browser execution. This means that we can compile different programming languages, including C/C++, Go, Rust, and more, into a unified standard binary format and use it as a replacement for JavaScript, running with near-native code efficiency in web browsers.
WebAssembly, also known as WASM, is a memory-safe and platform-independent technology that can efficiently map to different CPU architectures. It offers several key advantages:
In addition, the Web is the only true universal platform that allows access to your applications on any device. This also enables 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, which directly correspond to CPU instructions. By removing floating-point operations, deterministic behavior can be easily achieved, which is necessary for consensus algorithms. Supported by the LLVM compiler infrastructure project, 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 it is supported by the backends of browsers developed by these companies.
The beauty of WASM lies in its ability to run anywhere without the need for downloading or installing, as it is in binary format. With just one click, web applications can be executed immediately when needed. It is even more secure than directly downloading and running binary files, as browsers have built-in security mechanisms that prevent the executed code from harming your system. Additionally, sharing web applications is simple - links can be placed anywhere as clickable strings.
Web has evolved from a platform for static content and small script languages to a powerful and popular platform filled with amazing applications and features, thanks to the built-in functionality of browsers and the interactivity provided by the Web. However, Web applications are still predominantly driven by the same scripting language (JavaScript), which was not initially designed to accomplish these tasks.
JavaScript was initially a simple scripting language aimed at bringing interactivity to lightweight hypertext documents in Web applications. Its design was easy to learn and write, and it did not prioritize runtime speed. Over the years, significant performance improvements in JavaScript parsing by browsers have led to notable performance boosts.
With the accelerated speed of JavaScript execution, the range of things that can be done within browsers has expanded significantly. New APIs have introduced features such as interactive graphics, video streaming, offline browsing, and more. Moreover, an increasing number of applications that were previously limited to desktop environments have entered the Web. Now you can easily edit documents and send emails in your browser. However, in certain domains, the performance of JavaScript remains a challenge. Think about software applications you use besides browsers: games, video editing, 3D rendering, or music production. These applications require extensive computations and high performance. JavaScript struggles to meet these high-performance requirements.
However, it is not practical to replace JavaScript, and it might even take decades to achieve that goal, as the entire Internet relies on it. Moreover, there is a large community constantly improving JavaScript. Indeed, compared to other languages, JavaScript has some shortcomings in aspects such as null and ==. However, these issues are not severe enough to warrant replacing the entire technology.
So, WebAssembly will not replace JavaScript, but that doesn’t mean that WASM won’t be used in the future. In fact, the use of WASM will become more and more widespread. This is because WASM can bring powerful computational capabilities to the web, such as image processing or games. With WASM, you can create a web-based version of Photoshop that runs well, or a 3D game that runs at 60 frames per second or even higher frame rates in the browser. Games, in particular, present a challenge because they require simultaneous execution of audio and video processing, as well as coordination of physics effects and AI. WASM has the ability to efficiently run games in the browser, opening the door to bringing many other applications to the browser.
The figure above shows a comparison of the workflow between JavaScript and WebAssembly (wasm). It can be observed that wasm is much more concise compared to JavaScript.
WASM VM
In 2018, the Ethereum ecosystem began discussing the use of a WASM VM as a smart contract virtual machine, as it was considered to have better performance than the EVM. Gavin Wood, the inventor of the EVM, has expressed the feasibility of replacing it with WASM, and Vitalik has also stated that Ethereum 2.0 will be upgraded to support WASM contracts (eWASM) to meet more development needs. Today, the development of WASM contracts has already taken shape.
Architecture Size Issue
Traditional computers have instruction sets that accept input of 32 or 64 bits. EVM, however, is different and unique as it is a 256-bit computer designed to handle Ethereum’s hash algorithm more easily, which produces explicit 256-bit outputs.
However, the actual computer running EVM programs needs to split the 256-bit words into their native architectures to execute smart contracts, making the entire system inefficient and impractical.
Additionally, if you want to implement a complex algorithm like SHA256 using EVM’s basic OPCODES on Ethereum, you’re in for a tough time! To address the high gas cost issue of running complex programs through the instruction set, Ethereum introduced the concept of precompiles, which compiles the program into EVM and consumes a fixed amount of gas. A notable precompile is the Ethereum hash algorithm, as implementing it within the virtual machine would result in extremely expensive fees when contracts are called.
Bloated Precompilation
The problem with precompilation is that it continuously increases the bloatedness and complexity of the virtual machine, without addressing the core issue: the inefficient and poor design of the current instruction set and specifications.
What if we could define a new specification and instruction set that doesn’t require precompilation of these complex programs, but instead efficiently achieves the desired results through basic instructions? This is where WASM comes into play.
The EWASM team is currently integrating WebAssembly on Ethereum to ensure a more efficient and simplified execution layer, making Ethereum suitable as a fully decentralized computing platform. WASM has been adopted as a standard by many other projects, including Dfinity and EOS, both using it to enhance their execution layers.
The Stylus project is an initiative on the Arbitrum Ethereum Layer 2 network that aims to improve the performance of smart contract execution by introducing the WebAssembly (WASM) virtual machine. Contracts can be executed faster than with Solidity, while reducing gas costs. This makes it easier to build high-performance smart contracts on the Arbitrum network, and currently supports compilation in C, C++, and Rust.
Custom Precompile Support: Stylus also supports custom precompiles, which allows developers to deploy their own Rust or C++ precompiles to the Arbitrum network. This can help introduce new cryptographic algorithms or other specific functionalities on-chain without waiting for on-chain upgrades. For example, tensor computation can be precompiled to reduce inference costs, which can be beneficial for 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 that Stylus contracts can interact with existing EVM contracts and share the same global state as the EVM.
Reentrancy: Unlike Cosmos Wasm, Stylus Rust SDK introduces a reentrancy feature and allows developers to enable it manually. This enables contracts to have more flexibility in interoperability, but developers need to carefully manage the state to ensure security.
Based on the thriving ecosystem of Arbitrum, the integration of Stylus is perhaps the most meaningful WASM integration. It also enhances the competitiveness of Arbitrum among zkRollup fields.
The Gear protocol is creating a technology that can be deployed as a Polkadot parachain, serving as a tool for hosting smart contracts. Similar to Polkadot, Gear also utilizes the Substrate framework, which simplifies the process of creating different blockchains for specific applications. Substrate provides out-of-the-box functionality, 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 instead of 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, and C++. For developers from outside the crypto world, the barrier to entry is low because they can build smart contracts in a familiar environment. Developers find it easier to experiment with smart contract programming languages.
Gear’s smart contract architecture utilizes the Actor Model under the hood and provides the following functionalities:
Each program has a fixed amount of memory, which Gear allows control over. A program can only read and write in its own memory and cannot access the memory space of other programs. Each program has its own independent memory space, and information on Gear nodes can be processed in parallel.
CosmWasm is a modern and powerful Wasm-based smart contract platform that can easily integrate with Cosmos-SDK. This showcases one of the main advantages of CosmWasm: contracts written with CosmWasm are tightly integrated with IBC (Inter-Blockchain Communication) natively, allowing developers and users to enter a multi-chain future. Currently, only Rust is supported.
Advantages of CosmWasm
Challenges and Limitations
In addition to the wasm virtual machine, there is also 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 executed computations without re-executing them. By leveraging ZKWASM, developers can flexibly build zero-knowledge proof (ZKP) applications using various programming languages. These applications can seamlessly execute in web browsers.
ZKWASM is derived from ZKSNARK, which is a combination of SNARG and zero-knowledge proofs. Let’s explain it further. Typically, 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 framework, ZoKrates, etc. This poses a barrier to existing programs, making it difficult for them to leverage the power of ZKSNARK. However, there is another way, which is not to use ZKSNARK at the source code level but at the bytecode level of a virtual machine, and then implement a virtual machine that supports ZKSNARK. Delphinus Labs has adopted the latter approach by incorporating the entire WASM virtual machine into a ZKSNARK circuit. 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 computed honestly and will not disclose any private information.
ZKWASM provides various use cases, such as enabling the on-chain verification of operations performed in the browser. It allows for web-based interactions that are verifiable on the blockchain. Other use cases include oracle services, off-chain computation, automation, bridging the gap between Web2 and Web3, generating proofs for machine learning and data processing, and even gaming and social applications. With increasing adoption, zkWASM expands the possibilities of Web3 and integrates 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 trusted and decentralized digital ecosystem.
Web’s performance and the future of smart contract platform execution layer are promising. Not only will dApps have higher performance, but integrating WASM will also make it easier for those familiar with mainstream languages like Rust and Go to develop smart contracts, without having to learn the intricacies of solidity or other blockchain development languages. According to Evans Data Corporation, there are nearly 27 million developers worldwide, and this number is steadily growing, with an expected increase to over 28.7 million by 2024. However, the number of developers in the blockchain field is still less than 30,000, accounting for only about one-thousandth of the total number of developers. Although this number is steadily increasing, learning new smart contract languages may still be a barrier for developers to enter the blockchain industry.
But more and more blockchains are starting to support Web Assembly as the bytecode for compiled smart contracts. WASM brings efficiency, interoperability, and a wide range of use cases to blockchains. It also serves as the key to unlock the door for developers, lowering the barrier to entry into blockchain development. Just imagine, in the near future, when Web 2.0 developers want to try their hand at blockchain development, they can use familiar languages like Python, C++, and JavaScript to build large-scale applications on the blockchain, maximizing the value of decentralized networks. First, lower the barrier for creators (developers), then lower the barrier for users, and move towards mass adoption.
https://blog.scottlogic.com/2022/06/20/state-of-wasm-2022.html
https://www.notion.so/18f67cee15c147dfae68b06269a455c0?pvs=21
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
https://github.com/DelphinusLab/zkWasm
Thank you to Maggie and Xinyou Ji (CMU) for their advice and guidance on this article.
Disclaimer: All articles from Foresight Ventures are not intended as investment advice. Investments involve risks, so please assess your own risk tolerance and make investment decisions carefully.
WebAssembly (Wasm) is a portable, high-performance binary instruction format that can run in web browsers. It is designed as a universal compilation target that can be used with multiple programming languages and 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 recording transactions, storing data, and executing smart contracts, among other applications.
There are several relationships and application scenarios between Wasm and blockchain:
In summary, the combination of Wasm and blockchain provides more efficient, secure, and flexible blockchain applications and services. The portability and high performance of Wasm make it an important technology in the field of blockchain.
WebAssembly is an efficient and lightweight instruction set standard developed by the World Wide Web Consortium (W3C). It is hailed as a disruptor for the web and high-performance computing, supporting cross-browser execution. This means that we can compile different programming languages, including C/C++, Go, Rust, and more, into a unified standard binary format and use it as a replacement for JavaScript, running with near-native code efficiency in web browsers.
WebAssembly, also known as WASM, is a memory-safe and platform-independent technology that can efficiently map to different CPU architectures. It offers several key advantages:
In addition, the Web is the only true universal platform that allows access to your applications on any device. This also enables 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, which directly correspond to CPU instructions. By removing floating-point operations, deterministic behavior can be easily achieved, which is necessary for consensus algorithms. Supported by the LLVM compiler infrastructure project, 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 it is supported by the backends of browsers developed by these companies.
The beauty of WASM lies in its ability to run anywhere without the need for downloading or installing, as it is in binary format. With just one click, web applications can be executed immediately when needed. It is even more secure than directly downloading and running binary files, as browsers have built-in security mechanisms that prevent the executed code from harming your system. Additionally, sharing web applications is simple - links can be placed anywhere as clickable strings.
Web has evolved from a platform for static content and small script languages to a powerful and popular platform filled with amazing applications and features, thanks to the built-in functionality of browsers and the interactivity provided by the Web. However, Web applications are still predominantly driven by the same scripting language (JavaScript), which was not initially designed to accomplish these tasks.
JavaScript was initially a simple scripting language aimed at bringing interactivity to lightweight hypertext documents in Web applications. Its design was easy to learn and write, and it did not prioritize runtime speed. Over the years, significant performance improvements in JavaScript parsing by browsers have led to notable performance boosts.
With the accelerated speed of JavaScript execution, the range of things that can be done within browsers has expanded significantly. New APIs have introduced features such as interactive graphics, video streaming, offline browsing, and more. Moreover, an increasing number of applications that were previously limited to desktop environments have entered the Web. Now you can easily edit documents and send emails in your browser. However, in certain domains, the performance of JavaScript remains a challenge. Think about software applications you use besides browsers: games, video editing, 3D rendering, or music production. These applications require extensive computations and high performance. JavaScript struggles to meet these high-performance requirements.
However, it is not practical to replace JavaScript, and it might even take decades to achieve that goal, as the entire Internet relies on it. Moreover, there is a large community constantly improving JavaScript. Indeed, compared to other languages, JavaScript has some shortcomings in aspects such as null and ==. However, these issues are not severe enough to warrant replacing the entire technology.
So, WebAssembly will not replace JavaScript, but that doesn’t mean that WASM won’t be used in the future. In fact, the use of WASM will become more and more widespread. This is because WASM can bring powerful computational capabilities to the web, such as image processing or games. With WASM, you can create a web-based version of Photoshop that runs well, or a 3D game that runs at 60 frames per second or even higher frame rates in the browser. Games, in particular, present a challenge because they require simultaneous execution of audio and video processing, as well as coordination of physics effects and AI. WASM has the ability to efficiently run games in the browser, opening the door to bringing many other applications to the browser.
The figure above shows a comparison of the workflow between JavaScript and WebAssembly (wasm). It can be observed that wasm is much more concise compared to JavaScript.
WASM VM
In 2018, the Ethereum ecosystem began discussing the use of a WASM VM as a smart contract virtual machine, as it was considered to have better performance than the EVM. Gavin Wood, the inventor of the EVM, has expressed the feasibility of replacing it with WASM, and Vitalik has also stated that Ethereum 2.0 will be upgraded to support WASM contracts (eWASM) to meet more development needs. Today, the development of WASM contracts has already taken shape.
Architecture Size Issue
Traditional computers have instruction sets that accept input of 32 or 64 bits. EVM, however, is different and unique as it is a 256-bit computer designed to handle Ethereum’s hash algorithm more easily, which produces explicit 256-bit outputs.
However, the actual computer running EVM programs needs to split the 256-bit words into their native architectures to execute smart contracts, making the entire system inefficient and impractical.
Additionally, if you want to implement a complex algorithm like SHA256 using EVM’s basic OPCODES on Ethereum, you’re in for a tough time! To address the high gas cost issue of running complex programs through the instruction set, Ethereum introduced the concept of precompiles, which compiles the program into EVM and consumes a fixed amount of gas. A notable precompile is the Ethereum hash algorithm, as implementing it within the virtual machine would result in extremely expensive fees when contracts are called.
Bloated Precompilation
The problem with precompilation is that it continuously increases the bloatedness and complexity of the virtual machine, without addressing the core issue: the inefficient and poor design of the current instruction set and specifications.
What if we could define a new specification and instruction set that doesn’t require precompilation of these complex programs, but instead efficiently achieves the desired results through basic instructions? This is where WASM comes into play.
The EWASM team is currently integrating WebAssembly on Ethereum to ensure a more efficient and simplified execution layer, making Ethereum suitable as a fully decentralized computing platform. WASM has been adopted as a standard by many other projects, including Dfinity and EOS, both using it to enhance their execution layers.
The Stylus project is an initiative on the Arbitrum Ethereum Layer 2 network that aims to improve the performance of smart contract execution by introducing the WebAssembly (WASM) virtual machine. Contracts can be executed faster than with Solidity, while reducing gas costs. This makes it easier to build high-performance smart contracts on the Arbitrum network, and currently supports compilation in C, C++, and Rust.
Custom Precompile Support: Stylus also supports custom precompiles, which allows developers to deploy their own Rust or C++ precompiles to the Arbitrum network. This can help introduce new cryptographic algorithms or other specific functionalities on-chain without waiting for on-chain upgrades. For example, tensor computation can be precompiled to reduce inference costs, which can be beneficial for 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 that Stylus contracts can interact with existing EVM contracts and share the same global state as the EVM.
Reentrancy: Unlike Cosmos Wasm, Stylus Rust SDK introduces a reentrancy feature and allows developers to enable it manually. This enables contracts to have more flexibility in interoperability, but developers need to carefully manage the state to ensure security.
Based on the thriving ecosystem of Arbitrum, the integration of Stylus is perhaps the most meaningful WASM integration. It also enhances the competitiveness of Arbitrum among zkRollup fields.
The Gear protocol is creating a technology that can be deployed as a Polkadot parachain, serving as a tool for hosting smart contracts. Similar to Polkadot, Gear also utilizes the Substrate framework, which simplifies the process of creating different blockchains for specific applications. Substrate provides out-of-the-box functionality, 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 instead of 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, and C++. For developers from outside the crypto world, the barrier to entry is low because they can build smart contracts in a familiar environment. Developers find it easier to experiment with smart contract programming languages.
Gear’s smart contract architecture utilizes the Actor Model under the hood and provides the following functionalities:
Each program has a fixed amount of memory, which Gear allows control over. A program can only read and write in its own memory and cannot access the memory space of other programs. Each program has its own independent memory space, and information on Gear nodes can be processed in parallel.
CosmWasm is a modern and powerful Wasm-based smart contract platform that can easily integrate with Cosmos-SDK. This showcases one of the main advantages of CosmWasm: contracts written with CosmWasm are tightly integrated with IBC (Inter-Blockchain Communication) natively, allowing developers and users to enter a multi-chain future. Currently, only Rust is supported.
Advantages of CosmWasm
Challenges and Limitations
In addition to the wasm virtual machine, there is also 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 executed computations without re-executing them. By leveraging ZKWASM, developers can flexibly build zero-knowledge proof (ZKP) applications using various programming languages. These applications can seamlessly execute in web browsers.
ZKWASM is derived from ZKSNARK, which is a combination of SNARG and zero-knowledge proofs. Let’s explain it further. Typically, 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 framework, ZoKrates, etc. This poses a barrier to existing programs, making it difficult for them to leverage the power of ZKSNARK. However, there is another way, which is not to use ZKSNARK at the source code level but at the bytecode level of a virtual machine, and then implement a virtual machine that supports ZKSNARK. Delphinus Labs has adopted the latter approach by incorporating the entire WASM virtual machine into a ZKSNARK circuit. 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 computed honestly and will not disclose any private information.
ZKWASM provides various use cases, such as enabling the on-chain verification of operations performed in the browser. It allows for web-based interactions that are verifiable on the blockchain. Other use cases include oracle services, off-chain computation, automation, bridging the gap between Web2 and Web3, generating proofs for machine learning and data processing, and even gaming and social applications. With increasing adoption, zkWASM expands the possibilities of Web3 and integrates 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 trusted and decentralized digital ecosystem.
Web’s performance and the future of smart contract platform execution layer are promising. Not only will dApps have higher performance, but integrating WASM will also make it easier for those familiar with mainstream languages like Rust and Go to develop smart contracts, without having to learn the intricacies of solidity or other blockchain development languages. According to Evans Data Corporation, there are nearly 27 million developers worldwide, and this number is steadily growing, with an expected increase to over 28.7 million by 2024. However, the number of developers in the blockchain field is still less than 30,000, accounting for only about one-thousandth of the total number of developers. Although this number is steadily increasing, learning new smart contract languages may still be a barrier for developers to enter the blockchain industry.
But more and more blockchains are starting to support Web Assembly as the bytecode for compiled smart contracts. WASM brings efficiency, interoperability, and a wide range of use cases to blockchains. It also serves as the key to unlock the door for developers, lowering the barrier to entry into blockchain development. Just imagine, in the near future, when Web 2.0 developers want to try their hand at blockchain development, they can use familiar languages like Python, C++, and JavaScript to build large-scale applications on the blockchain, maximizing the value of decentralized networks. First, lower the barrier for creators (developers), then lower the barrier for users, and move towards mass adoption.
https://blog.scottlogic.com/2022/06/20/state-of-wasm-2022.html
https://www.notion.so/18f67cee15c147dfae68b06269a455c0?pvs=21
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
https://github.com/DelphinusLab/zkWasm
Thank you to Maggie and Xinyou Ji (CMU) for their advice and guidance on this article.
Disclaimer: All articles from Foresight Ventures are not intended as investment advice. Investments involve risks, so please assess your own risk tolerance and make investment decisions carefully.