Skip to main content

Python bindings for fast EVM tracing using REVM

Project description

pyrevm-trace

Python bindings for fast EVM simulation and tracing, built on REVM via PyO3.

Simulate transactions locally, capture call trees, and profile gas usage — no node required.

Features

  • Transaction simulation — execute calls against in-memory EVM state
  • Call tracing — full recursive call tree with inputs, outputs, and success flags
  • Gas profiling — opcode-level gas breakdown
  • Async supportAsyncSimulator offloads to a thread so it won't block your event loop
  • Typed API — Pydantic v2 models for all results

Installation

Requires Python 3.10+ and Rust (for building from source).

uv add pyrevm-trace
# or
pip install pyrevm-trace

To build from source:

git clone https://github.com/salva-imm/pyrevm-trace
cd pyrevm-trace
uv run maturin develop --release

Quick Start

from pyrevm_trace import Simulator

sim = Simulator(chain_id=1)

# Set up state
sim.set_balance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", 10**18)
sim.set_code("0x1234567890123456789012345678901234567890", bytes.fromhex("600160005260206000f3"))

# Simulate a call
result = sim.simulate(
    caller="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
    to="0x1234567890123456789012345678901234567890",
    calldata=b"",
    gas_limit=100_000,
)

print(result.success)    # True
print(result.gas_used)   # e.g. 21318
print(result.return_data.hex())  # 0000...0001

API

Simulator

Synchronous wrapper around EVMSimulator.

from pyrevm_trace import Simulator

sim = Simulator(chain_id=1)
sim.set_balance(address: str, balance: int) -> None
sim.set_code(address: str, bytecode: bytes) -> None
sim.set_storage(address: str, slot: int, value: int) -> None

result: SimulationResult = sim.simulate(
    caller: str,
    to: str,
    calldata: bytes = b"",
    value: int = 0,
    gas_limit: int = 30_000_000,
    with_trace: bool = False,
    with_gas_profile: bool = False,
)

AsyncSimulator

Drop-in async version — simulation runs in a thread via asyncio.to_thread.

import asyncio
from pyrevm_trace import AsyncSimulator

async def main():
    sim = AsyncSimulator(chain_id=1)
    sim.set_code("0x1234...", bytecode)
    result = await sim.simulate(caller="0xabcd...", to="0x1234...", gas_limit=100_000)
    print(result.success)

asyncio.run(main())

Call Tracing

result = sim.simulate(..., with_trace=True)

if result.calls:
    print(result.calls.from_)      # caller address
    print(result.calls.to)         # target address
    print(result.calls.success)    # bool
    for sub in result.calls.calls: # nested calls
        ...

Gas Profiling

result = sim.simulate(..., with_gas_profile=True)

for step in result.gas_steps:
    print(f"pc={step.pc} op=0x{step.op:02x} cost={step.gas_cost}")

with_trace takes priority over with_gas_profile if both are set.

Models

class SimulationResult(BaseModel):
    success: bool
    gas_used: int
    return_data: bytes
    logs: list[Log]
    calls: CallFrame | None          # present when with_trace=True
    gas_steps: list[GasStep] | None  # present when with_gas_profile=True

class Log(BaseModel):
    address: str
    topics: list[str]
    data: bytes

class CallFrame(BaseModel):
    from_: str      # "from" in raw dict
    to: str
    calldata: bytes
    value: str      # decimal string (U256)
    gas_limit: int
    success: bool
    output: bytes
    calls: list[CallFrame]

class GasStep(BaseModel):
    pc: int
    op: int
    gas_remaining: int
    gas_cost: int

Development

# Build Rust extension
uv run maturin develop

# Run tests
uv run pytest

# Run Rust unit tests
cargo test

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrevm_trace-0.1.0.tar.gz (52.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyrevm_trace-0.1.0-cp312-cp312-win_amd64.whl (695.4 kB view details)

Uploaded CPython 3.12Windows x86-64

pyrevm_trace-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (796.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pyrevm_trace-0.1.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

pyrevm_trace-0.1.0-cp311-cp311-win_amd64.whl (694.5 kB view details)

Uploaded CPython 3.11Windows x86-64

pyrevm_trace-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (796.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

pyrevm_trace-0.1.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.5 MB view details)

Uploaded CPython 3.11macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

pyrevm_trace-0.1.0-cp310-cp310-win_amd64.whl (694.6 kB view details)

Uploaded CPython 3.10Windows x86-64

pyrevm_trace-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (796.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

pyrevm_trace-0.1.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.5 MB view details)

Uploaded CPython 3.10macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file pyrevm_trace-0.1.0.tar.gz.

File metadata

  • Download URL: pyrevm_trace-0.1.0.tar.gz
  • Upload date:
  • Size: 52.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyrevm_trace-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2e92f464c55812df2deb8cae7b0a3e87490ce6a9f2bd16558085554222a65dae
MD5 06ba49f260fddfc87d1792e7628dc0e0
BLAKE2b-256 3f8e84c8d19d3af4c52952def79572139157dcbb2592e2258b671728dbf5edbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0.tar.gz:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f292b9a2d3c4a074d71e2dfd2053f5e0a67ecd782c6a28f0ed2fca1989c74051
MD5 5690e3670de4a8a6e0432fbc146f923f
BLAKE2b-256 6bd71b1f8e4dc8e8553d5234af52689471b3ebe6542ea1b0877c84b9a52ab8ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cf8fdd89653296e24d401aa64f4bcbbd54176c54235cb58dfd769ad040dbebe8
MD5 bedffb76ec8c2d239d1aae24ce212d2c
BLAKE2b-256 a08cde9c6b42b244bf934a69574200c5c9fc7281facb03e6e5351b0adae21ff2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 4da71b3db66babbef005dcc8ca8a52c2f5bb4a46ca706b2d094efa52516bbd22
MD5 02e5b7166ad5b42828bfa8698f6f1983
BLAKE2b-256 3b3ce8046600aa7f409a20702ab3f6f2697dddf3cabb77c911da565879ba214d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5fe3ebced28d0aa9ee5ab725d1abd7b0d55ea3616908ca3c34e6f289590a6448
MD5 9fe2d395cd68a6b0cddce62146a6ece8
BLAKE2b-256 880672e5e04fc4ec1f63c0ef14e957bcc9d356370e44346d6f2b1e96d3f75e9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b87afa3eb6ef63460c1527981181653a41d6fabbd3dd2e8ac26cc3b252ceb9f6
MD5 1fe06927697008ec1716bdd74ea5943b
BLAKE2b-256 6a3ee57443b5406b3f1b8b39dd95a553f6698550e44d8ea17d2a85b887ccea12

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b4f68beaf1676ba5d46e3a01b643885404fedc26717fda29178871dcea497906
MD5 0e8a38b53bfeccef7ff1a0dfdd7dc4b2
BLAKE2b-256 c3de06c1ccc645757fa694694859213fcf4bff3fd908e789bce35b71cb1685b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e40ad49e75edf240cc70ffcf147a92e7a0b79d1663e9f3af07b0c1a350bdab35
MD5 cabd8598b28b8cbd78749145d63ac364
BLAKE2b-256 ff5ed02f6b49ba1fec81e21db761dd3da5e8ca65565e8f569f1c429371230296

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp310-cp310-win_amd64.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eab1acb79a179a9e71f257c7eae94e03c0799eb7baed91ab0d275fe4e8b5dadd
MD5 33fd2ee3a7bd6d1e3aba5b81968a0773
BLAKE2b-256 949972813b91e1de8b1bfae2a871514c32cd6e80d7a79ef6662414e1c4cfb130

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrevm_trace-0.1.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pyrevm_trace-0.1.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 68af4e14c8bb7df253ef721c6a43f382c008af4baeab831c1a52a9500228d06f
MD5 63d004224658b9533ef9b346f19cb8ac
BLAKE2b-256 efa449bf4c9dffda8fde9f869ec86b2095e1fca9f3ce17f4df2e02f99e9e1db6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrevm_trace-0.1.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: publish.yml on salva-imm/pyrevm-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page