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
description: Overview of Polkadot's dual virtual machine architecture, offering flexibility in choosing the right execution backend for developers.
4
+
categories: Basics, Smart Contracts
5
+
---
6
+
1
7
# Dual Virtual Machine Stack
2
8
3
9
## Introduction
@@ -6,329 +12,62 @@ Polkadot's smart contract platform provides developers with a unique dual virtua
6
12
7
13
The dual-stack architecture consists of:
8
14
9
-
-**REVM Backend**: Provides full Ethereum Virtual Machine compatibility, enabling unchanged Solidity contracts and familiar tooling
10
-
-**PolkaVM (PVM) Backend**: A RISC-V-based virtual machine optimized for performance and enabling new use cases
15
+
-**[REVM Backend](#revm-backend){target=\_blank}**: Provides full Ethereum Virtual Machine compatibility, enabling unchanged Solidity contracts and familiar tooling
16
+
-**[PolkaVM Backend](#polkavm-backend){target=\_blank}**: A RISC-V-based virtual machine optimized for performance and enabling new use cases
11
17
12
18
Both backends share common infrastructure including RPC interfaces, tooling support, and precompiles, ensuring consistent developer experience while offering distinct performance characteristics.
The REVM backend integrates a complete Ethereum Virtual Machine implementation, enabling Solidity contracts to run unchanged on Polkadot's smart contract platform.
The [REVM backend](https://github.com/bluealloy/revm){target=\_blank} integrates a complete Ethereum Virtual Machine implementation, enabling Solidity contracts to run unchanged on Polkadot's smart contract platform.
59
31
60
-
### Use Cases
32
+
This allows developers to use their existing Ethereum tooling and infrastructure to build on Polkadot.
61
33
62
34
The REVM backend is ideal for:
63
35
64
-
-**Quick migration**: Projects porting existing Ethereum dApps without code modifications
PolkaVM represents a next-generation virtual machine built on RISC-V architecture, optimized for high-performance smart contract execution while maintaining Solidity compatibility through the Revive compiler.
80
-
81
-
### Core Architecture Differences
82
-
83
-
PolkaVM introduces fundamental architectural improvements over the EVM:
84
-
85
-
```mermaid
86
-
flowchart TB
87
-
subgraph "EVM Architecture"
88
-
EVMStack[Stack-Based Operations]
89
-
EVM256[256-bit Word Size]
90
-
EVMGas[Single Gas Metric]
91
-
end
92
-
93
-
subgraph "PolkaVM Architecture"
94
-
PVMReg[Register-Based Operations]
95
-
PVM64[64-bit Word Size]
96
-
PVMWeight[Multi-Dimensional Resources]
97
-
end
98
-
99
-
EVMStack -.->|vs| PVMReg
100
-
EVM256 -.->|vs| PVM64
101
-
EVMGas -.->|vs| PVMWeight
102
-
```
103
-
104
-
#### Register-Based Design
105
-
106
-
PolkaVM's RISC-V register-based approach provides several advantages:
107
-
108
-
-**Hardware alignment**: Efficient translation to modern CPU architectures through simple 1:1 mapping to x86-64
109
-
-**Optimized execution**: Reduced compilation complexity via strategic register limitation
110
-
-**Performance gains**: Direct register allocation eliminates stack manipulation overhead
111
-
112
-
#### 64-bit Word Size
113
-
114
-
Operating with native 64-bit words enables:
115
-
116
-
-**Hardware-supported operations**: Direct arithmetic without emulation overhead
117
-
-**Compatibility preservation**: Maintains Solidity's 256-bit operations through YUL translation
118
-
-**Mixed-language support**: Integration of performance-critical components in lower-level languages
119
-
-**Reduced overhead**: Eliminates unnecessary precision costs for standard operations
120
-
121
-
#### Multi-Dimensional Resource Metering
122
-
123
-
Unlike EVM's single gas metric, PolkaVM meters three distinct resources:
|**`ref_time`**| Computational time (closest to gas) | Similar to EVM gas |
128
-
|**`proof_size`**| State proof size for validator verification | No EVM equivalent |
129
-
|**`storage_deposit`**| State bloat management through deposits | Partially similar to gas |
130
-
131
-
All resources can be limited at the transaction level, and the Ethereum RPC proxy maps all three dimensions into the single gas dimension for seamless user experience.
132
-
133
-
### Compilation Process
134
-
135
-
PolkaVM contracts go through a sophisticated compilation pipeline:
[PolkaVM](https://github.com/paritytech/polkavm){target=\_blank} represents a next-generation virtual machine built on [RISC-V](https://en.wikipedia.org/wiki/RISC-V){target=\_blank} architecture, optimized for high-performance smart contract execution while maintaining Solidity compatibility through the Revive compiler.
168
44
169
-
#### Advanced Memory Management
45
+
###Core PVM concepts
170
46
171
-
PolkaVM implements fixed memory limits per contract:
-**Dynamic pricing**: Gas values are benchmark-based, not fixed
232
-
-**Cross-contract calls**: Resource limits forwarded automatically, not manually specified
233
-
-**Reentrancy protection**: Cannot rely on gas stipends; must implement explicit guards
47
+
-**Architecture**: Register-based RISC-V VM with native 64-bit words. Solidity is supported via Revive/LLVM, offering lower overhead than the EVM's stack-based, 256-bit design.
48
+
-**Resources (pricing)**: Dimensions like `ref_time` (compute), `proof_size` (state proof), `storage_deposit` (state bloat) are mapped to a single gas number at the RPC layer.
49
+
-**Execution**: Interpreter at the time of writing; JIT planned for heavy workloads. Lazy interpretation avoids upfront compilation cost.
50
+
-**Deployment**: Two-step flow. First upload code, and then instantiate by code hash. On-chain constructors replace runtime code generation (no dynamic codegen).
51
+
-**Limits**: Fixed caps (stack depth, event topics/data, storage value size, transient/immutable vars, code size) for predictable nesting and capacity planning.
52
+
-**Tooling/bytecode**: Ethereum JSON-RPC and common tooling work. PVM bytecode is RISC-V (EVM bytecode inspectors won't parse); limited `EXTCODECOPY`.
53
+
-**Calls and safety**: Cross-contract calls forward resource limits automatically. Use explicit reentrancy guards; do not rely on gas stipends. Pricing is benchmark-based, making compute cheaper relative to I/O.
234
54
235
55
## Choosing the Right Backend
236
56
237
57
The dual-stack architecture allows developers to select the optimal backend based on their specific requirements:
238
58
239
-
### Choose REVM When:
240
-
241
-
- Migrating existing Ethereum contracts without modifications
242
-
- Requiring exact EVM behavior for audited code
243
-
- Using tools that inspect EVM bytecode
244
-
- Prioritizing rapid deployment over optimization
245
-
- Working with established Ethereum infrastructure
- Performance benchmarking against reference implementations
310
-
311
-
### PolkaVM Roadmap
312
-
313
-
- JIT compiler implementation for advanced optimization
314
-
- Dynamic memory metering for deeper contract nesting
315
-
- Additional language support beyond Solidity
316
-
- Extended precompile ecosystem
317
-
318
-
### Shared Infrastructure
319
-
320
-
- Anvil-compatible local test nodes
321
-
- Comprehensive test suites from major Ethereum applications
322
-
- Differential testing against reference implementations
323
-
- Stress testing and benchmarking tools
59
+
- Choose REVM when:
324
60
325
-
## Getting Started
61
+
- Migrating existing Ethereum contracts without modifications
62
+
- Requiring exact EVM behavior for audited code
63
+
- Using tools that inspect EVM bytecode
64
+
- Prioritizing rapid deployment over optimization
65
+
- Working with established Ethereum infrastructure
326
66
327
-
Developers can begin building on either backend:
67
+
- Choose PolkaVM when:
328
68
329
-
1.**Development environment**: Set up Hardhat or Foundry with Polkadot smart contract platform
330
-
2.**Backend selection**: Choose REVM for compatibility or PVM for performance
331
-
3.**Local testing**: Use Anvil-compatible test nodes for both backends
332
-
4.**Deployment**: Deploy to testnet (Kusama) before mainnet (Polkadot)
69
+
- Building performance-critical applications
70
+
- Requiring intensive computation
71
+
- Optimizing for lower execution costs
333
72
334
73
The dual-stack architecture ensures developers have the flexibility to optimize for their specific use case while maintaining access to Polkadot's advanced capabilities through shared infrastructure and precompiles.
0 commit comments