Skip to content

PolkaVM

Introduction

PolkaVM is a general-purpose, user-level virtual machine based on the RISC-V instruction set. pallet-revive embeds PolkaVM as its PVM execution backend, next to the EVM backend that runs standard Solidity bytecode.

This page explains how PolkaVM programs are built, how pallet-revive recognizes and executes them, and which toolchains produce them. For the behavioral differences that Solidity developers see on PVM, such as memory limits, gas, and contract creation, see EVM vs PVM. For the full smart contract stack, see the Smart Contracts Overview.

What PolkaVM Is

PolkaVM executes programs compiled for a RISC-V target instead of a stack machine such as the EVM. Its design goals include the following:

  • Sandboxed execution that keeps guest code away from the host system.
  • Fully deterministic execution, so the same code and inputs always produce the same output.
  • Fast, single-pass compilation, so loading new code is near-instantaneous.
  • Small program binaries and a low memory footprint per instance.
  • Cheap, deterministic gas metering.

Note

The PolkaVM README lists these as design goals and states that not all of them are met yet. Refer to the PolkaVM repository for the project's status.

From Source Code to a Program Blob

A compiler does not emit PolkaVM code directly. Instead, a PVM toolchain produces a RISC-V ELF file for the riscv64emac-unknown-none-polkavm target and then links it into a PolkaVM program blob with polkavm-linker. The linker rewrites the ELF into PolkaVM's own compact format, which is the artifact you deploy, conventionally stored in a .polkavm file.

Every program blob starts with the four magic bytes PVM\0, followed by a version byte and the blob length. PolkaVM programs expose named entry points, called exports, that the host can call, and they reach the outside world only through host functions that the embedding environment provides.

The polkatool command-line tool from the PolkaVM repository works with program blobs. Its subcommands include link (ELF to .polkavm), disassemble, assemble, stats, and get-target-json-path.

How pallet-revive Executes Contracts

pallet-revive decides which backend runs a contract by inspecting the code you upload:

  • PVM: Code that starts with the PolkaVM magic bytes is treated as a program blob and executed by PolkaVM.
  • EVM: Any other code is treated as EVM bytecode and executed by the EVM backend, but only if the runtime sets the AllowEVMBytecode configuration item of pallet-revive to true. Otherwise, the upload is rejected.

Both kinds of contracts share the same account model, storage, Ethereum JSON-RPC interface, and precompiles, and they can call each other.

The Contract Interface

A PVM contract is a program blob with two exports:

  • deploy: The constructor, called once when the contract is instantiated.
  • call: The entry point for every later call to the contract.

Neither export takes arguments or returns a value. A contract reads its input with host functions such as call_data_size and call_data_copy, and ends execution with return_value, which carries the output data and a flag that marks a revert. Other host functions give access to storage, events, balances, block information, and calls to other contracts. The pallet-revive-uapi crate defines this interface for contract code; its HostFn trait documents every host function. pallet-revive passes call data to the contract unchanged, so a PVM contract that decodes its input and encodes its output with the Solidity ABI can be called by Ethereum tools like any other contract.

Deployment

pallet-revive stores PVM code separately from the contracts that use it. You can upload code on its own with the upload_code dispatchable and instantiate contracts from its code hash later, or upload and instantiate in one step. Only PVM code can be instantiated from a code hash; EVM contracts are always deployed from their init code. See Contract Deployment for how this affects factory contracts.

When you deploy a PVM contract with an Ethereum transaction (a transaction without a to address), the transaction data is the program blob followed by the constructor input. pallet-revive reads the blob length from the blob header, splits the data at that point, uploads the code, and passes the rest to the deploy export.

Toolchains That Produce PVM Bytecode

You can produce PVM contracts from Solidity or from Rust:

  • Solidity with resolc: The resolc compiler compiles Solidity, through the Yul IR that solc emits and a custom LLVM build, to PolkaVM program blobs. Use it when you have Solidity contracts that should run on PVM.
  • Rust with cargo-pvm-contract: cargo-pvm-contract is a Cargo subcommand that scaffolds Rust contract projects and builds them into .polkavm files. The generated contracts are no_std Rust programs that call host functions through pallet-revive-uapi and mark their exports with polkavm-derive. This is a low-level way to write contracts, well suited to small, performance-sensitive code that Solidity contracts call. See Write Rust Contracts.
  • ink!: ink! is a third-party Rust smart contract language whose version 6 targets pallet-revive; its repository states that it has not been actively maintained since January 2026.

The contract fixtures that pallet-revive uses for its tests are written in Rust against pallet-revive-uapi and show how to use most host functions.

Where to Go Next

  • Guide Write Rust Contracts


    Scaffold, build, and deploy a Rust contract for pallet-revive with cargo-pvm-contract.

    Get Started

  • Guide The resolc Compiler


    Compile Solidity contracts to PolkaVM bytecode.

    Get Started

  • Learn EVM vs PVM


    Review the behavioral differences between contracts on PVM and contracts on the EVM.

    Reference

Last update: November 17, 2026
| Created: November 17, 2026