pyrevm-trace 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyrevm_trace-0.1.0/.cargo/config.toml.example +15 -0
- pyrevm_trace-0.1.0/.github/workflows/ci.yml +45 -0
- pyrevm_trace-0.1.0/.github/workflows/publish.yml +83 -0
- pyrevm_trace-0.1.0/.gitignore +19 -0
- pyrevm_trace-0.1.0/.python-version +1 -0
- pyrevm_trace-0.1.0/CLAUDE.md +66 -0
- pyrevm_trace-0.1.0/Cargo.lock +3199 -0
- pyrevm_trace-0.1.0/Cargo.toml +19 -0
- pyrevm_trace-0.1.0/LICENSE +21 -0
- pyrevm_trace-0.1.0/PKG-INFO +194 -0
- pyrevm_trace-0.1.0/README.md +171 -0
- pyrevm_trace-0.1.0/docs/PLAN.md +1517 -0
- pyrevm_trace-0.1.0/pyproject.toml +40 -0
- pyrevm_trace-0.1.0/python/pyrevm_trace/__init__.py +6 -0
- pyrevm_trace-0.1.0/python/pyrevm_trace/async_simulator.py +39 -0
- pyrevm_trace-0.1.0/python/pyrevm_trace/models.py +41 -0
- pyrevm_trace-0.1.0/python/pyrevm_trace/simulator.py +38 -0
- pyrevm_trace-0.1.0/src/executor.rs +237 -0
- pyrevm_trace-0.1.0/src/gas_profiler.rs +39 -0
- pyrevm_trace-0.1.0/src/lib.rs +12 -0
- pyrevm_trace-0.1.0/src/tracer.rs +57 -0
- pyrevm_trace-0.1.0/src/types.rs +52 -0
- pyrevm_trace-0.1.0/tests/test_async_simulator.py +39 -0
- pyrevm_trace-0.1.0/tests/test_gas_profiler.py +40 -0
- pyrevm_trace-0.1.0/tests/test_models.py +64 -0
- pyrevm_trace-0.1.0/tests/test_simulation.py +78 -0
- pyrevm_trace-0.1.0/tests/test_simulator.py +52 -0
- pyrevm_trace-0.1.0/tests/test_tracer.py +82 -0
- pyrevm_trace-0.1.0/uv.lock +231 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copy this file to .cargo/config.toml and set PYO3_PYTHON to your Python interpreter.
|
|
2
|
+
# Required for `cargo test` to link against Python when using pyo3 extension-module feature.
|
|
3
|
+
#
|
|
4
|
+
# Find your Python path: which python3 (or: pyenv which python3)
|
|
5
|
+
|
|
6
|
+
[env]
|
|
7
|
+
PYO3_PYTHON = "/path/to/your/python3"
|
|
8
|
+
|
|
9
|
+
[target.aarch64-apple-darwin]
|
|
10
|
+
rustflags = [
|
|
11
|
+
"-L/path/to/your/python/lib",
|
|
12
|
+
"-lpython3.12",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
# For x86_64-apple-darwin or Linux, add a matching [target.*] section.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test (${{ matrix.os }}, Python ${{ matrix.python-version }})
|
|
12
|
+
runs-on: ${{ matrix.os }}
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: ${{ matrix.python-version }}
|
|
26
|
+
|
|
27
|
+
- name: Set up Rust
|
|
28
|
+
uses: dtolnay/rust-toolchain@stable
|
|
29
|
+
|
|
30
|
+
- name: Cache Rust
|
|
31
|
+
uses: Swatinem/rust-cache@v2
|
|
32
|
+
|
|
33
|
+
- name: Install uv
|
|
34
|
+
uses: astral-sh/setup-uv@v5
|
|
35
|
+
|
|
36
|
+
- name: Install dependencies
|
|
37
|
+
run: |
|
|
38
|
+
uv venv
|
|
39
|
+
uv pip install maturin pydantic pytest pytest-asyncio
|
|
40
|
+
|
|
41
|
+
- name: Build extension
|
|
42
|
+
run: uv run maturin develop --skip-install
|
|
43
|
+
|
|
44
|
+
- name: Run Python tests
|
|
45
|
+
run: uv run pytest tests/ -v
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
name: Build wheels (${{ matrix.target }})
|
|
11
|
+
runs-on: ${{ matrix.os }}
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
include:
|
|
15
|
+
- os: ubuntu-latest
|
|
16
|
+
target: x86_64
|
|
17
|
+
- os: ubuntu-latest
|
|
18
|
+
target: aarch64
|
|
19
|
+
- os: macos-latest
|
|
20
|
+
target: universal2-apple-darwin
|
|
21
|
+
- os: windows-latest
|
|
22
|
+
target: x86_64
|
|
23
|
+
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
|
|
27
|
+
- name: Set up Python
|
|
28
|
+
uses: actions/setup-python@v5
|
|
29
|
+
with:
|
|
30
|
+
python-version: "3.12"
|
|
31
|
+
|
|
32
|
+
- name: Build wheels
|
|
33
|
+
uses: PyO3/maturin-action@v1
|
|
34
|
+
with:
|
|
35
|
+
target: ${{ matrix.target }}
|
|
36
|
+
args: --release --out dist --interpreter 3.10 3.11 3.12
|
|
37
|
+
sccache: true
|
|
38
|
+
manylinux: auto
|
|
39
|
+
|
|
40
|
+
- name: Upload wheels
|
|
41
|
+
uses: actions/upload-artifact@v4
|
|
42
|
+
with:
|
|
43
|
+
name: wheels-${{ matrix.target }}
|
|
44
|
+
path: dist
|
|
45
|
+
|
|
46
|
+
build-sdist:
|
|
47
|
+
name: Build source distribution
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
|
+
|
|
52
|
+
- name: Build sdist
|
|
53
|
+
uses: PyO3/maturin-action@v1
|
|
54
|
+
with:
|
|
55
|
+
command: sdist
|
|
56
|
+
args: --out dist
|
|
57
|
+
|
|
58
|
+
- name: Upload sdist
|
|
59
|
+
uses: actions/upload-artifact@v4
|
|
60
|
+
with:
|
|
61
|
+
name: wheels-sdist
|
|
62
|
+
path: dist
|
|
63
|
+
|
|
64
|
+
publish:
|
|
65
|
+
name: Publish to PyPI
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
needs: [build, build-sdist]
|
|
68
|
+
environment:
|
|
69
|
+
name: pypi
|
|
70
|
+
url: https://pypi.org/p/pyrevm-trace
|
|
71
|
+
permissions:
|
|
72
|
+
id-token: write # trusted publishing — no token needed
|
|
73
|
+
|
|
74
|
+
steps:
|
|
75
|
+
- name: Download all wheels
|
|
76
|
+
uses: actions/download-artifact@v4
|
|
77
|
+
with:
|
|
78
|
+
pattern: wheels-*
|
|
79
|
+
merge-multiple: true
|
|
80
|
+
path: dist
|
|
81
|
+
|
|
82
|
+
- name: Publish to PyPI
|
|
83
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Python-generated files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[oc]
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
wheels/
|
|
7
|
+
*.egg-info
|
|
8
|
+
|
|
9
|
+
# Virtual environments
|
|
10
|
+
.venv
|
|
11
|
+
|
|
12
|
+
# Rust build artifacts
|
|
13
|
+
target/
|
|
14
|
+
|
|
15
|
+
# Compiled Python extensions
|
|
16
|
+
*.so
|
|
17
|
+
|
|
18
|
+
# Machine-specific Cargo config (PYO3_PYTHON path — copy from .cargo/config.toml.example)
|
|
19
|
+
.cargo/config.toml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12.3
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Behavior & Tool Guidelines
|
|
6
|
+
- use "rtk" before bash commands
|
|
7
|
+
- Always use the Bash tool for file operations (e.g., cat, ls, grep, find) instead of internal Read or Search tools. If you need to see a file, run cat or head via Bash.
|
|
8
|
+
|
|
9
|
+
## Build & Test Commands
|
|
10
|
+
|
|
11
|
+
This is a hybrid Rust/Python project. **Always use `uv run` for Python commands** — the project was created with `uv`.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Build the Rust extension (required after any change to src/)
|
|
15
|
+
# --skip-install avoids maturin's pip path, which doesn't support PEP 735 dependency-groups
|
|
16
|
+
uv run maturin develop --skip-install
|
|
17
|
+
|
|
18
|
+
# Run Python tests
|
|
19
|
+
uv run pytest
|
|
20
|
+
|
|
21
|
+
# Run a single test
|
|
22
|
+
uv run pytest tests/test_simulation.py::test_set_balance -v
|
|
23
|
+
|
|
24
|
+
# Run Rust unit tests (no Python involved)
|
|
25
|
+
cargo test
|
|
26
|
+
|
|
27
|
+
# Run Rust tests for a specific module
|
|
28
|
+
cargo test types
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Architecture
|
|
32
|
+
|
|
33
|
+
The project has two distinct layers that must be kept in sync.
|
|
34
|
+
|
|
35
|
+
### Rust layer (`src/`)
|
|
36
|
+
|
|
37
|
+
PyO3 extension compiled to `python/pyrevm_trace/_pyrevm_trace.cpython-*.so` by maturin.
|
|
38
|
+
|
|
39
|
+
- **`src/lib.rs`** — PyO3 module entry point. Registers all Python-visible classes. Only touch this to add new `#[pyclass]` types.
|
|
40
|
+
- **`src/executor.rs`** — `EVMSimulator` `#[pyclass]`. Owns the `CacheDB<EmptyDB>` (in-memory EVM state) and all `#[pymethods]`. This is where Python ↔ REVM conversion happens: extract Python types → call REVM → convert result to Python dicts.
|
|
41
|
+
- **`src/types.rs`** — Stateless conversion helpers (`parse_address`, `address_to_hex`, `py_int_to_u256`). All Rust modules that touch Python-provided addresses or amounts use these.
|
|
42
|
+
- **`src/tracer.rs`** — `CallTracer` implementing REVM's `Inspector` trait for recursive call tree capture.
|
|
43
|
+
- **`src/gas_profiler.rs`** — `GasProfiler` implementing `Inspector` for opcode-level gas steps.
|
|
44
|
+
|
|
45
|
+
Data flows one way: Python dict → Rust extraction → REVM execution → result as Python dict. No Pydantic or serde on the Rust side.
|
|
46
|
+
|
|
47
|
+
### Python layer (`python/pyrevm_trace/`)
|
|
48
|
+
|
|
49
|
+
Pure Python, depends on the compiled `.so`.
|
|
50
|
+
- `models.py` — Pydantic v2 models wrapping the raw dicts from Rust (`SimulationResult`, `CallFrame`, `GasStep`, `Log`)
|
|
51
|
+
- `simulator.py` — `Simulator` class: typed sync wrapper
|
|
52
|
+
- `async_simulator.py` — `AsyncSimulator`: offloads simulation to `asyncio.to_thread` for non-blocking async use
|
|
53
|
+
|
|
54
|
+
### Key invariants
|
|
55
|
+
|
|
56
|
+
- The Rust layer returns **raw Python dicts** from `simulate()`. The Python layer wraps them in Pydantic models. Never add serde/JSON serialization on the Rust side.
|
|
57
|
+
- Each `EVMSimulator` instance owns independent state — safe for concurrent use across threads/tasks when each caller has its own instance.
|
|
58
|
+
- `with_trace=True` runs a `CallTracer` inspector; `with_gas_profile=True` runs `GasProfiler`. Both flags together: only trace is active (combined inspector is future work).
|
|
59
|
+
|
|
60
|
+
## Development Setup
|
|
61
|
+
|
|
62
|
+
`.cargo/config.toml` is gitignored (machine-specific Python paths for `cargo test`). Copy `.cargo/config.toml.example` and set `PYO3_PYTHON` to your Python 3.12 interpreter path, or export it as an env var before running `cargo test`.
|
|
63
|
+
|
|
64
|
+
## Commit Style
|
|
65
|
+
|
|
66
|
+
Plain commit messages only — no `Co-Authored-By` trailers.
|