Native EVM Contracts on Polkadot

#EVM #Smart Contract

Table of Contents

This is a presentation about PolkaVM that I made to present to one of local web3 communities. Since it’s currently in development, things might have changed and what you’re going to read might not be valid anymore. Feel free to consult the official docs.

Overview

  • Execute EVM contracts natively on Substrate-based chains
  • Uses pallet-revive in Substrate runtime
  • Supports Ethereum-like transactions and state transitions
  • Benefits: Lower gas fees, faster transactions, interoperability with Substrate

What is PolkaVM?

PolkaVM is a cutting-edge virtual machine tailored to optimize smart contract execution on Polkadot.

Unlike traditional Ethereum Virtual Machines (EVM), PolkaVM is built with a RISC-V-based register architecture and a 64-bit word size.


Why RISC-V?

  • Open Standard: allows for greater customization and innovation in VM design.
  • Versatile: easy to transpile into common hardware formats such as x86, x64, and ARM.
  • Simplicity and efficiency: simple and clean ISA leads to more efficient and easier optimization of smart contracts.
  • 100x efficiency gains for ZK-EVM, see Vitalik proposal here.

PolkaVM vs EVM (Part 1)

FeaturePolkaVMEVM
ArchitectureRISC-V-based registerStack-based
Word Size64-bit256-bit
OptimizationTailored for smart contract execution on PolkadotGeneral-purpose for Ethereum
Arithmetic OperationsFaster due to register architectureSlower due to stack operations
ArchitectureRISC-V-based registerStack-based
Word Size64-bit256-bit

PolkaVM vs EVM (Part 2)

FeaturePolkaVMEVM
Hardware TranslationMore efficientLess efficient
Language IntegrationSeamless with C and RustPrimarily Solidity
ScalabilityImproved for modern blockchain applicationsLimited by design
EcosystemNewer, growingWell-established

PolkaVM vs EVM (Part 3)

FeaturePolkaVMEVM
Gas EfficiencyPotentially more efficient with precise meteringLess efficient for complex operations
Memory ManagementMore flexible with 64-bit addressingLimited by 256-bit word size

PolkaVM - Key Benefits

  • Faster arithmetic operations and efficient hardware translation
  • Seamless integration of high-performance languages like C and Rust for advanced optimization
  • Improved scalability for modern blockchain applications

Key Components

  • pallet_revive: Runtime module executing smart contracts, converting Ethereum transactions for blockchain compatibility

  • PolkaVM: Custom RISC-V-based VM optimized for performance, supporting Solidity and high-performance languages

  • Revive: Compiler translating Solidity to RISC-V for PolkaVM, ensuring full Solidity compatibility

  • Revive Remix: Modified Remix IDE with LLVM-based Revive backend for efficient Solidity contract deployment on Polkadot


Key Considerations

  • Gas Pricing: Custom or Ethereum model
  • Account Management: Handle both Substrate and Ethereum accounts
  • Storage: Manage EVM state in Substrate storage
  • Performance: Balance EVM execution and chain performance

Development Tools

  • Remix: Web-based Solidity IDE
  • Hardhat: Development environment for Ethereum
  • Truffle: Testing framework for Ethereum
  • Web3.js: JavaScript library for Ethereum interaction
  • Ethers.js: Alternative JavaScript library for Ethereum

DOOM Demo!

https://youtu.be/hJcw5FMSjQs?si=WSOk0prFh6hVo9oH


Key Takeaway

You can run normal software compiled from normal programming languages (Rust, C, C++, etc) using normal abstractions on Polkadot soon.


References