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.1.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.1-cp37-abi3-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.7+Windows x86-64

aleo_contract_abi_generator-0.2.1-cp37-abi3-manylinux_2_28_x86_64.whl (2.5 MB view details)

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

aleo_contract_abi_generator-0.2.1-cp37-abi3-manylinux_2_28_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

aleo_contract_abi_generator-0.2.1-cp37-abi3-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

aleo_contract_abi_generator-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 266ea361dc8d9ef4d8877c9dcd6ff361e73977537e6ddf5921ff97f32c79b4c9
MD5 a07c66eff2b380a8b3a8d898be1419b3
BLAKE2b-256 f42e3ce5c7bc554e8d544d8b14df2f48f2e78065c056f53921eb28aa48be407e

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.1.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.1-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a47d90a8ce85d41cdd9ee42ca4bd4cc471f20caa6f84c27411d25bf7b2f3564d
MD5 a1c2910a8ca7e58f1abb30fcd8b8e2de
BLAKE2b-256 1f5af6377ce9a3cc5808a6557d682a2636fe91877fd71ceb9275d7de4bb17ca5

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.1-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.1-cp37-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.1-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5c5ddc53eff2fe6d47c18df9f428538d50c47c2ba6834b5743ddfcd7abdab1c3
MD5 77145dcf4894a10443235eca575d18af
BLAKE2b-256 d86395a624eb8740923ea5af9a550ac4f77680620578f4bb163293e21565d22f

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.1-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.1-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.1-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 264a0c3875d3c4914ae1b6a0de8a2f07741a69ad2131fcc92db06e84f7e2a33d
MD5 9103c8090c6e2b6f8f01e246b88170a7
BLAKE2b-256 d0badcc0f39b29fbda66a477b908cb3541bdf85e920ec2a8749ed24e89517947

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.1-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.1-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c2de35683f104232c99f6488de660819e507ac46024a4b7cb81484399ddca9d
MD5 1a036c8ca232ce1f67cebbbb1c363a63
BLAKE2b-256 33756209f2065d7697996c35dd92bced08e1b9a6c385e604549cb341364ac3f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.1-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.1-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for aleo_contract_abi_generator-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b8b21a32fcb84c63eade18a2eafb5588742727d45d036177662d037897d98e66
MD5 6477a6f2c6a2e015f164ff27d72e13dd
BLAKE2b-256 5ef9bd6c3b98f5d5208028784ad59f61a06dd1a2c5efc3998b0e5b6648deb3f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for aleo_contract_abi_generator-0.2.1-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