Original author: Mike@Foresight Ventures
WebAssembly (Wasm for short) is a portable, high-performance binary instruction format that can run in a web browser. It is designed as a general-purpose compilation target that can be used in multiple 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, allowing contracts to run on different blockchain platforms. Wasms 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 implement cross-chain interaction functions. By compiling the logic of different blockchains into Wasm code, the same logic can be executed on different blockchains to achieve cross-chain data transmission and interaction.
Off-chain computation: Wasm can be used to perform computations outside the blockchain and submit the results to the blockchain. This can improve computing efficiency and flexibility while maintaining data security and credibility.
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, the privacy of the data can be protected while ensuring the verifiability of the calculation.
In short, Wasm and blockchain can be combined with each other to provide more efficient, secure and flexible blockchain applications and services. Wasms portability and high performance make it one of the important technologies in the blockchain field.
1. What is WebAssembly?
WebAssembly, or WASM for short, is memory-safe, platform-independent, and maps perfectly and efficiently to all types of CPU architectures, with the following key advantages:
Efficient: WASM has a complete set of language features. In fact, WASM is a binary format that is small in size and fast to load. Its goal is to fully utilize the capabilities of the hardware to achieve the execution efficiency of native languages.
Plus: The web is the only truly universal platform that makes your apps accessible on any device. This also allows you to maintain a single code base, simplifying updates and ensuring that all users can access your application. WASM supports 64-bit and 32-bit integer operations, corresponding to CPU instructions one-to-one. By removing floating point operations, determinism can be easily achieved, which is necessary for consensus algorithms.
Powered by the LLVM Compiler Infrastructure Project, this means Wasm can benefit from over a decade of LLVM compiler optimizations. WASM is continuously developed by major companies such as Google, Apple, Microsoft, Mozilla, and Facebook. The backends of browsers developed by these major companies all support wasm compilation.
The beauty of WASM is that it is like a magic engine, it can run anywhere, there is no need to download or install because it is in binary format. With just one click, you can run web applications immediately when you need them. It is more secure than downloading and running the binary directly because the browser has built-in security mechanisms so that the code running in it cannot harm your system. And sharing web applications is just as easy - links are clickable strings that can be placed anywhere.
2. Why do we need WebAssembly?
In 2018, the Ethereum ecosystem began to discuss using WASM VM as a smart contract virtual machine because it felt that its performance was better than EVM. Gavin Wood, the inventor of EVM, has expressed the feasibility of WASM replacing EVM, and Vitalik has also stated that Ethereum 2.0 will be upgraded to the Wasm contract (eWASM) to meet more development needs. Now, the development of Wasm contract has taken a certain shape.
2.3 How is EVM designed? Why is it inefficient?
Schema size is too large
Traditional computers contain instruction sets that accept only 32-bit or 64-bit input. The EVM is different and special in that it is a 256-bit computer, intentionally designed this way to make it easier to process Ethereums hashing algorithms, and it will explicitly produce 256-bit output.
However, the computer that actually runs the EVM program needs to split the 256-bit words into their native architecture to execute the smart contract, making the entire system very inefficient and impractical.
Also, if you want to implement a complex algorithm like SHA 256 on Ethereum using its basic OPCODES, then good luck! In order to solve the high gas problem caused by running complex programs through the instruction set, Ethereum introduced the concept of precompilation, which compiles the program into the EVM and consumes a fixed amount of gas. One precompilation worth paying attention to is the Ethereum hashing algorithm, because if this algorithm is implemented in a virtual machine, the contract will incur extremely expensive fees when called.
The problem with precompilation is that it continues to increase the bloat and complexity of the virtual machine without solving the core problem: the inefficient and poor design of the current instruction set and specification.
What if we could define a new specification and instruction set that didnt require precompiling these complex programs, but could be implemented efficiently with only basic instructions? This is where WASM comes in handy.
2.4 Comparison between EVM and WASM VM
speed: WASM is designed to provide faster execution than EVM. EVM may have efficiency issues when dealing with compiling and executing smart contracts, while WASM improves loading speed and processing power by directly converting to compiled code.
Precompiled: The EVM relies on precompiled contracts to efficiently perform cryptographic calculations, but this may lead to the risk of hard forks. WASM eliminates the dependence on precompiled contracts, allowing developers to create efficient and fast smart contracts.
transaction fee:The faster Wasm virtual machine can significantly increase transaction throughput, and contract deployment and transaction costs can also be significantly reduced. It can be said that the Wasm contract has solved the current problems of high transaction fees and transaction congestion on Ethereum.
The EWASM team is integrating WebAssembly on Ethereum to ensure that the execution layer of Ethereum is more efficient and simpler, making it suitable as a completely decentralized computing platform. WASM has been adopted as a standard by many other projects, including Dfinity and EOS both using it to power their execution layers.
The Stylus project improves the execution performance of smart contracts by introducing the WebAssembly (WASM) virtual machine on the Ethereum second-layer network Arbitrum. 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 precompilation 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 features on-chain without having to wait for on-chain upgrades. For example, tensor computation can be pre-compiled to reduce inference costs, which may be helpful for on-chain machine learning.
Interoperability with EVM:Stylus enables 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 with EVM.
Reentrancy:Unlike Cosmos wasm, Stylus Rust SDK introduces reentrancy and allows developers to manually enable it. This allows contracts to interoperate more flexibly, but requires developers 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 will also benefit arbitrums competitiveness in zkrollup.
Gear Protocol is creating a technology that can be deployed as a Polkadot parachain, which will be the tool for hosting smart contracts. Like Polkadot, Gear uses the Substrate framework. This simplifies the process of creating different blockchains for specific applications. Substrate provides a wide range of functionality out of the box, allowing people to focus on creating custom engines on top of the protocol.
Previously, launching a blockchain was expensive, but Gear allows dApp developers to focus on their own 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.). It has a low barrier to entry for developers coming from outside the crypto world, as they can build smart contracts in a familiar environment. It is easier for developers to try smart contract programming languages.
Gear’s smart contract architecture uses actor models under the hood and provides the following capabilities:
Providing persistent memory for immutable programs
Asynchronous message processing
Minimal, intuitive and adequate API surface for blockchain context
The actor communication proxy model between on-chain components provides higher composability, better compatibility with parallel code execution and sharding.
Each program has a fixed amount of memory, which Gear allows you to control. A program can only read and write in its own memory and cannot access the memory space of other programs. Each program has an independent memory space and can process information on the Gear node in parallel.
CosmWasm is a modern, powerful Wasm-based smart contract platform that easily plugs into the Cosmos-SDK. This demonstrates one of the main advantages of CosmWasm: contracts written in CosmWasm are natively and tightly integrated with IBC (Inter-Blockchain Communication), allowing developers and users to enter a multi-chain future, currently only supported in Rust.
Advantages of CosmWasm
safety:Improving the security of smart contracts using the Rust language.
Cross-chain compatibility:IBC (Inter-Blockchain Communication) protocol support in the Cosmos ecosystem.
performance:Compared to traditional EVM (Ethereum Virtual Machine), CosmWasm has demonstrated higher efficiency and lower transaction fees in some cases.
Developer friendly:The Rust language’s type-safety and memory-safety features reduce certain types of bugs in smart contracts.
challenges and limitations
learning curve: Compared to more commonly used smart contract languages such as Solidity, Rust may have a steeper learning curve for beginners. CosmWASM needs to support more language compilations to gain the possibility of mass adoption.
Ecosystem and tool support: Although growing, CosmWasm’s development tools and ecosystem may still be limited compared to mature smart contract platforms such as Ethereum.
Market share and popularity: Among smart contract platforms, CosmWasm may not be well-known compared to Ethereum, Binance Smart Chain, etc., which affects its ability to attract developers and users.
Maintenance and upgrade challenges: Although CosmWasm provides contract upgrade functions, the maintenance and upgrade management of smart contracts is still a complex task that needs to be handled carefully to avoid security vulnerabilities.
Compatibility issues: For projects that are accustomed to the EVM or other smart contract environments, migrating to CosmWasm may face compatibility challenges.
In addition to the wasm virtual machine, there is also a recent emerging technology ZKWASM. The inventor Delphinus Labs has open sourced the ZK-WASM code on github. ZKWASM enables developers to verify the correctness of performed calculations without re-executing them. By leveraging ZKWASM, developers have the flexibility to build ZKP applications using a variety of programming languages. These applications execute seamlessly in a Web browser.
The concept of ZKWASM comes from ZKSNARK, which is a hybrid of SNARG and zero-knowledge proof. Lets explain, usually, 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 poses an obstacle to existing programs to some extent, making it difficult for them to leverage the power of ZKSNARK. But 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 adopted the latter approach and wrote the entire WASM virtual machine into the ZKSNARK circuit, so that existing WASM applications can run directly on ZKWASM without any modification. Therefore, the cloud service provider can prove to any user that the calculation results were calculated honestly without revealing any private information.
ZKWASM provides various use cases, such as allowing ZK proofs of some operations in the browser to be uploaded to the chain. Make web page operation blockchain verifiable. Another example is oracles, off-chain computing, automation, connecting Web2 and Web3, and generating proofs for machine learning and data processing, and even games and social applications. As adoption increases, zkWASM will expand the possibilities of Web3 and bring Web2 developers into this transformative landscape.
Through Delphinus Labs 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.
The future is bright for the performance of the web and the execution layer of smart contract platforms. Not only will dApps have higher performance, integrating WASM will also make smart contract development easier for those who are familiar with the robustness of mainstream languages such as Rust and Go, rather than needing to learn Solidity or other blockchain development languages. Various details are needed to develop useful applications on Ethereum. According to Evans Data Corporation, there are nearly 27 million developers worldwide. This number is growing steadily - by about 3% last year and is expected to exceed 28.7 million by 2024. There are no more than 30,000 developers on the blockchain, accounting for about one thousandth of the total number of developers. Although this number has been steadily increasing, it may still be difficult for developers to learn new smart contract languages. The threshold for entering the blockchain.
https://www.notion.so/ 18 f 67 cee 15 c 147 dfae 68 b 06269 a 455 c 0 ?pvs=21
Thanks to Maggie, Xinyou Ji (CMU), and Sinka Gao (Delphinus Labs) for providing suggestions and guidance on this article.
About Foresight Ventures
Foresight Ventures is betting on the innovation process of cryptocurrency in the next few decades. It manages multiple funds: VC funds, secondary active management funds, multi-strategy FOF, and special purpose S fund Foresight Secondary Fund l. The total asset management scale exceeds 4 One hundred million U.S. dollars. Foresight Ventures adheres to the concept of Unique, Independent, Aggressive, Long-term and provides extensive support for projects through strong ecological power. Its team comes from senior people from top financial and technology companies including Sequoia China, CICC, Google, Bitmain and other top financial and technology companies.