Skip to main content

Python bindings for ABI generation from Aleo bytecode

Project description

aleo-contract-abi-generator

Generates a JSON ABI from deployed Aleo bytecode, and checks one ABI against another for compatibility. Rust bindings around Leo's ABI generation with full snarkVM validation — a program that does not validate does not get an ABI. Everything runs locally; nothing touches the network.

The distribution is aleo-contract-abi-generator; the import module is aleo_abi.

import aleo_abi

abi_json = aleo_abi.generate_abi("simple.aleo", bytecode, "testnet", None)
violations = aleo_abi.check_compatibility(candidate_json, standard_json)

Install

pip install aleo-contract-abi-generator

Most callers want the friendlier hook in the main SDK instead — aleo.abi.generate_abi accepts a Program object or a raw bytecode string, infers the program name, and returns a dict:

from aleo import abi
from aleo.mainnet import Program

result = abi.generate_abi(Program.credits())
result["program"]        # "credits.aleo"

The hook imports this package lazily and raises ImportError with the install command if it is absent — the main SDK does not depend on it.

Generating an ABI

generate_abi(program_name, bytecode, network, imports) returns a pretty-printed JSON string describing the program: its structs, records, mappings, and functions, each field carrying a structured type ({"Primitive": {"Int": "I32"}}, record ownership, visibility).

snarkVM validation is contextual: a program that declares imports is rejected unless those imports are supplied. Pass them as (program_id, bytecode) pairs in topological order — dependencies before dependents:

abi_json = aleo_abi.generate_abi(
    "shield_swap_v3.aleo", amm_bytecode, "testnet",
    [("test_shield_swap_multisig_core.aleo", multisig_bytecode)],
)

network is "mainnet", "testnet", or "canary" — it selects the validation rules, not a connection.

Checking compatibility

check_compatibility(candidate_abi_json, standard_abi_json) returns a list of violation strings — empty means the candidate satisfies the standard. Use it to pin a deployed contract's surface and fail your CI when the deployment drifts, instead of your consumers:

violations = aleo_abi.check_compatibility(deployed_abi, pinned_abi)
assert not violations, "\n".join(violations)

This is how shield-swap-sdk's live drift test guards its committed bindings (codegen/regen-abi.sh regenerates the pin from the deployed program).

Downstream: generated Python bindings

The ABI JSON is the input format for the main SDK's aleo.codegen, which emits typed dataclasses and entrypoint stubs from it:

python -m aleo.codegen --abi shield_swap.abi.json --out _generated.py

Tests

cd sdk-abi && python -m pytest python/tests -v   # hermetic — no network

Fixtures and expected ABIs are vendored from Leo's own test suite, so the output shape is pinned to upstream.

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

aleo_contract_abi_generator-0.2.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distributions

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

aleo_contract_abi_generator-0.2.0-cp37-abi3-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.7+Windows x86-64

aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ x86-64

aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file aleo_contract_abi_generator-0.2.0.tar.gz.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c75d199f1b9ca029524a2ca5344f20a60d28d826c81facfe06e7ea6ae4993d81
MD5 ac9c8bc8647350c626684f47426fbda0
BLAKE2b-256 bc8c6a7debd821713561a43d291c587cfa3e3f8792b32694b1067f96301102be

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.0.tar.gz:

Publisher: sdk-wheels.yml on ProvableHQ/python-sdk

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

File details

Details for the file aleo_contract_abi_generator-0.2.0-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0f6cc8db42d88d44f35e03d2b4a74e328905967b17f948e5da9a39142d3c1606
MD5 74956ba131b4451f715998bdc5c8c0cc
BLAKE2b-256 51abc91d4dcdfd9b061448a64eb218b0e5517306f3d2eda1cc7fb6101f646f65

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.0-cp37-abi3-win_amd64.whl:

Publisher: sdk-wheels.yml on ProvableHQ/python-sdk

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

File details

Details for the file aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 69a6eba5b08c5b436a4672318ce1b0489a6b47a8b20cb6bcef67acbfa1e300ed
MD5 1c7ab7a93c865ab6a1d800f75d674cb0
BLAKE2b-256 d9bc45e52972a7ad836e242baa43654525c83c94573e329530e5253a45b9a40e

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_x86_64.whl:

Publisher: sdk-wheels.yml on ProvableHQ/python-sdk

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

File details

Details for the file aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0cf2b95d0c8f009e0fd6f7759f64b4b1fe0c2618f653134c4bda271f0c078086
MD5 ab854615b33d2bb17796421939ce2551
BLAKE2b-256 b5951950540070c8f4c4ffd4bb3e496118d82b736c95b85ec1304ca6c32a4bf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.0-cp37-abi3-manylinux_2_28_aarch64.whl:

Publisher: sdk-wheels.yml on ProvableHQ/python-sdk

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

File details

Details for the file aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 19caa9233a6b70ea87a3b6af55a1dfdf46ab8e3d3935a316e3cc670151cfbf95
MD5 a4b600e35aaa2de47c66992f015676d4
BLAKE2b-256 17eaf827f7535969b578d06095d899495dda9a5711c29a8262f4ee552bce491d

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_11_0_arm64.whl:

Publisher: sdk-wheels.yml on ProvableHQ/python-sdk

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

File details

Details for the file aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dbf7723a406daa35b6e23777b8fc0393accd486293f156b0142e2fd2d8c344af
MD5 3723c89d10c2204a1bba4161da80e815
BLAKE2b-256 780542f939f6bc6f29ee6477e414034fd04622755bd1415578cd5fdd0bac389b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.0-cp37-abi3-macosx_10_12_x86_64.whl:

Publisher: sdk-wheels.yml on ProvableHQ/python-sdk

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