Difference between revisions of "WebAssembly"

From Internet Computer Wiki
Jump to: navigation, search
m
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''[https://webassembly.org/ WebAssembly] is a virtual machine (VM) designed for client, server and blockchain applications. It is used to run [[Canister smart contracts|canister]] smart contracts on the Internet Computer (IC). WebAssembly runs portable [[Glossary#byte-code|byte code]] instructions that are created by compiling software code written in programming languages such as [[Rust]] and [[Motoko]].'''
+
'''Canister smart contracts should be run efficiently and fast by the Internet Computer (IC). They are running WebAssembly (Wasm) code, which is a highly portable code format widely used for web-based applications as well as client-server and blockchain applications. Wasm is open-source, built for high-performance and efficiency and takes advantage of a wide community effort. Canister Wasm code is created by compiling software written in high-level programming languages such as Rust and Motoko. Because it’s faster, more efficient, and more portable than alternatives, Wasm is key to building efficient applications on the IC.'''
  
WebAssembly (or "WASM") was co-designed by Andreas Rossberg, who joined the [[Dfinity Foundation]] early in 2017 to work on its canister smart contract [[execution environment]], and the [[Motoko language]]. The standard is maintained by the [https://en.wikipedia.org/wiki/World_Wide_Web_Consortium World Wide Web Consortium].
+
== Portability & High-performance ==
 +
WebAssembly has quickly established itself as one of the Internet’s favorite code formats due to its portability, efficiency and wide-range community support. Most high-level languages can be compiled down to efficient and portable Wasm code. Wasm code can either be executed internally by browsers or run under virtual machines (VMs) with minimal overhead compared to native execution. For example, Cloudflare uses it to provide "cloud worker" functionality, and advanced blockchains can use it to run high performance smart contracts.
  
WebAssembly has quickly established itself as the internet's favorite virtual machine. Now every major web browser can run WASM modules imported by HTML, Cloudflare uses it to provide [https://blog.cloudflare.com/announcing-wasi-on-workers/ "cloud worker" functionality], and advanced blockchains can use it to run high performance smart contracts.
+
== Target of Many High-level Languages ==
 +
Most high level languages can nowadays be compiled down to Wasm. In addition to LLVM being able to target Wasm, popular languages such as C, C++, Rust, .NET are now efficiently compiled to Wasm as well. Andreas Rossberg, co-designer of WebAssembly, who joined the DFINITY Foundation in 2017, also led the effort to design the Motoko programming language, which is designed to take full advantage of WebAssembly features, and adapt them to reap special Internet Computer features such as actor model smart contracts and orthogonal persistence.
  
The Internet Computer uses the WebAssembly VM to run its canister smart contracts for a number of reasons, including:
+
== Execution of WebAssembly ==
 +
WebAssembly is platform independent and can execute on (m)any hardware and software platforms. Wasm code is intended to run on a stack-based virtual machine. There are many runtimes and virtual machines that enable Wasm execution either through a browser or as a separate sandboxed process. For the Internet Computer, the Wasmtime project is used to run user-defined canister smart contracts, which provides good performance. An important feature for the IC software stack is enforcing deterministic smart contract execution (to enable state machine replication). For Wasm, this is achieved through removing floating point and SIMD operations.
  
* It is formally specified, which increases its security.
+
== Security ==
 +
The execution of Wasm code can easily be sandboxed and isolated from the operation of other smart contracts and processes on the IC nodes. The IC protects against attacks using OS process isolation and sandboxing. Each canister is compiled and executed in its own sandboxed process that communicates only with the main replica process via security-audited IPC. Sandboxes are given the minimal set of permissions needed to execute using object-based access control (SELinux). Furthermore, Wasm code can be formally verified.
  
* It provides near-native performance, greatly improving smart contract efficiency.
+
== Features ==
 
+
In summary, there are several features of WebAssembly that enable it to be the code format for canister smart contracts on the Internet Computer:
* It is targeted by [https://en.wikipedia.org/wiki/LLVM LLVM], which means large numbers of programming languages can easily be used for smart contract creation.
+
*It is formally specified, which increases its security.
 
+
*It provides near-native performance, greatly improving smart contract efficiency.
* It has been very widely adopted as the new standard for computation on the Web, and consequently a massive decentralized R&D effort constantly evolves and improves the standard, and a large variety of virtual machine implementations have been created.
+
*It is targeted by LLVM, which means large numbers of programming languages can easily be used for smart contract creation.
 
+
*It has been very widely adopted as the new standard for computation on the Web, and consequently a massive decentralized R&D effort constantly evolves and improves the standard, and a large variety of virtual machine implementations have been created.
Andreas Rossberg has proposed several improvements to WebAssembly that are working their way through the standards process, including [https://github.com/WebAssembly/multi-memory WASM multi-memories], which will be used by the Internet Computer to add hardware parallelism to smart contracts, without the need to introduce concurrency constructs into smart contract code.
+
*Its execution can be made deterministic by not allowing floating point and SIMD operations.
 
+
*Its execution is memory-safe and sandboxed.
Andreas also led the effort to design the [[Motoko]] programming language, which is designed to take full advantage of WebAssembly features, and adapt them in respect of special Internet Computer features such as [[actor model]] smart contracts and [[orthogonal persistence]].
 

Latest revision as of 18:09, 18 November 2023

Canister smart contracts should be run efficiently and fast by the Internet Computer (IC). They are running WebAssembly (Wasm) code, which is a highly portable code format widely used for web-based applications as well as client-server and blockchain applications. Wasm is open-source, built for high-performance and efficiency and takes advantage of a wide community effort. Canister Wasm code is created by compiling software written in high-level programming languages such as Rust and Motoko. Because it’s faster, more efficient, and more portable than alternatives, Wasm is key to building efficient applications on the IC.

Portability & High-performance

WebAssembly has quickly established itself as one of the Internet’s favorite code formats due to its portability, efficiency and wide-range community support. Most high-level languages can be compiled down to efficient and portable Wasm code. Wasm code can either be executed internally by browsers or run under virtual machines (VMs) with minimal overhead compared to native execution. For example, Cloudflare uses it to provide "cloud worker" functionality, and advanced blockchains can use it to run high performance smart contracts.

Target of Many High-level Languages

Most high level languages can nowadays be compiled down to Wasm. In addition to LLVM being able to target Wasm, popular languages such as C, C++, Rust, .NET are now efficiently compiled to Wasm as well. Andreas Rossberg, co-designer of WebAssembly, who joined the DFINITY Foundation in 2017, also led the effort to design the Motoko programming language, which is designed to take full advantage of WebAssembly features, and adapt them to reap special Internet Computer features such as actor model smart contracts and orthogonal persistence.

Execution of WebAssembly

WebAssembly is platform independent and can execute on (m)any hardware and software platforms. Wasm code is intended to run on a stack-based virtual machine. There are many runtimes and virtual machines that enable Wasm execution either through a browser or as a separate sandboxed process. For the Internet Computer, the Wasmtime project is used to run user-defined canister smart contracts, which provides good performance. An important feature for the IC software stack is enforcing deterministic smart contract execution (to enable state machine replication). For Wasm, this is achieved through removing floating point and SIMD operations.

Security

The execution of Wasm code can easily be sandboxed and isolated from the operation of other smart contracts and processes on the IC nodes. The IC protects against attacks using OS process isolation and sandboxing. Each canister is compiled and executed in its own sandboxed process that communicates only with the main replica process via security-audited IPC. Sandboxes are given the minimal set of permissions needed to execute using object-based access control (SELinux). Furthermore, Wasm code can be formally verified.

Features

In summary, there are several features of WebAssembly that enable it to be the code format for canister smart contracts on the Internet Computer:

  • It is formally specified, which increases its security.
  • It provides near-native performance, greatly improving smart contract efficiency.
  • It is targeted by LLVM, which means large numbers of programming languages can easily be used for smart contract creation.
  • It has been very widely adopted as the new standard for computation on the Web, and consequently a massive decentralized R&D effort constantly evolves and improves the standard, and a large variety of virtual machine implementations have been created.
  • Its execution can be made deterministic by not allowing floating point and SIMD operations.
  • Its execution is memory-safe and sandboxed.