Overview
Leo provides a minimal standard library focused on zero-knowledge circuit operations. Most functionality is expressed through built-in operations and Aleo VM primitives.Built-in Functions
Mapping Operations
Mapping operations are available in finalizer functions for interacting with on-chain storage.Mapping::get
Retrieve a value from a mapping by key.Mapping::get_or_use
Retrieve a value from a mapping, or return a default if the key doesn’t exist.mapping: The mapping to querykey: The key to look updefault: The value to return if the key doesn’t exist
Mapping::set
Store a value in a mapping.- Creates the key if it doesn’t exist
- Overwrites the existing value if the key exists
- Changes are committed on-chain
Mapping::remove
Remove a key-value pair from a mapping.Random Number Generation
TheChaCha namespace provides cryptographically secure randomness.
ChaCha::rand_bool
Generate a random boolean value.Random values are generated deterministically based on the transaction’s randomness seed, ensuring reproducibility.
ChaCha::rand_u8 / rand_u16 / rand_u32 / rand_u64 / rand_u128
Generate random unsigned integers.ChaCha::rand_i8 / rand_i16 / rand_i32 / rand_i64 / rand_i128
Generate random signed integers.ChaCha::rand_field
Generate a random field element.ChaCha::rand_scalar
Generate a random scalar value.Assertions
assert
Assert that a condition is true. If false, the program execution fails.- Input validation
- Invariant checking
- Access control
- Boundary conditions
assert_eq
Assert that two values are equal.assert_ne
Assert that two values are not equal.Built-in Constants
Group Constants
group::GEN
The generator point of the elliptic curve group.Operator Overloading
Leo supports standard operators for built-in types:Arithmetic Operators
Comparison Operators
Logical Operators
Bitwise Operators
Context Variables
self.caller
The address of the account that invoked the current function.- Authorization checks
- Tracking function invokers
- Access control
self.signer
The address of the account that signed the transaction.block.height (Finalizers Only)
The current block height, available only in finalizer functions.- Time-based logic
- Expiration checks
- Epoch-based features
Type Conversion
as Operator
Explicitly cast between compatible types.- Integer to integer (any size)
- Integer to field
- Integer to scalar
- Field to integer (with potential loss)
No Standard Library Imports
Unlike many languages, Leo does not require importing standard library functions. All built-in functions are available in the global namespace.Limitations
Future Additions
The Leo standard library is intentionally minimal. Future versions may include:- Hash functions (Poseidon, SHA-256, etc.)
- Signature verification utilities
- Merkle tree operations
- Additional cryptographic primitives
Related Resources
Built-in Types
Complete type reference
Examples
See standard library in use