Aleo for Agents is offline at present

glossary·2026-08-03·1 min read

Free Function (Helper)

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. They add no separate entry point and cannot be called from outside the program.

Leo 4.x removed the inline and function keywords. Everything is fn now, and where it sits decides its role: inside the program { } block it is an entry point, outside it is a helper. Helpers declared inside the program block are a parse error.

The related final fn is the same idea for on-chain code. It also lives outside the program block, and its body is inlined into each caller's final { } block, which makes it a way to deduplicate finalization logic rather than a standalone on-chain function.

Sources