Python bindings for the Komozoi EVM simulator
Project description
Komozoi EVM — Python Bindings
komozoievm is a Python package that exposes the Komozoi EVM C++ engine for
simulating Ethereum transactions and contract execution against either a
user-supplied mock chain state or a real chain provider.
The package is built from the same C++ sources as the native library and is distributed as binary wheels on PyPI.
Installation
pip install komozoievm
Building from a source checkout requires a C++17 compiler and CMake:
pip install .
Quick start
import komozoievm as evm
src = "0x0000000000000000000000000000000000000001"
dst = "0x0000000000000000000000000000000000000002"
# An in-memory chain populated by Python code. Addresses must be valid
# 20-byte hex strings; malformed values raise ``ValueError``.
chain = evm.MockChain()
chain.set_balance(src, 10 * 10**18)
chain.set_code(dst, bytes.fromhex("6001600101"))
# Simulate a call without mutating state.
block = evm.BlockInfo(number=1, timestamp=1_700_000_000, base_fee=10)
result = chain.simulate(dst, src, b"", 0, block)
print(result.success, result.return_data.hex())
# ``execute`` performs the same call but commits the resulting state.
result = chain.execute(dst, src, value=1_000_000_000_000_000_000)
Module layout
komozoievm is a single top-level module. Names listed below are the public
Python surface; everything not listed should be treated as internal and is
subject to change.
Types
| Python type | Description |
|---|---|
Address |
20-byte Ethereum address. Accepts bytes, bytearray, hex str (with or without 0x), None, or another Address. str(address) returns the EIP-55 checksum form. |
U256 |
256-bit unsigned integer. Implicitly converts from Python int; values out of range raise OverflowError. |
Address and U256 are thin wrappers; functions that accept them also accept
the plain Python equivalents (bytes, str, int).
Data classes
BlockInfo(number, timestamp, base_fee=0, gas_limit=30_000_000, chain_id=1, coinbase=..., randao=0)— fields exposed for the block context.AccountInfo(address, balance=0, next_nonce=0)— minimal account state.AccessListEntry(address, storage_keys=()).SimulationResultwith attributes:success: bool,return_data: bytes,reason: str,gas_used: int.CallTrace— an aggregating tracer that records every contract call performed during a transaction. Pass an instance astrace=tosimulate/execute; the captured entries are available on thecallsattribute.CallTraceEntrywith attributes:src: Address,dst: Address,calldata: bytes,returndata: bytes,gas_used: int,success: bool.EventTracewith attributes:src: Address,topics: list[int],data: bytes.
Transaction construction
tx = evm.TransactionBuilder(
to=address,
nonce=int,
gas_limit=int,
value=0,
gas_price=0,
max_fee_per_gas=0,
max_priority_fee_per_gas=0,
data=b"",
access_list=[],
).build()
For common contract calls, you can use the Transaction.call helper:
tx = evm.Transaction.call(
from_=address,
to=address,
value=0,
data=b"",
gas_limit=100_000
)
For signed transactions, pass a 32-byte private key:
raw = tx.sign_and_encode(private_key=bytes.fromhex(...))
Chain providers
StateProvider is an abstract base class that Python code can subclass to
serve as the chain backend. Override:
get_account_info(self, address: Address, block_number: int = 0) -> AccountInfoget_contract_code(self, address: Address) -> bytesget_storage_slots(self, address: Address, slot_keys: list[int], block_number: int = 0) -> list[int]update_account(self, address: Address, info: AccountInfo) -> boolsave_contract_code(self, address: Address, code: bytes) -> boolupdate_storage_slots(self, address: Address, entries: dict[int, int]) -> bool
MockChain is a built-in StateProvider implementation backed by in-memory
hash tables. It is the recommended starting point for test suites and is what
the examples in this document use.
Running the EVM
The high-level entry points on any StateProvider (including MockChain)
hide transaction construction behind keyword arguments:
result = chain.simulate(dst, src, data=b"", value=0, block=None,
gas=3_000_000, trace=None)
result = chain.execute(dst, src, data=b"", value=0, block=None,
gas=3_000_000, trace=None)
gas = evm.EVM.initial_gas_cost(calldata)
All arguments after src are optional. block defaults to a sensible
context; value and gas accept either int or float (e.g. 1e18
for one ETH, 1.5e6 for 1.5M gas) — floats are rounded to the nearest
integer for gas and truncated toward zero for value. data defaults
to empty calldata, and gas defaults to 3,000,000.
If dst has no contract code installed it is treated as an Externally
Owned Account: the call succeeds immediately after any value transfer,
without executing any bytecode. Installing code via set_code turns
the address into a contract from that point on.
simulate does not mutate the underlying provider. execute writes the
resulting state back through the provider's update_* callbacks.
For lower-level control you can build a Transaction (or
TransactionBuilder) explicitly and run it through the EVM class:
machine = evm.EVM(chain)
tx = evm.Transaction.call(from_=src, to=dst, data=b"", gas_limit=100_000)
result = machine.simulate(tx, block_info, tracer=None)
Tracing
The simplest way to capture every contract call made by a transaction is
evm.CallTrace:
trace = evm.CallTrace()
chain.execute(dst, src, trace=trace)
for entry in trace.calls:
print(entry.src, "->", entry.dst, entry.success)
For custom logic, subclass evm.Tracer and override the callbacks:
class MyTracer(evm.Tracer):
def on_contract_call(self, chain, call_trace):
print(f"Call from {call_trace.src} to {call_trace.dst}")
def on_event_log(self, chain, event_trace):
print(f"Log from {event_trace.src} with {len(event_trace.topics)} topics")
chain.execute(dst, src, trace=MyTracer())
Threading and memory
The bindings release the GIL during long-running EVM execution so that Python threads can make progress in parallel. Callbacks into Python (state provider methods, tracers) reacquire the GIL automatically.
Versioning
Wheels are tagged with the upstream Komozoi EVM version followed by a build metadata suffix when applicable. Breaking changes to the Python API are only introduced on a major version bump.
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 Distributions
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 komozoi_evm-0.0.1.tar.gz.
File metadata
- Download URL: komozoi_evm-0.0.1.tar.gz
- Upload date:
- Size: 92.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6659b7a2cc88a9f6a9422452525042f0d7b683c358627853cd3480f08c034ad6
|
|
| MD5 |
c395bccab226e097bf724c3fb15d49ae
|
|
| BLAKE2b-256 |
19810605b211fa73ef1bd565ebce97d1dd7e2f50e8f6d0539f0eeda55003dd14
|
Provenance
The following attestation bundles were made for komozoi_evm-0.0.1.tar.gz:
Publisher:
release-pypi.yml on komozoi/komozoievm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
komozoi_evm-0.0.1.tar.gz -
Subject digest:
6659b7a2cc88a9f6a9422452525042f0d7b683c358627853cd3480f08c034ad6 - Sigstore transparency entry: 1738518568
- Sigstore integration time:
-
Permalink:
komozoi/komozoievm@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/komozoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Trigger Event:
push
-
Statement type:
File details
Details for the file komozoi_evm-0.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: komozoi_evm-0.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 358.8 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfacc0a1d4c66ea7d7296c85758fc288a11d56a57706a24d30f46967ea7e1a1a
|
|
| MD5 |
6f86f258c56c9fcb3b0f77ad619cee64
|
|
| BLAKE2b-256 |
30bcc413caeae62c188623ef99b903d1f52e95db3f33bf5ff66c144ccee40839
|
Provenance
The following attestation bundles were made for komozoi_evm-0.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-pypi.yml on komozoi/komozoievm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
komozoi_evm-0.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
dfacc0a1d4c66ea7d7296c85758fc288a11d56a57706a24d30f46967ea7e1a1a - Sigstore transparency entry: 1738518712
- Sigstore integration time:
-
Permalink:
komozoi/komozoievm@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/komozoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Trigger Event:
push
-
Statement type:
File details
Details for the file komozoi_evm-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: komozoi_evm-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 358.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58c7a26ec907d81762f030e33037a668eb7b2ffc846300d561af8bbc1ac8955f
|
|
| MD5 |
db6f404dfcf4659824198e159bd3ec77
|
|
| BLAKE2b-256 |
54a8f0b6aa14b318116adc6b8aa685a1e4983655d0705cdcadf7d4699fad1b84
|
Provenance
The following attestation bundles were made for komozoi_evm-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-pypi.yml on komozoi/komozoievm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
komozoi_evm-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
58c7a26ec907d81762f030e33037a668eb7b2ffc846300d561af8bbc1ac8955f - Sigstore transparency entry: 1738518689
- Sigstore integration time:
-
Permalink:
komozoi/komozoievm@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/komozoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Trigger Event:
push
-
Statement type:
File details
Details for the file komozoi_evm-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: komozoi_evm-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 358.6 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b60f2da75ea0cc5d74e3eeeec57d72732097332ae632beb7d2fb7898a4506851
|
|
| MD5 |
8854e4112a1105f7fe0b98f18781df96
|
|
| BLAKE2b-256 |
fa7ae14783cd8f431ad32915031ed9dc2b601120cb183e64f5da0d331eb39a91
|
Provenance
The following attestation bundles were made for komozoi_evm-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-pypi.yml on komozoi/komozoievm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
komozoi_evm-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
b60f2da75ea0cc5d74e3eeeec57d72732097332ae632beb7d2fb7898a4506851 - Sigstore transparency entry: 1738518736
- Sigstore integration time:
-
Permalink:
komozoi/komozoievm@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/komozoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Trigger Event:
push
-
Statement type:
File details
Details for the file komozoi_evm-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: komozoi_evm-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 357.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b22e829bf3b2accdb5e6f722579bd0ab55ca1228ebc5f7b67f47e2a63d35fd0
|
|
| MD5 |
9fbc919472d64dbd7a187a43d9afeb89
|
|
| BLAKE2b-256 |
b9c9d9eda40a4c2da310302879018cc7a2d0ec6a692c3799bc57fa87cd66686f
|
Provenance
The following attestation bundles were made for komozoi_evm-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-pypi.yml on komozoi/komozoievm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
komozoi_evm-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
6b22e829bf3b2accdb5e6f722579bd0ab55ca1228ebc5f7b67f47e2a63d35fd0 - Sigstore transparency entry: 1738518642
- Sigstore integration time:
-
Permalink:
komozoi/komozoievm@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/komozoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Trigger Event:
push
-
Statement type:
File details
Details for the file komozoi_evm-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: komozoi_evm-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 357.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74657d7950b81e222aa543d66f4af7a865f2dd3b9f0067ec5035177dd1139ce0
|
|
| MD5 |
bbb0082f7d5626a530c0a945f08f7300
|
|
| BLAKE2b-256 |
48f1376c7556c9d90f0ce856438689159e235ebc0d610d4ce4f01fab77d5d08e
|
Provenance
The following attestation bundles were made for komozoi_evm-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-pypi.yml on komozoi/komozoievm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
komozoi_evm-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
74657d7950b81e222aa543d66f4af7a865f2dd3b9f0067ec5035177dd1139ce0 - Sigstore transparency entry: 1738518610
- Sigstore integration time:
-
Permalink:
komozoi/komozoievm@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/komozoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@b2240f428645fd53ce0c8ae728fb03c16b9bb482 -
Trigger Event:
push
-
Statement type: