You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Summary: Compare Polkadot’s dual smart contract VMs—REVM for EVM compatibility and PolkaVM for RISC-V performance, flexibility, and efficiency.
3198
+
3199
+
# Dual Virtual Machine Stack
3200
+
3201
+
!!! smartcontract "PolkaVM Preview Release"
3202
+
PolkaVM smart contracts with Ethereum compatibility are in **early-stage development and may be unstable or incomplete**.
3203
+
## Introduction
3204
+
3205
+
Polkadot's smart contract platform supports two distinct virtual machine (VM) architectures, providing developers with flexibility in selecting the optimal execution backend for their specific needs. This approach strikes a balance between immediate Ethereum compatibility and long-term innovation, enabling developers to deploy either unmodified (Ethereum Virtual Machine) EVM contracts using Rust Ethereum Virtual Machine (REVM) or optimize for higher performance using PolkaVM (PVM).
3206
+
3207
+
Both VM options share common infrastructure, including RPC interfaces, tooling support, and precompiles. The following sections compare architectures and guide you in selecting the best VM for your project's needs.
3208
+
3209
+
## Migrate from EVM
3210
+
3211
+
The [REVM backend](https://github.com/bluealloy/revm){target=\_blank} integrates a complete Rust implementation of the EVM, enabling Solidity contracts to run unchanged on Polkadot's smart contract platform.
3212
+
3213
+
REVM allows developers to use their existing Ethereum tooling and infrastructure to build on Polkadot. Choose REVM to:
3214
+
3215
+
- Migrate existing Ethereum contracts without modifications.
3216
+
- Retain exact EVM behavior for audit tools.
3217
+
- Use developer tools that rely upon inspecting EVM bytecode.
3218
+
- Prioritize rapid deployment over optimization.
3219
+
- Work with established Ethereum infrastructure and tooling to build on Polkadot.
3220
+
3221
+
REVM enables Ethereum developers to seamlessly migrate to Polkadot, achieving performance and fee improvements without modifying their existing contracts or developer tooling stack.
3222
+
3223
+
## Upgrade to PolkaVM
3224
+
3225
+
[**PolkaVM**](https://github.com/paritytech/polkavm){target=\_blank} is a custom virtual machine optimized for performance with [RISC-V-based](https://en.wikipedia.org/wiki/RISC-V){target=\_blank} architecture, supporting Solidity and additional high-performance languages. It serves as the core execution environment, integrated directly within the runtime. Choose the PolkaVM for:
3226
+
3227
+
- An efficient interpreter for immediate code execution.
3228
+
- A planned [Just In Time (JIT)](https://en.wikipedia.org/wiki/Just-in-time_compilation){target=\_blank} compiler for optimized performance.
3229
+
- Dual-mode execution capability, allowing selection of the most appropriate backend for specific workloads.
3230
+
- Optimized performance for short-running contract calls through the interpreter.
3231
+
3232
+
The interpreter remains particularly beneficial for contracts with minimal code execution, as it enables immediate code execution through lazy interpretation.
3233
+
3234
+
## Architecture
3235
+
3236
+
The following key components of PolkaVM work together to enable Ethereum compatibility on Polkadot-based chains.
3237
+
3238
+
### Revive Pallet
3239
+
3240
+
[**`pallet_revive`**](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/index.html){target=\_blank} is a runtime module that executes smart contracts by adding extrinsics, runtime APIs, and logic to convert Ethereum-style transactions into formats compatible with Polkadot SDK-based blockchains. It processes Ethereum-style transactions through the following workflow:
3241
+
3242
+
```mermaid
3243
+
sequenceDiagram
3244
+
participant User as User/dApp
3245
+
participant Proxy as Ethereum JSON RPC Proxy
3246
+
participant Chain as Blockchain Node
3247
+
participant Pallet as pallet_revive
3248
+
3249
+
User->>Proxy: Submit Ethereum Transaction
3250
+
Proxy->>Chain: Repackage as Polkadot Compatible Transaction
3251
+
Chain->>Pallet: Process Transaction
3252
+
Pallet->>Pallet: Decode Ethereum Transaction
3253
+
Pallet->>Pallet: Execute Contract via PolkaVM
3254
+
Pallet->>Chain: Return Results
3255
+
Chain->>Proxy: Forward Results
3256
+
Proxy->>User: Return Ethereum-compatible Response
3257
+
```
3258
+
3259
+
This proxy-based approach eliminates the need for node binary modifications, maintaining compatibility across different client implementations. Preserving the original Ethereum transaction payload simplifies the adaptation of existing tools, which can continue processing familiar transaction formats.
3260
+
3261
+
### PolkaVM Design Fundamentals
3262
+
3263
+
PolkaVM differs from the EVM in two key ways that make it faster, more hardware-efficient, and easier to extend:
3264
+
3265
+
- **Register-based design**: Instead of a stack machine, PolkaVM uses a RISC-V–style register model. This design:
3266
+
3267
+
- Uses a fixed set of registers to pass arguments, not an infinite stack.
3268
+
- Maps cleanly to real hardware like x86-64.
3269
+
- Simplifies compilation and boosts runtime efficiency.
3270
+
- Enables tighter control over register allocation and performance tuning.
3271
+
3272
+
- **64-bit word size**: PolkaVM runs on a native 64-bit word size, aligning directly with modern CPUs. This design:
3273
+
3274
+
- Executes arithmetic operations with direct hardware support.
3275
+
- Maintains compatibility with Solidity’s 256-bit types via YUL translation.
3276
+
- Accelerates computation-heavy workloads through native word alignment.
3277
+
- Integrates easily with low-level, performance-focused components.
- Summary: Discover PolkaVM, a high-performance smart contract VM for Polkadot, enabling Ethereum compatibility via pallet_revive, Solidity support & optimized execution.
6562
-
6563
-
# PolkaVM Design
6564
-
6565
-
!!! smartcontract "PolkaVM Preview Release"
6566
-
PolkaVM smart contracts with Ethereum compatibility are in **early-stage development and may be unstable or incomplete**.
6567
-
## Introduction
6568
-
6569
-
The Asset Hub smart contracts solution includes multiple components to ensure Ethereum compatibility and high performance. Its architecture allows for integration with current Ethereum tools, while its innovative virtual machine design enhances performance characteristics.
6570
-
6571
-
## PolkaVM
6572
-
6573
-
[**PolkaVM**](https://github.com/paritytech/polkavm){target=\_blank} is a custom virtual machine optimized for performance with [RISC-V-based](https://en.wikipedia.org/wiki/RISC-V){target=\_blank} architecture, supporting Solidity and additional high-performance languages. It serves as the core execution environment, integrated directly within the runtime. It features:
6574
-
6575
-
- An efficient interpreter for immediate code execution.
6576
-
- A planned JIT compiler for optimized performance.
6577
-
- Dual-mode execution capability, allowing selection of the most appropriate backend for specific workloads.
6578
-
- Optimized performance for short-running contract calls through the interpreter.
6579
-
6580
-
The interpreter remains particularly beneficial for contracts with minimal code execution, as it eliminates JIT compilation overhead and enables immediate code execution through lazy interpretation.
6581
-
6582
-
## Architecture
6583
-
6584
-
The smart contract solution consists of the following key components that work together to enable Ethereum compatibility on Polkadot-based chains.
6585
-
6586
-
### Pallet Revive
6587
-
6588
-
[**`pallet_revive`**](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/index.html){target=\_blank} is a runtime module that executes smart contracts by adding extrinsics, runtime APIs, and logic to convert Ethereum-style transactions into formats compatible with Polkadot SDK-based blockchains. It processes Ethereum-style transactions through the following workflow:
6589
-
6590
-
```mermaid
6591
-
sequenceDiagram
6592
-
participant User as User/dApp
6593
-
participant Proxy as Ethereum JSON RPC Proxy
6594
-
participant Chain as Blockchain Node
6595
-
participant Pallet as pallet_revive
6596
-
6597
-
User->>Proxy: Submit Ethereum Transaction
6598
-
Proxy->>Chain: Repackage as Polkadot Compatible Transaction
6599
-
Chain->>Pallet: Process Transaction
6600
-
Pallet->>Pallet: Decode Ethereum Transaction
6601
-
Pallet->>Pallet: Execute Contract via PolkaVM
6602
-
Pallet->>Chain: Return Results
6603
-
Chain->>Proxy: Forward Results
6604
-
Proxy->>User: Return Ethereum-compatible Response
6605
-
```
6606
-
6607
-
This proxy-based approach eliminates the need for node binary modifications, maintaining compatibility across different client implementations. Preserving the original Ethereum transaction payload simplifies adapting existing tools, which can continue processing familiar transaction formats.
6608
-
6609
-
### PolkaVM Design Fundamentals
6610
-
6611
-
PolkaVM introduces two fundamental architectural differences compared to the Ethereum Virtual Machine (EVM):
6612
-
6613
-
```mermaid
6614
-
flowchart TB
6615
-
subgraph "EVM Architecture"
6616
-
EVMStack[Stack-Based]
6617
-
EVM256[256-bit Word Size]
6618
-
end
6619
-
6620
-
subgraph "PolkaVM Architecture"
6621
-
PVMReg[Register-Based]
6622
-
PVM64[64-bit Word Size]
6623
-
end
6624
-
```
6625
-
6626
-
- **Register-based design**: PolkaVM utilizes a RISC-V register-based approach. This design:
6627
-
6628
-
- Employs a finite set of registers for argument passing instead of an infinite stack.
6629
-
- Facilitates efficient translation to underlying hardware architectures.
6630
-
- Optimizes register allocation through careful register count selection.
6631
-
- Enables simple 1:1 mapping to x86-64 instruction sets.
6632
-
- Reduces compilation complexity through strategic register limitation.
6633
-
- Improves overall execution performance through hardware-aligned design.
6634
-
6635
-
- **64-bit word size**: PolkaVM operates with a 64-bit word size. This design:
6636
-
6637
-
- Enables direct hardware-supported arithmetic operations.
6638
-
- Maintains compatibility with Solidity's 256-bit operations through YUL translation.
6639
-
- Allows integration of performance-critical components written in lower-level languages.
6640
-
- Optimizes computation-intensive operations through native word size alignment.
6641
-
- Reduces overhead for operations not requiring extended precision.
6642
-
- Facilitates efficient integration with modern CPU architectures.
6643
-
6644
-
## Compilation Process
6645
-
6646
-
When compiling a Solidity smart contract, the code passes through the following stages:
The compilation process integrates several specialized components:
6663
-
6664
-
1. **Solc**: The standard Ethereum Solidity compiler that translates Solidity source code to [YUL IR](https://docs.soliditylang.org/en/latest/yul.html){target=\_blank}.
6665
-
2. **Revive Compiler**: Takes YUL IR and transforms it to [LLVM IR](https://llvm.org/){target=\_blank}.
6666
-
3. **LLVM**: A compiler infrastructure that optimizes the code and generates RISC-V ELF objects.
6667
-
4. **PVM linker**: Links the RISC-V ELF object into a final PolkaVM blob with metadata.
0 commit comments