Skip to content

Commit 18f24ac

Browse files
committed
Add overview of Polkadot's dual virtual machine architecture to smart contracts section. Introduced REVM and PolkaVM backends, detailing their features, use cases, and shared infrastructure for developers.
1 parent e83de25 commit 18f24ac

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Dual Virtual Machine Stack
3+
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+
7+
# Dual Virtual Machine Stack
8+
9+
## Introduction
10+
11+
Polkadot's smart contract platform provides developers with a unique dual virtual machine architecture, offering flexibility in choosing the right execution backend for their needs. This approach balances immediate Ethereum compatibility with long-term innovation, allowing developers to deploy either unmodified EVM contracts or optimize for higher performance using PVM.
12+
13+
The dual-stack architecture consists of:
14+
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
17+
18+
Both backends share common infrastructure including RPC interfaces, tooling support, and precompiles, ensuring consistent developer experience while offering distinct performance characteristics.
19+
20+
```mermaid
21+
graph TD
22+
Devs["Developers"] --> REVM["REVM (EVM-compatible)"]
23+
Devs --> PVM["PolkaVM (RISC-V)"]
24+
REVM --> Infra["Shared Infrastructure<br/>(Ethereum JSON-RPC, Tooling, Precompiles)"]
25+
PVM --> Infra
26+
```
27+
28+
## REVM Backend
29+
30+
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.
31+
32+
This allows developers to use their existing Ethereum tooling and infrastructure to build on Polkadot.
33+
34+
The REVM backend is ideal for:
35+
36+
- Quick migration: Projects porting existing Ethereum dApps without code modifications
37+
- Established tooling: Teams leveraging mature Ethereum development infrastructure
38+
- Third-party integrations: Applications requiring standard EVM bytecode inspection
39+
- Compatibility requirements: Contracts needing exact EVM behavior for audited code
40+
41+
## PolkaVM Backend
42+
43+
[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.
44+
45+
### Core PVM concepts
46+
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.
54+
55+
## Choosing the Right Backend
56+
57+
The dual-stack architecture allows developers to select the optimal backend based on their specific requirements:
58+
59+
- Choose REVM when:
60+
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
66+
67+
- Choose PolkaVM when:
68+
69+
- Building performance-critical applications
70+
- Requiring intensive computation
71+
- Optimizing for lower execution costs
72+
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

Comments
 (0)