PyBitrum

Smart Contracts For Agents

Visit Repo
PyBitrum banner

About

## The problem it solves

PyBitrum solves the critical challenge of **making smart contract development accessible to Python developers** while ensuring production-grade security and autonomy. Here's what it enables:

### **1. Democratizing Smart Contract Development** - **Write Once, Deploy Everywhere**: Developers can write smart contracts in Python (a language 10M+ developers know) and simultaneously compile to both **Solidity and Vyper**, eliminating the steep learning curve of specialized smart contract languages. - **Lower Barrier to Entry**: Python's readability and familiar syntax reduce cognitive overhead compared to learning Solidity from scratch.

### **2. Autonomous Agent Deployment**

- **24/7 Agent Execution**: PyBitrum enables developers to deploy `AgentWallet` entities - autonomous agents with their own EOAs (Externally Owned Accounts), private keys, and on-chain identities that execute missions without human intervention. - **Mission Board Economy**: Post bounties in ETH, let agents claim, execute, and settle transactions autonomously - creating a decentralized task execution marketplace. - **Swarm Orchestration**: Coordinate fleets of agents using concurrent Python threads with shared state broadcasting, enabling complex multi-agent scenarios like market making, arbitrage, and liquidation bots.

### **3. Industrial-Grade Safety & Security** - **Compile-Time Security Guardrails**: 14 dangerous patterns (exec, eval, os, subprocess, sockets, etc.) are blocked at the security check stage - before any code transformation. - **Dual-Language Validation**: Code is validated for both Vyper and Solidity compatibility, ensuring maximum deployment flexibility and catching language-specific bugs early. - **Automatic Reentrancy Protection**: The `@agent_action` decorator auto-injects `@nonreentrant` and `msg.sender` verification, preventing common attack vectors without manual intervention.

### **4. Cloud-Native Development Experience** - **Browser-Based IDE**: The Playground provides a Monaco Editor with syntax highlighting, real-time compilation feedback, GitHub OAuth, and one-click MetaMask deployment. - **Instant Feedback Loop**: Developers see compilation errors/warnings and generated Solidity/Vyper code in real-time, accelerating iteration. - **Full-Stack Tooling**: Includes a Mission Board UI for agent interaction, comprehensive documentation hub, and a pip-installable SDK for local development.

### **5. Reduces Smart Contract Bugs & Costs** - **AST-Based Transformation**: Uses Abstract Syntax Trees to intelligently map Python constructs to EVM semantics, handling edge cases like memory layout and type conversions automatically. - **Consistent Code Generation**: The dual-compiler pipeline ensures generated contracts are idiomatic in both Solidity and Vyper, reducing the risk of subtle compiler-specific bugs. - **Lower Deployment Costs**: Vyper code often generates smaller bytecode than Solidity, reducing gas costs for on-chain deployments.

## Challenges we ran into

**Challenge 1: Dual-Compiler AST Parity** **Problem**: Python's AST has fundamentally different semantics than Solidity/Vyper. For example, Python's dynamic typing, runtime method resolution, and duck typing don't map cleanly to EVM's static types and fixed memory layout.

**Specific Issues**:

- Python `dict` → Vyper `HashMap` requires knowing the key/value types upfront (which Python doesn't enforce). - Python `list` → Vyper `DynArray` with a compile-time size limit (Vyper limits arrays to 256 elements by default). - Python's `self` context needed to be inferred as either `@internal` or `@external` visibility in Vyper/Solidity.

**How I Solved It**:

- **Type Inference Engine**: Built a multi-pass type analyzer that infers types from variable assignments, function return statements, and decorator hints. - **Decorator Annotations**: Introduced `@contract`, `@action`, `@read` decorators that let developers explicitly annotate visibility and mutability where inference fails. - **AST Transformation Layers**: Created separate `PythonToVyperTransformer` (36KB) and `PythonToSolidityTransformer` (24KB) classes, each handling language-specific quirks (e.g., Vyper's strict `String` sizing vs Solidity's dynamic `string`).

---

### **Challenge 2: Security Without False Positives** **Problem**: Blocking dangerous patterns like `exec()` and `eval()` is straightforward, but legitimate Python patterns get caught. For example: - A function named `execute()` shouldn't be blocked. - A variable containing `"os"` as a string shouldn't trigger an "os import" warning. - Developers were frustrated with overly strict validation.

**Specific Issues**:

- Regex patterns for `os.*` and `sys.*` produced false positives on identifiers like `custom_os_path` or `system_config`. - The first version blocked all `import` statements, making it impossible to use `from pybitrum import Contract`.

**How I Solved It**:

- **AST-Based Pattern Matching**: Replaced string regex with proper Python AST analysis. Now only `import os` and `import sys` are blocked, not arbitrary string matches. - **Whitelisted Imports**: Allowed safe imports like `from pybitrum import Contract`, `from typing import Dict`, etc. - **Multi-Pass Validation**: Split validation into a `SecurityChecker` (14 hard-coded patterns) and `CodeValidator` (AST walks), allowing different severity levels. - **Detailed Error Messages**: When validation fails, the compiler now returns specific line numbers and context (e.g., "exec() at line 42 is not allowed"), not just "bad code."

---

### **Challenge 3: TypeScript ↔ Python Serialization** **Problem**: The frontend (TypeScript/Next.js) sends Python code to the Flask compiler service and receives back Vyper/Solidity code + AST JSON. Serializing complex Python objects across HTTP required careful schema design.

**Specific Issues**:

- Python's `ast.AST` nodes aren't JSON-serializable by default. - Type mismatches between TypeScript interfaces and Python dictionaries caused runtime errors on the frontend. - Large ASTs (100+ KB for complex contracts) bloated JSON payloads, causing slow compilation responses.

**How I Solved It**:

- **Custom JSON Encoder**: Built a `PyBitrumJSONEncoder` that converts `ast.AST` nodes, code objects, and other non-serializable types to dictionaries. - **Zod Schemas**: On the backend (Express), used Zod to validate all compiler responses against strict TypeScript interfaces before returning to the frontend. - **AST Pruning**: Limited the AST response to only essential fields (function names, arguments, return types) rather than the full parse tree, reducing payload size by ~70%. - **HTTP Compression**: Enabled gzip compression on the Flask compiler service to further reduce response times.

---

### **Challenge 4: Vyper vs Solidity Bytecode Divergence** **Problem**: The same Python contract compiled to both Vyper and Solidity could produce different EVM bytecode and gas costs. For example: - Vyper's `HashMap` generates different storage layout than Solidity's `mapping`. - Vyper's built-in overflow checks add runtime gas overhead that Solidity 0.8.x includes at the language level. - Compiler optimizations differ-solcx defaults to different optimization runs than vyper.

**Specific Issues**:

- Agents couldn't trust both compiled versions; they'd pick one and ignore the other. - The Hive Registry contract expected a specific ABI, but Vyper and Solidity generated slightly different ABIs for the same logic. - Gas estimates were inconsistent, making it hard to price agent missions on the Mission Board.

**How I Solved It**:

- **Dual-ABI Registration**: Modified the Hive Registry to accept both Vyper and Solidity ABIs, storing them alongside the contract address. - **Deterministic Compilation**: Locked compiler versions (solcx 0.8.20, vyper 0.4.3) and fixed optimization settings to ensure reproducible bytecode.

Screenshots

PyBitrum screenshot 1PyBitrum screenshot 2PyBitrum screenshot 3PyBitrum screenshot 4PyBitrum screenshot 5

Team

From the public Devfolio project page. Votes, swipes and the judge score are hackfeed's own.

AI judge

Not judged yet. A free model reads this page, compares it with similar projects and this event's winners, then scores it and says what would make it win.

Still being built?

Not checked yet.

Swipe stats

0upvotes
0skips
0saves

Discussion 0

No comments yet. Ask the team something, or say what you'd use it for.

Posting as a guest. Plain text, 1,000 characters max.

Already built nearby

Closest projects by meaning and shared words. Similar isn't the same as copied: read them.

ContractAI

Contract AI: Write, compile, deploy, and interact with smart contracts seamlessly. With AI-powered, chain-specific agents and an integrated interaction tool, it's your one-stop platform for Solidity development. No setup needed — just bring your ideas to life!