Aleo Programs
An Aleo program defines private application logic executed by the Aleo VM. Most developers write programs in Leo and compile them for the VM.
Structure
- Program ID:
program <name>.aleo; - Entrypoints: typed inputs → computation → typed outputs
- Types: primitives plus
structandrecord
program foo.aleo;
function hello:
input r0 as u32.public;
input r1 as u32.private;
add r0 r1 into r2;
output r2 as u32.private;
Registers and visibility
Values are stored in registers (r0, r1, ...). Each value has a type and a visibility:
.public: revealed.private: proven, not revealed
Types
Primitive types include:
address
boolean
field
group
i8
i16
i32
i64
i128
u8
u16
u32
u64
u128
scalar
struct
struct array3:
a0 as u32;
a1 as u32;
a2 as u32;
record (private state)
Records are user-owned state. Transactions typically consume records and create new records.
record token:
owner as address.private;
amount as u64.private;
Example: mint + transfer
program foo.aleo;
record token:
owner as address.private;
amount as u64.private;
function mint:
input r0 as u64.private;
cast self.signer r0 into r1 as token.record;
output r1 as token.record;
function transfer_amount:
input r0 as token.record;
input r1 as address.private;
input r2 as u64.private;
sub r0.amount r2 into r3;
cast r0.owner r3 into r4 as token.record;
cast r1 r2 into r5 as token.record;
output r4 as token.record;
output r5 as token.record;