This guide walks through creating and compiling Aleo programs with snarkVM. Programs define the logic for zero-knowledge applications on the Aleo blockchain.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/provablehq/snarkvm/llms.txt
Use this file to discover all available pages before exploring further.
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 theProgram::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:use snarkvm_synthesizer::VM;
use snarkvm_ledger_store::ConsensusStore;
use aleo_std::StorageMode;
#[cfg(not(feature = "rocks"))]
type ConsensusMemory = snarkvm_ledger_store::helpers::memory::ConsensusMemory<CurrentNetwork>;
#[cfg(feature = "rocks")]
type ConsensusDB = snarkvm_ledger_store::helpers::rocksdb::ConsensusDB<CurrentNetwork>;
// Initialize storage
let store = ConsensusStore::open(StorageMode::Production)?;
// Create VM instance
let vm = VM::from(store)?;
use rand::thread_rng;
let rng = &mut thread_rng();
// Compile the program (generates keys)
let deployment = vm.deploy_raw(&program, rng)?;
println!("Program compiled successfully");
println!("Deployment size: {} bytes", deployment.size_in_bytes());
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:Next Steps
- Learn about deploying programs to the network
- Explore executing transactions with your programs
- Understand managing records created by your programs