Aleo for Agents is offline at present

glossary·2026-08-03·2 min read

Finalize

Finalize

Finalize is the on-chain execution phase of an Aleo program function. The main function body runs off-chain with private inputs and produces a zero-knowledge proof. The finalize portion runs on-chain after validators verify that proof. It is the only way to read from and write to mappings, Aleo's public key-value storage. In current Leo syntax, this is a final { } block within a function.

Private computation (record manipulation, arithmetic on secret values) happens off-chain where only the user sees the data. Public state changes (incrementing a counter, updating a registry, recording a vote) happen on-chain in the finalize phase, where all validators execute the same deterministic logic.

Finalize blocks operate on public data and mapping state. They cannot touch records, and context accessors like std::ctx::caller() are unavailable inside them. If a finalize block fails, through an assertion, an arithmetic overflow, or a get on a missing key, the entire transaction is rejected even though the proof was valid, and the fee is still consumed.

A final { } block closes over the surrounding entry point's scope, so a value computed in the off-chain half is simply readable inside it. Leo 3.5 required passing those values explicitly to a separate async function; that plumbing is gone. What has not changed is that anything the block writes becomes public, so a private value read in the proof half and stored in a mapping has been published.

Sources