Skip to main content
This example shows how to write a custom Aleo program, deploy it to the VM, and execute its functions using SnarkVM.

The program

We’ll create a simple program that performs basic arithmetic with private values:

Complete example

Step by step

1

Write the program

Aleo programs use a simple assembly-like syntax. Each function:
  • Declares inputs with types and visibility (.private or .public)
  • Performs operations using registers (r0, r1, etc.)
  • Returns outputs with types and visibility
2

Parse the program

Parse the program string into a Program object. This validates the syntax and generates the program ID.
3

Deploy the program

Deploy the program to the VM. This makes it available for execution.
4

Execute functions

Execute the deployed function with inputs. The VM generates a zero-knowledge proof that the computation was performed correctly.

Program features

Data types

Aleo supports these primitive types:
  • Integers: u8, u16, u32, u64, u128, i8, i16, i32, i64, i128
  • Field elements: field, group, scalar
  • Boolean: boolean
  • Address: address
  • Signature: signature

Visibility modifiers

  • .private - Hidden from public view, proven in zero-knowledge
  • .public - Visible on the blockchain
  • .record - Private state with ownership

Operations

Common operations available:
  • Arithmetic: add, sub, mul, div, rem
  • Bitwise: and, or, xor, shl, shr
  • Comparison: lt, lte, gt, gte
  • Logical: and, or, not
  • Cryptographic: hash.bhp256, commit.bhp256, sign.verify

Advanced example: Working with structs

Execute with struct inputs:
All computation is performed privately. The inputs, outputs, and intermediate values are hidden using zero-knowledge proofs.

Next steps

Proof verification

Learn about zero-knowledge proof generation

Creating programs

Deep dive into Aleo program development