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
* Add Contract Deployment Guide for Polkadot Hub
* fix: llms
* Enhance contract deployment documentation for Polkadot by detailing the two virtual machine backends, REVM and PolkaVM, along with their deployment characteristics and optimization strategies.
* fix: llms
* Apply suggestions from code review
Co-authored-by: Bruno Galvao <[email protected]>
* Update contract deployment documentation to include a link to the Revive compiler for enhanced clarity on the deployment process.
* fix: llms
* docs: add note on gas estimation discrepancies in contract deployment
* fix: llms
* Grammarly & such, fresh llms
---------
Co-authored-by: Bruno Galvao <[email protected]>
Co-authored-by: DAWN KELLY <[email protected]>
- Summary: Compare deployment flows for REVM and PVM-based smart contracts on the Polkadot Hub. Includes single-step REVM flows and PVM’s two-step deployment model.
2503
+
2504
+
# Contract Deployment
2505
+
2506
+
## Introduction
2507
+
2508
+
Polkadot's smart contract platform supports two distinct virtual machine backends: Rust Ethereum Virtual Machine (REVM) and PolkaVM. Each backend has its own deployment characteristics and optimization strategies. REVM provides full Ethereum compatibility with familiar single-step deployment, while the RISC-V-based PolkaVM uses a more structured two-step approach optimized for its architecture. Understanding these differences ensures smooth deployment regardless of which backend you choose for your smart contracts.
2509
+
2510
+
## REVM Deployment
2511
+
2512
+
The REVM backend enables seamless deployment of Ethereum contracts without modification. Contracts deploy exactly as they would on Ethereum, using familiar tools and workflows.
2513
+
2514
+
With REVM, deployment mirrors the Ethereum flow exactly including:
2515
+
2516
+
- Contracts are bundled and deployed in a single transaction.
2517
+
- Factory contracts can create new contracts at runtime.
2518
+
- Runtime code generation, including inline assembly, is supported.
2519
+
- Existing familiar tools like Hardhat, Foundry, and Remix work out of the box.
2520
+
2521
+
## PolkaVM Deployment
2522
+
2523
+
PolkaVM implements a fundamentally different deployment model optimized for its RISC-V architecture. While simple contract deployments work seamlessly, advanced patterns like factory contracts require understanding the two-step deployment process.
2524
+
2525
+
### Standard Contract Deployment
2526
+
2527
+
For most use cases, such as deploying ERC-20 tokens, NFT collections, or standalone contracts, deployment is transparent and requires no special steps. The [Revive compiler](https://github.com/paritytech/revive){target=\_blank} handles the deployment process automatically when using standard Solidity patterns.
2528
+
2529
+
### Two-Step Deployment Model
2530
+
2531
+
PolkaVM separates contract deployment into distinct phases:
2532
+
2533
+
1. **Code upload**: Contract bytecode must be uploaded to the chain before instantiation.
2534
+
2. **Contract instantiation**: Contracts are created by referencing previously uploaded code via its hash.
2535
+
2536
+
This architecture differs from the EVM's bundled approach and has important implications for specific deployment patterns.
2537
+
2538
+
### Factory Pattern Considerations
2539
+
2540
+
The common EVM pattern, where contracts dynamically create other contracts, requires adaptation for PolkaVM as follows:
2541
+
2542
+
**EVM Factory Pattern:**
2543
+
```solidity
2544
+
// This works on REVM but requires modification for PolkaVM
2545
+
contract Factory {
2546
+
function createToken() public returns (address) {
2547
+
// EVM bundles bytecode in the factory
2548
+
return address(new Token());
2549
+
}
2550
+
}
2551
+
```
2552
+
2553
+
**PolkaVM Requirements:**
2554
+
2555
+
- **Pre-upload dependent contracts**: All contracts that will be instantiated at runtime must be uploaded to the chain before the factory attempts to create them.
2556
+
- **Code hash references**: Factory contracts work with pre-uploaded code hashes rather than embedding bytecode.
2557
+
- **No runtime code generation**: Dynamic bytecode generation is not supported due to PolkaVM's RISC-V format.
2558
+
2559
+
### Migration Strategy for Factory Contracts
2560
+
2561
+
When migrating factory contracts from Ethereum to PolkaVM:
2562
+
2563
+
1. **Identify all contracts**: Determine which contracts will be instantiated at runtime.
2564
+
2. **Upload dependencies first**: Deploy all dependent contracts to the chain before deploying the factory.
4. **Avoid assembly creation**: Don't use `create` or `create2` opcodes in assembly blocks for manual deployment.
2567
+
2568
+
### Architecture-Specific Limitations
2569
+
2570
+
PolkaVM's deployment model creates several specific constraints:
2571
+
2572
+
- **`EXTCODECOPY` limitations**: Contracts using `EXTCODECOPY` to manipulate code at runtime will encounter issues.
2573
+
- **Runtime code modification**: Patterns that construct and mutate contract code on-the-fly are not supported.
2574
+
- **Assembly-based factories**: Factory contracts written in YUL assembly that generate code at runtime will fail with `CodeNotFound` errors.
2575
+
2576
+
These patterns are rare in practice and typically require dropping down to assembly, making them non-issues for standard Solidity development.
2577
+
2578
+
### On-Chain Constructors
2579
+
2580
+
PolkaVM provides on-chain constructors as an elegant alternative to runtime code modification:
2581
+
2582
+
- Enable contract instantiation without runtime code generation.
2583
+
- Support flexible initialization patterns.
2584
+
- Maintain separation between code upload and contract creation.
2585
+
- Provide predictable deployment costs.
2586
+
2587
+
## Gas Estimation vs Actual Consumption
2588
+
2589
+
Both REVM and PolkaVM deployments may show significant differences between gas estimation and actual consumption. You might see estimates that are several times higher than the actual gas consumed (often around 30% of the estimate). This is normal behavior because pre-dispatch estimation cannot distinguish between computation weight and storage deposits, leading to conservative overestimation. Contract deployments are particularly affected as they consume significant storage deposits for code storage.
| **Runtime Codegen** | Fully supported | Not supported |
2599
+
| **Simple Contracts** | No modifications needed | No modifications needed |
2600
+
| **Assembly Creation** | Supported | Discouraged, limited support |
2601
+
2602
+
## Conclusion
2603
+
2604
+
Both backends support contract deployment effectively, with REVM offering drop-in Ethereum compatibility and PolkaVM providing a more structured two-step approach. For the majority of use cases—deploying standard contracts like tokens or applications—both backends work seamlessly. Advanced patterns like factory contracts may require adjustment for PolkaVM, but these adaptations are straightforward with proper planning.
- Summary: Compare deployment flows for REVM and PVM-based smart contracts on the Polkadot Hub. Includes single-step REVM flows and PVM’s two-step deployment model.
2504
+
2505
+
# Contract Deployment
2506
+
2507
+
## Introduction
2508
+
2509
+
Polkadot's smart contract platform supports two distinct virtual machine backends: Rust Ethereum Virtual Machine (REVM) and PolkaVM. Each backend has its own deployment characteristics and optimization strategies. REVM provides full Ethereum compatibility with familiar single-step deployment, while the RISC-V-based PolkaVM uses a more structured two-step approach optimized for its architecture. Understanding these differences ensures smooth deployment regardless of which backend you choose for your smart contracts.
2510
+
2511
+
## REVM Deployment
2512
+
2513
+
The REVM backend enables seamless deployment of Ethereum contracts without modification. Contracts deploy exactly as they would on Ethereum, using familiar tools and workflows.
2514
+
2515
+
With REVM, deployment mirrors the Ethereum flow exactly including:
2516
+
2517
+
- Contracts are bundled and deployed in a single transaction.
2518
+
- Factory contracts can create new contracts at runtime.
2519
+
- Runtime code generation, including inline assembly, is supported.
2520
+
- Existing familiar tools like Hardhat, Foundry, and Remix work out of the box.
2521
+
2522
+
## PolkaVM Deployment
2523
+
2524
+
PolkaVM implements a fundamentally different deployment model optimized for its RISC-V architecture. While simple contract deployments work seamlessly, advanced patterns like factory contracts require understanding the two-step deployment process.
2525
+
2526
+
### Standard Contract Deployment
2527
+
2528
+
For most use cases, such as deploying ERC-20 tokens, NFT collections, or standalone contracts, deployment is transparent and requires no special steps. The [Revive compiler](https://github.com/paritytech/revive){target=\_blank} handles the deployment process automatically when using standard Solidity patterns.
2529
+
2530
+
### Two-Step Deployment Model
2531
+
2532
+
PolkaVM separates contract deployment into distinct phases:
2533
+
2534
+
1. **Code upload**: Contract bytecode must be uploaded to the chain before instantiation.
2535
+
2. **Contract instantiation**: Contracts are created by referencing previously uploaded code via its hash.
2536
+
2537
+
This architecture differs from the EVM's bundled approach and has important implications for specific deployment patterns.
2538
+
2539
+
### Factory Pattern Considerations
2540
+
2541
+
The common EVM pattern, where contracts dynamically create other contracts, requires adaptation for PolkaVM as follows:
2542
+
2543
+
**EVM Factory Pattern:**
2544
+
```solidity
2545
+
// This works on REVM but requires modification for PolkaVM
2546
+
contract Factory {
2547
+
function createToken() public returns (address) {
2548
+
// EVM bundles bytecode in the factory
2549
+
return address(new Token());
2550
+
}
2551
+
}
2552
+
```
2553
+
2554
+
**PolkaVM Requirements:**
2555
+
2556
+
- **Pre-upload dependent contracts**: All contracts that will be instantiated at runtime must be uploaded to the chain before the factory attempts to create them.
2557
+
- **Code hash references**: Factory contracts work with pre-uploaded code hashes rather than embedding bytecode.
2558
+
- **No runtime code generation**: Dynamic bytecode generation is not supported due to PolkaVM's RISC-V format.
2559
+
2560
+
### Migration Strategy for Factory Contracts
2561
+
2562
+
When migrating factory contracts from Ethereum to PolkaVM:
2563
+
2564
+
1. **Identify all contracts**: Determine which contracts will be instantiated at runtime.
2565
+
2. **Upload dependencies first**: Deploy all dependent contracts to the chain before deploying the factory.
4. **Avoid assembly creation**: Don't use `create` or `create2` opcodes in assembly blocks for manual deployment.
2568
+
2569
+
### Architecture-Specific Limitations
2570
+
2571
+
PolkaVM's deployment model creates several specific constraints:
2572
+
2573
+
- **`EXTCODECOPY` limitations**: Contracts using `EXTCODECOPY` to manipulate code at runtime will encounter issues.
2574
+
- **Runtime code modification**: Patterns that construct and mutate contract code on-the-fly are not supported.
2575
+
- **Assembly-based factories**: Factory contracts written in YUL assembly that generate code at runtime will fail with `CodeNotFound` errors.
2576
+
2577
+
These patterns are rare in practice and typically require dropping down to assembly, making them non-issues for standard Solidity development.
2578
+
2579
+
### On-Chain Constructors
2580
+
2581
+
PolkaVM provides on-chain constructors as an elegant alternative to runtime code modification:
2582
+
2583
+
- Enable contract instantiation without runtime code generation.
2584
+
- Support flexible initialization patterns.
2585
+
- Maintain separation between code upload and contract creation.
2586
+
- Provide predictable deployment costs.
2587
+
2588
+
## Gas Estimation vs Actual Consumption
2589
+
2590
+
Both REVM and PolkaVM deployments may show significant differences between gas estimation and actual consumption. You might see estimates that are several times higher than the actual gas consumed (often around 30% of the estimate). This is normal behavior because pre-dispatch estimation cannot distinguish between computation weight and storage deposits, leading to conservative overestimation. Contract deployments are particularly affected as they consume significant storage deposits for code storage.
| **Runtime Codegen** | Fully supported | Not supported |
2600
+
| **Simple Contracts** | No modifications needed | No modifications needed |
2601
+
| **Assembly Creation** | Supported | Discouraged, limited support |
2602
+
2603
+
## Conclusion
2604
+
2605
+
Both backends support contract deployment effectively, with REVM offering drop-in Ethereum compatibility and PolkaVM providing a more structured two-step approach. For the majority of use cases—deploying standard contracts like tokens or applications—both backends work seamlessly. Advanced patterns like factory contracts may require adjustment for PolkaVM, but these adaptations are straightforward with proper planning.
- Summary: Compare deployment flows for REVM and PVM-based smart contracts on the Polkadot Hub. Includes single-step REVM flows and PVM’s two-step deployment model.
2504
+
2505
+
# Contract Deployment
2506
+
2507
+
## Introduction
2508
+
2509
+
Polkadot's smart contract platform supports two distinct virtual machine backends: Rust Ethereum Virtual Machine (REVM) and PolkaVM. Each backend has its own deployment characteristics and optimization strategies. REVM provides full Ethereum compatibility with familiar single-step deployment, while the RISC-V-based PolkaVM uses a more structured two-step approach optimized for its architecture. Understanding these differences ensures smooth deployment regardless of which backend you choose for your smart contracts.
2510
+
2511
+
## REVM Deployment
2512
+
2513
+
The REVM backend enables seamless deployment of Ethereum contracts without modification. Contracts deploy exactly as they would on Ethereum, using familiar tools and workflows.
2514
+
2515
+
With REVM, deployment mirrors the Ethereum flow exactly including:
2516
+
2517
+
- Contracts are bundled and deployed in a single transaction.
2518
+
- Factory contracts can create new contracts at runtime.
2519
+
- Runtime code generation, including inline assembly, is supported.
2520
+
- Existing familiar tools like Hardhat, Foundry, and Remix work out of the box.
2521
+
2522
+
## PolkaVM Deployment
2523
+
2524
+
PolkaVM implements a fundamentally different deployment model optimized for its RISC-V architecture. While simple contract deployments work seamlessly, advanced patterns like factory contracts require understanding the two-step deployment process.
2525
+
2526
+
### Standard Contract Deployment
2527
+
2528
+
For most use cases, such as deploying ERC-20 tokens, NFT collections, or standalone contracts, deployment is transparent and requires no special steps. The [Revive compiler](https://github.com/paritytech/revive){target=\_blank} handles the deployment process automatically when using standard Solidity patterns.
2529
+
2530
+
### Two-Step Deployment Model
2531
+
2532
+
PolkaVM separates contract deployment into distinct phases:
2533
+
2534
+
1. **Code upload**: Contract bytecode must be uploaded to the chain before instantiation.
2535
+
2. **Contract instantiation**: Contracts are created by referencing previously uploaded code via its hash.
2536
+
2537
+
This architecture differs from the EVM's bundled approach and has important implications for specific deployment patterns.
2538
+
2539
+
### Factory Pattern Considerations
2540
+
2541
+
The common EVM pattern, where contracts dynamically create other contracts, requires adaptation for PolkaVM as follows:
2542
+
2543
+
**EVM Factory Pattern:**
2544
+
```solidity
2545
+
// This works on REVM but requires modification for PolkaVM
2546
+
contract Factory {
2547
+
function createToken() public returns (address) {
2548
+
// EVM bundles bytecode in the factory
2549
+
return address(new Token());
2550
+
}
2551
+
}
2552
+
```
2553
+
2554
+
**PolkaVM Requirements:**
2555
+
2556
+
- **Pre-upload dependent contracts**: All contracts that will be instantiated at runtime must be uploaded to the chain before the factory attempts to create them.
2557
+
- **Code hash references**: Factory contracts work with pre-uploaded code hashes rather than embedding bytecode.
2558
+
- **No runtime code generation**: Dynamic bytecode generation is not supported due to PolkaVM's RISC-V format.
2559
+
2560
+
### Migration Strategy for Factory Contracts
2561
+
2562
+
When migrating factory contracts from Ethereum to PolkaVM:
2563
+
2564
+
1. **Identify all contracts**: Determine which contracts will be instantiated at runtime.
2565
+
2. **Upload dependencies first**: Deploy all dependent contracts to the chain before deploying the factory.
4. **Avoid assembly creation**: Don't use `create` or `create2` opcodes in assembly blocks for manual deployment.
2568
+
2569
+
### Architecture-Specific Limitations
2570
+
2571
+
PolkaVM's deployment model creates several specific constraints:
2572
+
2573
+
- **`EXTCODECOPY` limitations**: Contracts using `EXTCODECOPY` to manipulate code at runtime will encounter issues.
2574
+
- **Runtime code modification**: Patterns that construct and mutate contract code on-the-fly are not supported.
2575
+
- **Assembly-based factories**: Factory contracts written in YUL assembly that generate code at runtime will fail with `CodeNotFound` errors.
2576
+
2577
+
These patterns are rare in practice and typically require dropping down to assembly, making them non-issues for standard Solidity development.
2578
+
2579
+
### On-Chain Constructors
2580
+
2581
+
PolkaVM provides on-chain constructors as an elegant alternative to runtime code modification:
2582
+
2583
+
- Enable contract instantiation without runtime code generation.
2584
+
- Support flexible initialization patterns.
2585
+
- Maintain separation between code upload and contract creation.
2586
+
- Provide predictable deployment costs.
2587
+
2588
+
## Gas Estimation vs Actual Consumption
2589
+
2590
+
Both REVM and PolkaVM deployments may show significant differences between gas estimation and actual consumption. You might see estimates that are several times higher than the actual gas consumed (often around 30% of the estimate). This is normal behavior because pre-dispatch estimation cannot distinguish between computation weight and storage deposits, leading to conservative overestimation. Contract deployments are particularly affected as they consume significant storage deposits for code storage.
| **Runtime Codegen** | Fully supported | Not supported |
2600
+
| **Simple Contracts** | No modifications needed | No modifications needed |
2601
+
| **Assembly Creation** | Supported | Discouraged, limited support |
2602
+
2603
+
## Conclusion
2604
+
2605
+
Both backends support contract deployment effectively, with REVM offering drop-in Ethereum compatibility and PolkaVM providing a more structured two-step approach. For the majority of use cases—deploying standard contracts like tokens or applications—both backends work seamlessly. Advanced patterns like factory contracts may require adjustment for PolkaVM, but these adaptations are straightforward with proper planning.
0 commit comments