Skip to main content
This guide walks through creating and compiling Aleo programs with snarkVM. Programs define the logic for zero-knowledge applications on the Aleo blockchain.

Program Structure

Aleo programs are written in the Leo/Aleo language and define functions, mappings, and records. Here’s a basic structure:

Parsing Programs

Use the Program::from_str method to parse program source code:
Program IDs must be unique on the network. Use a descriptive name followed by .aleo.

Validating Programs

Once parsed, you can access program components:

Compiling Programs with the VM

The VM compiles programs by generating proving and verifying keys:

Program Imports

Programs can import other programs that are already deployed:
Imported programs must be deployed to the network before your program can reference them.

Error Handling

Common compilation errors:

Best Practices

Use Meaningful Names

Document Complex Logic

Include comments in your program source to explain complex operations, especially in finalize blocks.

Test Incrementally

Start with simple functions and test them before adding complexity. Use the VM to execute test cases.

Optimize for Constraints

Zero-knowledge proofs have computational costs. Minimize operations in functions to reduce proving time:
  • Avoid unnecessary multiplications
  • Use efficient data structures
  • Keep functions focused and modular

Program Editions

Starting with consensus version V9, programs support editions for upgrades:
This allows deploying updated versions of programs while maintaining the same program ID.

Next Steps