Polkadot Virtual Machine (PVM) implementation with interpreter and recompiler as specified in GP
Project description
Tessera PVM
Tessera PVM is a Python implementation of the Tessera virtual machine, offering two execution modes: a straightforward interpreter and a more performant recompiler.
Project Structure
tsrkit_pvm/: The main package.core/: Abstract base classes and core PVM components.common/: Shared utilities and data structures.interpreter/: The interpreter-based PVM implementation.recompiler/: The recompiler-based PVM implementation.
tests/: The project's test suite, which includes PVM test cases and schemas.
Core Components
The fundamental building blocks of the PVM are defined in tsrkit_pvm/core/:
ipvm.py: Contains thePVMabstract base class.program_base.py: Defines the base class for PVM programs.memory.py: Provides the base class for memory management.
Implementations
- Interpreter: Located in
tsrkit_pvm/interpreter/, this implementation executes bytecode instruction by instruction. It is easier to debug and inspect. - Recompiler: Found in
tsrkit_pvm/recompiler/, this implementation recompiles PVM bytecode into native machine code for significantly faster execution.
Installation
Install the package using pip:
pip install .
Usage
The primary way to run a PVM program is to use the static execute method on either the Interpreter or Recompiler class.
Here is a corrected example of how to execute a PVM program with the interpreter:
from tsrkit_pvm.interpreter.pvm import Interpreter
from tsrkit_pvm.interpreter.program import Program
from tsrkit_pvm.interpreter.memory import INT_Memory
from tsrkit_pvm.common.status import ExecutionStatus
# Your PVM bytecode
bytecode = bytes([0, 0, 14, 40, 2, 200, 50, 1, 40, 2, 200, 67, 2, 51, 1, 40, 246, 165, 20])
# 1. Decode the bytecode into a Program object
# The `decode` method returns a single Program instance.
program = Program.decode(bytecode)
# 2. Initialize memory, registers, and gas
# INT_Memory takes a dictionary for initial memory, a list for input, and a list for output.
memory = INT_Memory({}, [], [])
registers = [0] * 13 # PVM has 13 registers
gas = 100_000
# 3. Execute the program
status, final_pc, remaining_gas, final_registers, final_memory = Interpreter.execute(
program=program,
program_counter=0,
gas=gas,
registers=registers,
memory=memory
)
# 4. Check the result
if status == ExecutionStatus.OUT_OF_GAS:
print("Execution finished: Out of gas.")
print(f"Gas consumed: {gas - remaining_gas}")
else:
print(f"Execution finished with status: {status}")
Testing
To run the comprehensive test suite and verify the functionality of both the interpreter and recompiler, use pytest:
poetry run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tsrkit_pvm-0.2.1.tar.gz.
File metadata
- Download URL: tsrkit_pvm-0.2.1.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f32acb702b3e18619aa234f8f427671260f867798da2f01cec1cd2c9f795880
|
|
| MD5 |
9ee9b312238b1ffe5c655a441897fff8
|
|
| BLAKE2b-256 |
3a3625c5d3730a122b493cf58420e7f92c1d169babcfdd8d2011b27b43c5e220
|
File details
Details for the file tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c1d73e335e65d19e7d1799e6a758ac857149a0385f893818999cf04814aefd3
|
|
| MD5 |
322612039f7729851c57de3a3bdf3ddc
|
|
| BLAKE2b-256 |
ad19eca4b4307c609329fbd428909c66ee19ad312cd87496ee7c4612a8d3d095
|
File details
Details for the file tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 6.1 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cd337fd2ee26709fc266aab825c1dc8bac89d56bbde653bb4817e9c2977fb16
|
|
| MD5 |
d1b3dacd24d99f2c4d6ad896ca9f42a3
|
|
| BLAKE2b-256 |
6a6e30175bab3edfe217ad1f5453b24dbeac53b39e45dfb125c2f9a1450c813d
|
File details
Details for the file tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5baff8304fe04a689d440538a29d514b61cc3b31095eea4649d74e82c28888ee
|
|
| MD5 |
013c25813dfb641765d3ff01254694e4
|
|
| BLAKE2b-256 |
5c966e82b033edb8c313f26835e9f0786312819cd0401d1a6777123759b1cc38
|
File details
Details for the file tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f215ee0ad790c997f4a4e42364866d7e92e0901746639b2573211295f40f707c
|
|
| MD5 |
fce080541d006ec72ddcbc1e040c4a6d
|
|
| BLAKE2b-256 |
9cdfd62e0ccf537956b1ffc5d916a084d8ea672ed079ec648c1ebbf769aa8ba9
|
File details
Details for the file tsrkit_pvm-0.2.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: tsrkit_pvm-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64b86e4df1d9bbe245036f1abfef6f2ee22be05ff79e3a07a5f0d1fc20e639dd
|
|
| MD5 |
b51b16222ca1bb0b6387f6d31115b0fd
|
|
| BLAKE2b-256 |
b9eee8a7b812d325dbe354988091bde8201ebd751490bace38847454a5d0d797
|
File details
Details for the file tsrkit_pvm-0.2.1-cp312-cp312-macosx_10_13_x86_64.whl.
File metadata
- Download URL: tsrkit_pvm-0.2.1-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.12, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6388de7f5d0bb1f42a308d5e8d108ffccb0c5dc6110d07f4f58a798356937976
|
|
| MD5 |
2501bbf74a01fc935281e36d2668c530
|
|
| BLAKE2b-256 |
ffc162fb61454eb4ff2e60866409a51694b7ed2434270f5511e6445a6a94b7ab
|