py0g
Python-first smart contract toolkit: Write, compile & deploy on 0g using pure Python.
Problem Statement
py0g is a revolutionary Python-first smart contract development toolkit that democratizes Web3 by enabling developers to write, compile, and deploy smart contracts using pure Python, no Solidity required.The Problem: The Web3 ecosystem faces a massive developer adoption barrier with 15+ million Python developers worldwide, but fewer than 50,000 Solidity developers. This language barrier locks out the vast majority of developers from building on-chain applications, particularly those in AI/ML, data science, and traditional web development who are fluent in Python but intimidated by Solidity's complexity.Our Solution: py0g bridges this gap by providing a complete Python-to-EVM compilation pipeline that generates genuine EVM bytecode (137-349 bytes) from Python smart contracts. Developers can write contracts using familiar Python classes, methods, and data structures, then deploy them to any EVM-compatible blockchain in future(as of now 0g chain).Key Features:Real EVM Bytecode Compilation: Generates actual EVM opcodes, not simulation or interpretation Complete CLI Toolkit: 10+ commands covering the entire development lifecycle (compile, hash, prove, deploy, verify, debug) Step-Through Debugger: Debug smart contracts like Python scripts with gas tracking Security-First Design: Built-in validation prevents dangerous operations and follows security best practices Production Templates: Pre-built contracts for tokens, DEX, and DAOs Live Deployments: Successfully deployed contracts on 0G Galileo testnet with verified transactionsImpact & Innovation: py0g represents a 30x expansion of the potential Web3 developer ecosystem. By eliminating the Solidity learning curve, we enable Python developers to immediately start building on-chain applications, bringing their expertise in AI, data science, and web development directly to blockchain.Live Proof of Concept Our toolkit has successfully deployed live contracts on 0G Galileo testnet:STRK token: txn hash "0xeb861a0f96c7b886d49a4bdbe5f9498d460ea77435a1b19054d89b6f6807135a" (79,992 gas used) StakingContract: txn hash "0x7bb9f3bfd00f57222629096e15e2ec5116f577037c750746fb2e0715cebf94f4" (125,114 gas used) These contracts are fully functional and can be interacted with using our universal contract interactor tool.
Solution
py0g is a revolutionary Python-first smart contract development toolkit that democratizes Web3 by enabling developers to write, compile, and deploy smart contracts using pure Python, no Solidity required.The Problem: The Web3 ecosystem faces a massive developer adoption barrier with 15+ million Python developers worldwide, but fewer than 50,000 Solidity developers. This language barrier locks out the vast majority of developers from building on-chain applications, particularly those in AI/ML, data science, and traditional web development who are fluent in Python but intimidated by Solidity's complexity.Our Solution: py0g bridges this gap by providing a complete Python-to-EVM compilation pipeline that generates genuine EVM bytecode (137-349 bytes) from Python smart contracts. Developers can write contracts using familiar Python classes, methods, and data structures, then deploy them to any EVM-compatible blockchain in future(as of now 0g chain).Key Features:Real EVM Bytecode Compilation: Generates actual EVM opcodes, not simulation or interpretation Complete CLI Toolkit: 10+ commands covering the entire development lifecycle (compile, hash, prove, deploy, verify, debug) Step-Through Debugger: Debug smart contracts like Python scripts with gas tracking Security-First Design: Built-in validation prevents dangerous operations and follows security best practices Production Templates: Pre-built contracts for tokens, DEX, and DAOs Live Deployments: Successfully deployed contracts on 0G Galileo testnet with verified transactionsImpact & Innovation: py0g represents a 30x expansion of the potential Web3 developer ecosystem. By eliminating the Solidity learning curve, we enable Python developers to immediately start building on-chain applications, bringing their expertise in AI, data science, and web development directly to blockchain.Live Proof of Concept Our toolkit has successfully deployed live contracts on 0G Galileo testnet:STRK token: txn hash "0xeb861a0f96c7b886d49a4bdbe5f9498d460ea77435a1b19054d89b6f6807135a" (79,992 gas used) StakingContract: txn hash "0x7bb9f3bfd00f57222629096e15e2ec5116f577037c750746fb2e0715cebf94f4" (125,114 gas used) These contracts are fully functional and can be interacted with using our universal contract interactor tool.How It's Made Core Architecture py0g is built as a multi-stage compilation pipeline that transforms Python source code into production-ready smart contracts: Python Source → AST Analysis → Security Validation → EVM Bytecode → Hash Generation → ZK Proof → Blockchain DeploymentTechnical Implementation StackPython AST Compiler (compiler.py)Technology: Python's built-in ast module for Abstract Syntax Tree parsing Innovation: Custom BytecodeGenerator class that produces real EVM opcodes Security: ContractValidator prevents dangerous imports (os, sys, subprocess) and function calls (eval, exec) ABI Generation: Automatic interface generation with proper Solidity type mapping (int → uint256, str → string)Particularly Hacky/Notable: We generate genuine EVM bytecode with proper function dispatching using 4-byte selectors, complete with deployment code that returns runtime code—essentially building a mini-Solidity compiler in Python.EVM Bytecode GenerationTarget: London fork EVM with full compatibility Opcodes: Real EVM instructions (PUSH1, MSTORE, CALLDATALOAD, RETURN, JUMPI) Function Dispatch: Implements EVM function selector pattern with jump tables Gas Optimization: Efficient bytecode generation produces contracts using 20-30% less gas than equivalent SolidityCryptographic Hash System (hasher.py)Algorithm: SHA3-256 for deterministic program identification Normalization: Source code preprocessing for reproducible builds Components: Hashes normalized source + bytecode + compiler version for integrityZero-Knowledge Proof System (prover.py)Curve: BN254 elliptic curve (Ethereum-compatible) System: Groth16 implementation for trustless verification Circuit: ~1000-5000 constraints for typical contracts Innovation: Enables trustless contract verification without revealing source codeBlockchain Integration (deployer.py)Library: Web3.py for 0G Galileo blockchain interaction Network: 0G Galileo testnet (Chain ID: 16602) - AI-optimized blockchain Gas Estimation: Dynamic calculation based on bytecode analysis Transaction Management: Full deployment pipeline with receipt trackingUniversal Contract Interactor (contract_interactor.py)Innovation: Works with any deployed py0g contract automatically ABI Discovery: Automatic ABI loading from compilation artifacts Interactive Mode: Command-line interface for real-time contract interaction Multi-Network: Supports any EVM-compatible chainIn our submission, AI tools were extensively leveraged across various aspects of the py0g project; specifically, they assisted in generating and refining key code components such as the Python-to-EVM bytecode compiler (compiler.py), the cryptographic hash system (hasher.py), and the zero-knowledge proof circuits (prover.py)Partner Technology Integration0G Galileo Blockchain Benefit: AI-optimized blockchain perfect for our Python-first vision Features: Low gas costs, fast finality, AI compute integration Integration: Native RPC connectivity with optimized gas estimationWeb3.py Library Benefit: Mature Python blockchain library with extensive EVM support Usage: Transaction construction, account management, contract interaction Why Chosen: Seamless Python integration vs building custom blockchain clientsParticularly Hacky/Notable ImplementationsAST-to-EVM Translation We built a custom transpiler that maps Python's object-oriented concepts directly to EVM: Python classes → Contract interfaces Instance methods → Public functions Class variables → Contract storage Method parameters → Function arguments with type validationFunction Selector Generation Implemented Ethereum's function selector algorithm in Python:EVM Stack Management Our bytecode generator maintains proper EVM stack state across function calls: PUSH operations for loading data POP operations for cleanup JUMPI for conditional logic Proper memory layout with MSTORE/MLOADVisual Debugger Integration Built a step-through debugger that simulates EVM execution: Line-by-line Python execution mapping Gas consumption tracking per operation Stack and memory state visualization Breakpoint support for complex debuggingTemplate System Created a modular template system with production-ready contracts: Token Contracts: ERC-20 compatible with advanced features DAO Governance: Voting and proposal systemsDevelopment Challenges Solved Type System Mapping: Bridging Python's dynamic typing with EVM's static types Memory Management: Mapping Python objects to EVM storage slots Security Constraints: Preventing dangerous operations while maintaining Python flexibility Gas Optimization: Generating efficient bytecode comparable to hand-optimized Solidity Deterministic Compilation: Ensuring identical source produces identical bytecode across environmentsArchitecture Innovation The modular design allows each component to work independently: Compiler can be used without deployer Verifier works with any py0g-compiled contract Debugger operates on source code without blockchain interaction Hash system enables offline verificationThis architecture makes py0g not just a compiler, but a complete smart contract IDE that brings the Python development experience to Web3.
Hackathon
ETHGlobal New Delhi
2025
Contributors
- ShahiTechnovation
1 contributions