Free Function (Helper)
A free function in Leo is a helper defined outside the program { } block. It is automatically inlined by the compiler into the calling function's proof rather than generating a separate proof of its own:
leo
fn check_balance(balance: u64, amount: u64) -> bool {
return balance >= amount;
}
program my_program.aleo {
@noupgrade
constructor() {}
fn transfer(balance: u64, amount: u64) -> u64 {
assert(check_balance(balance, amount));
return balance - amount;
}
}
Use free functions for code reuse - validation checks, calculations, formatting - without the overhead of creating additional transitions. They cannot be called directly from outside the program.