Skip to main content

Estimate worst-case EVM gas costs from runtime measurements.

Project description

evm-gasfit

PyPI version Python versions CI Docs License: CC0-1.0

Estimate worst-case EVM gas costs from runtime measurements.

evm-gasfit is a standalone, analysis-only Python package. Given a YAML test config, a CSV of per-client runtime measurements, and a JSON of opcode counts, it fits NNLS regressions over the runtimes, applies an optional glue-opcode adjustment, and produces a gas-cost proposal as CSV and Markdown artifacts.

Install

For development (editable + test tools):

pip install -e ".[dev]"

The optional specs extra pulls per-fork GasCosts tables directly from ethereum/execution-specs. Without it, the package falls back to a bundled per-fork table:

pip install -e ".[specs]"

Python 3.10 or newer is required.

Quickstart

A minimal tests.yaml:

version: 1
anchor_rate: 1.0e8
clients:
  - geth
  - besu
gas_costs:
  fork: osaka
models:
  presets:
    - arithmetic_add

clients is required: only rows whose client_name matches an entry here are kept from the runtimes CSV, and a configured client that produced no fits at all surfaces in the proposal report's Incomplete client coverage section.

Any gas-param name that the model proposes but the fork's GasCosts doesn't already define must be declared up front under new_params. The value is either null ("no prior default") or an integer that renders as the current_gas baseline in the proposal diff:

new_params:
  COLD_ACCOUNT_NOCODE_ACCESS: null   # no prior default to diff against
  STORAGE_WRITE: 2800                # render 2800 in the diff column

Names without a declaration are a hard config error — this catches typos in model_params RHS values at load time.

Run the full pipeline from the command line:

evm-gasfit run \
    --config tests.yaml \
    --runtimes runtime.csv \
    --opcounts opcounts.json \
    --out ./out

Exit codes: 0 on success, 1 for config/input errors, 2 for modeling failures.

Or drive it from Python:

from evm_gasfit import GasFit

fit = GasFit.from_config("tests.yaml")
fit.load_runtimes("runtime.csv")
fit.load_opcounts("opcounts.json")
fit.estimate_models()
fit.build_proposal()
fit.write_reports("./out")

Public API

The top-level package re-exports a small surface:

from evm_gasfit import GasFit, GasCosts, load_config

Everything else is internal. See the rendered API reference at docs/api.md (auto-deployed to GitHub Pages from mkdocs.yml).

Outputs

write_reports(out_dir) emits:

  • results.csv — one row per fit ((spec, model_by-combo, client)).
  • new_gas_all_params.csv — per-client gas-param proposals.
  • new_gas.csv — worst-case across clients (one row per gas param).
  • runtime_estimation_autogenerated_report.md — per-spec regression summary.
  • new_gas_proposal.md — final proposal, opening with a Contents TOC. Carries a diff table for fitted rows (against patched fork values + new_params integer baselines), a Client comparison section showing each parameter's worst vs. second-worst client and a worst / second-worst ratio (large ratios flag the worst client as an outlier) plus a per-client overview of proposed values — rendered as a log2(proposed / current) heatmap when plots are on (red = more expensive than current, green = cheaper, blank rows for new_params declared without a baseline) or as a markdown table when plots are off, a Worst-case provenance section with one collapsible block per gas param showing every per-client candidate (one row per (test_name, target_opcode, model_coef_name, model_by) combo, one column per client, cells = proposed gas); the cell the per-client selector picked as that client's worst-case is highlighted (outlined on the heatmap, bolded in the markdown-table fallback), and a warnings section containing Missing parameters (proposed names that produced no value), Incomplete client coverage (proposed names fit for some clients but missing on others), Missing glue adjustments, and Other. A trailing Poor-fit selections section flags winning fits whose p-value or R² crossed the modeling.poor_fit_*_threshold knobs (Winners with poor fit) plus any losing candidates that failed the same thresholds (Other weak candidates).

When glue adjustment is enabled, glue_results.csv, glue_opcodes_by_test.csv, and glue_opcodes_autogenerated_report.md are written too. Each priced glue opcode's per-client contribution is applied only when its fit passes both glue_contribution_p_value_threshold (default 0.05) and glue_contribution_rsquared_threshold (default 0.7); skipped contributions surface under Missing glue adjustments in the proposal so the affected gas params and clients are auditable. When output.plots: true, regression and diagnostic figures land under figs/.

Tests

pytest

The end-to-end suite synthesizes its own inputs and exercises the public API and CLI; there are no fixtures to download.

License

See LICENSE.

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

evm_gasfit-0.0.1.tar.gz (118.8 kB view details)

Uploaded Source

Built Distribution

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

evm_gasfit-0.0.1-py3-none-any.whl (84.1 kB view details)

Uploaded Python 3

File details

Details for the file evm_gasfit-0.0.1.tar.gz.

File metadata

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

File hashes

Hashes for evm_gasfit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8ca64f2e1c5a28c40a5b2331fb84980614b7869e413fee83d2a8583834b6551e
MD5 0f9f32e617a38088e8986a66068599e5
BLAKE2b-256 e7709fee1c00626c984423453a6a7ee6abaff4de4f00f5f914baa8a678c465e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for evm_gasfit-0.0.1.tar.gz:

Publisher: release.yml on misilva73/evm-gasfit

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

File details

Details for the file evm_gasfit-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: evm_gasfit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 84.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for evm_gasfit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 246da6e1885d5b7f220c7fb2ce5b9e1522b3c0cbfa17bb59b7b23ad575c7b737
MD5 20621ccf7ef1a09fb9b3e2d7f129f414
BLAKE2b-256 7e5e3d9dcbe485dd72e39a49ad2b2f408dea159b85ee7a71bba9a18d344a0ee2

See more details on using hashes here.

Provenance

The following attestation bundles were made for evm_gasfit-0.0.1-py3-none-any.whl:

Publisher: release.yml on misilva73/evm-gasfit

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