Skip to main content

Compiler-backed tool for upgrading Vyper contracts.

Project description

vyupgrade

A compiler-backed tool for upgrading Vyper contracts across language versions. It rewrites legacy syntax to a chosen target compiler, then proves the rewrite is safe by compiling the source and the result and comparing their ABI, method identifiers, and storage layout.

It covers the syntax changes from Vyper 0.2.1 through 0.4.3. Rules are version-gated: a given rewrite only fires when the migration from the source version to the target version actually crosses the compiler release that introduced the change.

Install

Run it once without installing:

uvx vyupgrade contracts/

Or install it as a tool:

uv tool install vyupgrade
vyupgrade contracts/

Usage

Preview the changes as a unified diff:

vyupgrade contracts/ --diff

Apply them in place and write a machine-readable report:

vyupgrade contracts/ --write --report-json vyupgrade-report.json

Fail without writing when files would change, for use in CI:

vyupgrade contracts/ --check

The target defaults to 0.4.3; pass --target-version to migrate to a different release.

Paths may be files or directories; directories are searched recursively for .vy and .vyi sources. The source version is inferred per file from its #pragma version (or legacy # @version) line. Pass --source-version to override the inference for files that have no pragma.

How it validates

For each file, vyupgrade compiles the original under its source compiler and the rewritten output under the target compiler, then compares the two artifacts. A migration is only written back when every file still compiles under the target. Differences in ABI, method identifiers, or storage layout are surfaced as diagnostics rather than silently accepted.

Compiler subprocesses run through the bundled uv, using uv run --no-project --with vyper==<version> so each side gets the exact compiler it needs instead of inheriting an incompatible interpreter. When a file belongs to another project, the nearest pyproject.toml is read and any declared packages matching its Vyper imports (such as snekmate) are added to the compiler environment.

Dependency inference is intentionally conservative. Exact requirements, ordinary version ranges, and Git dependencies are supported. Project-specific specifier syntaxes that cannot be translated to a compiler environment, such as Poetry caret requirements, are skipped; use --compiler-search-paths, --source-vyper, or --target-vyper for unusual layouts.

Options

  • --target-version — target Vyper version or spec (default 0.4.3).
  • --source-version — override the per-file inferred source version.
  • --diff — print a unified diff instead of the report.
  • --write — apply changes in place (only when every file compiles).
  • --check — exit non-zero if any file would change; write nothing.
  • --bump-pragma — rewrite the pragma to the target so output compiles against the target compiler instead of preserving the original range.
  • --aggressive — enable rewrites that change behavior or are not provably safe (e.g. enumflag).
  • --select / --ignore — comma-separated rule codes to include or exclude.
  • --report-json PATH — write a JSON report of fixes, diagnostics, and validation results.
  • --format mamushi — run mamushi over written files to reformat them.
  • --test-command CMD — run a test command after a successful write and record its result.
  • --enable-decimals — treat decimals as enabled when reasoning about 0.4.x rules.
  • --source-vyper / --target-vyper — pin the exact compiler version for each side.
  • --source-python / --target-python — pin the Python interpreter for each compiler subprocess.
  • --compiler-search-paths — extra import search paths for the compiler.
  • --config PATH — read configuration from a specific pyproject.toml.

Configuration

Defaults can live in pyproject.toml under [tool.vyupgrade]. Command-line flags take precedence.

[tool.vyupgrade]
paths = ["contracts/"]
target-version = "0.4.3"
source-version = "infer"
report-json = "vyupgrade-report.json"
aggressive = false
format = "none"

Exit codes

  • 0 — success.
  • 1--check found files that would change.
  • 2 — a file failed to compile under the target compiler.
  • 3 — a file failed to compile under the source compiler.
  • 4 — usage error (no paths, or conflicting flags).
  • 5 — an error-severity diagnostic was raised.

Coverage

Rewrites carry a VY### code and diagnostics a VYD### code. Where the source intent cannot be proven safe, the change is reported as a manual-review diagnostic instead of being applied.

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

vyupgrade-0.1.0.tar.gz (49.8 kB view details)

Uploaded Source

Built Distribution

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

vyupgrade-0.1.0-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vyupgrade-0.1.0.tar.gz
Algorithm Hash digest
SHA256 af57da046365dfdf43e11bdde88ec3e99c215e6065ada31c4164d4437c0bcf73
MD5 b63f00410b4d0214f64c1452e696e6c5
BLAKE2b-256 01618d295bd00b27900d08d26b59ace1d6148322e56703135736a5bee6b65224

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on banteg/vyupgrade

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

File details

Details for the file vyupgrade-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for vyupgrade-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d76c8b9e5f184dd531ee034b543a6262ba7b17ebbe82f25c6afe8a9d6e4a1df
MD5 ce820fb4b3edbe049d0e8b39d6d4a440
BLAKE2b-256 9d6cd51821b96ffc0f6530496ceb5415ae896550da144a7b2e709392488a5bdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for vyupgrade-0.1.0-py3-none-any.whl:

Publisher: publish.yml on banteg/vyupgrade

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