PyVax — Python to EVM transpiler for Avalanche smart contracts
Project description
PyVax — Python-to-EVM Transpiler & Ecosystem
PyVax is a powerful compiler toolchain and web ecosystem that allows developers to write EVM (Ethereum Virtual Machine) smart contracts in pure, unadulterated Python. It consists of a production-grade Python-to-EVM transpiler (avax_cli), a deployment framework, and an immersive Web3 landing page/documentation platform (app/).
🏗️ Whole-Project Codebase Analysis
The PyVax project is split into two primary domains: the Core Transpiler CLI and the Next.js Web Platform.
1. avax_cli/ (Core Transpiler & CLI Toolchain)
This directory houses the actual compiler, deployment scripts, and command-line interfaces.
transpiler.py: The heart of PyVax. Evaluates Python ASTs (Abstract Syntax Trees) and maps Python expressions/statements to raw EVM bytecodes. It features a completeEVMBytecodeGenerator, aPeepholeOptimizer, memory allocators, and ABI generators.cli.py: ATyper-powered CLI with commands for scaffolding (new), compilation (compile), deployment (deploy), and interaction (call/info).deployer.py/interactor.py: Handles on-chain execution leveragingweb3.py. Integrates EIP-1559 gas pricing dynamically to adapt to network congestion (primarily targeting Avalanche C-Chain/Fuji).wallet.py: Manages secure, encrypted keystore files for autonomous agent wallets.compiler.py: Iterates through.pycontract files, invokes the transpiler, and outputs compiled artifact JSONs.
2. app/ & content/ (Web Platform)
The Next.js 14 web platform that powers the PyVax landing page and interactive documentation.
app/: Next.js App Router containing the landing page, immersive 3D WebGL experiences (using Three.js/React Three Fiber), and MDX-powered documentation pages.components/: Features a rich UI system utilizing Tailwind CSS, Framer Motion for scroll-driven animations, andScrollImageSequencefor narrative scrollytelling.content/: Uses Fumadocs (or equivalent MDX parsing) to manage structured documentation, tutorials, and API references.
⚡ Transpiler Features (v0.3.0)
The PyVax transpiler has been aggressively optimized in v0.3.0 to match the gas efficiency and security profiles of Solidity 0.8.27 and Huff.
1. Advanced Gas Optimizations (-15% overall gas reduction)
- Binary Search Dispatch: Automatically upgrades from linear
O(n)toO(log n)selector tree dispatch for contracts with >4 functions. Saves up to 62% gas per function call compared to the linear fallback. - SLOAD Caching: Emulates Solidity's CSE (Common Subexpression Elimination) pass #17. Pre-scans ASTs to find state variables read multiple times in a function and caches them in memory (
MLOAD). Reduces redundant reads from 2,100 gas to 3 gas (99.9% savings). - Peephole Optimizer: Multi-pass bytecode reducer. Implements constant folding (
PUSH5 + PUSH3 + ADD→PUSH8) and identity elimination (ISZERO / ISZEROdouble-negations →∅). - Shared Revert Deduplication: Eliminates bytecode bloat by deduplicating identical
require()error string encodings into single shared blocks at the bytecode footer (saves ~75 bytes per duplicate message).
2. Solidity-Grade Security
- Overflow-Safe Arithmetic: Implicitly protects
ADD,SUB, andMULoperations. Validates results on the stack and reverts safely to prevent integer underflow/overflow attacks (Solidity 0.8+ behavior). - Compile-Time Stack Validation: Tracks EVM stack depth dynamically during compilation across 50+ opcodes. Fails the build immediately if the EVM 1024 stack limit is breached, preventing silent runtime failures.
- Isolated Memory Scopes: Dynamically allocates scratch memory (
0x80+) per-function to prevent data collision betweenemit(),require(), and local variables.
3. Comprehensive EVM Feature Parity
msg_sender(),msg_value(),block_number(),block_timestamp()all natively mapped to opcodes.- Full support for Python
while,for x in range(), andif/elif/elsecomplex control flows. - Native event emissions via
LOG1-LOG4. - Complex state storage: Support for dictionaries mapping to EVM
keccak256slot resolutions.
🚀 Installation & CLI Usage
Prerequisites
- Python 3.9+
- Node.js 18+ (for Web dependencies)
CLI Commands (pyvax)
- Scaffold a new project:
pyvax new my-protocol cd my-protocol
- Create a Wallet:
pyvax wallet new deployer
- Compile Python Contracts:
pyvax compile # Outputs optimized ABI and bytecode to /build
- Deploy to Avalanche/EVM:
pyvax deploy AgentVault --network fuji
- Call Contract via CLI:
pyvax call 0xYourDeployedAddress get_total --view
📝 Writing a PyVax Contract
A PyVax contract is standard, valid Python. It is evaluated via the ast module—no Python interpreter is ever deployed on-chain!
from pyvax import Contract, action
class Vault(Contract):
# State Variables (Slot 0, Slot 1)
balances: dict = {}
total_deposits: int = 0
@action
def deposit(self, amount: int):
# Implicitly overflow-safe arithmetic (reverts on overflow)
self.require(amount > 0, "Amount must be positive")
sender = self.msg_sender()
self.balances[sender] = self.balances[sender] + amount
self.total_deposits = self.total_deposits + amount
self.emit("Deposit", sender, amount)
@action
def get_balance(self, user: str) -> int:
return self.balances[user]
(Note: When transpiled using v0.3.0, self.balances[sender] caching and binary function routing are automatically injected into the generated bytecode!)
📊 Benchmark results: PyVax vs Solc vs Huff
| Metric | PyVax v0.3 | Solidity 0.8.27 | Huff 0.3 |
|---|---|---|---|
| Dispatch (16 funcs) | 88 gas | 88 gas | 72 gas |
| SLOAD (3x read) | 106 gas | 100 gas | 100 gas |
| Revert Size (2x msg) | 86 bytes | 72 bytes | N/A |
| Optimization Approach | AST Passes + Peephole | Yul IR + CSE | Direct Macros |
👨💻 Web App Development
To run the PyVax full-stack landing page and web platform locally:
npm install
npm run dev
# The website will be available at localhost:3000
Built with ❤️ for the Avalanche & Python Ecosystems.
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 Distribution
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 pyvax_cli-1.0.0.tar.gz.
File metadata
- Download URL: pyvax_cli-1.0.0.tar.gz
- Upload date:
- Size: 171.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
941655995bd94ad81820580f3fb599239fdd159907181c9b0bf52bafc6c0fcf6
|
|
| MD5 |
9f7dabb4ec069694cb54400cc810389e
|
|
| BLAKE2b-256 |
2bf6098dedf18e96ce774e5aeefe42ee606441bb6459a5eaf27bcd427c52781e
|
Provenance
The following attestation bundles were made for pyvax_cli-1.0.0.tar.gz:
Publisher:
publish.yml on ShahiTechnovation/pyvax-rebrand
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyvax_cli-1.0.0.tar.gz -
Subject digest:
941655995bd94ad81820580f3fb599239fdd159907181c9b0bf52bafc6c0fcf6 - Sigstore transparency entry: 1060231760
- Sigstore integration time:
-
Permalink:
ShahiTechnovation/pyvax-rebrand@385d95645ad2c04ef07201716970b4a5e7d7dc37 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ShahiTechnovation
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@385d95645ad2c04ef07201716970b4a5e7d7dc37 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyvax_cli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyvax_cli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 187.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cdd2924b0380454315d2bf5eee63aa337f057e3ba39bd2b7f27ffef6c706b80
|
|
| MD5 |
2b28faa687a716f435bfea48d9c05e2d
|
|
| BLAKE2b-256 |
0aa9195553661399954e6f848f92a95b5a8ebfc4595eb35e47bd46d9e5bb8b51
|
Provenance
The following attestation bundles were made for pyvax_cli-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on ShahiTechnovation/pyvax-rebrand
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyvax_cli-1.0.0-py3-none-any.whl -
Subject digest:
4cdd2924b0380454315d2bf5eee63aa337f057e3ba39bd2b7f27ffef6c706b80 - Sigstore transparency entry: 1060231764
- Sigstore integration time:
-
Permalink:
ShahiTechnovation/pyvax-rebrand@385d95645ad2c04ef07201716970b4a5e7d7dc37 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ShahiTechnovation
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@385d95645ad2c04ef07201716970b4a5e7d7dc37 -
Trigger Event:
release
-
Statement type: