Skip to main content
The network module defines the Network trait and its implementations (MainnetV0, TestnetV0, CanaryV0). Networks specify consensus parameters, cryptographic functions, and blockchain configuration.

Network Trait

The core trait that defines a network’s parameters and capabilities.

Declaration

Identity Constants

u16
The network ID (unique identifier)
&'static str
The long network name (e.g., “Mainnet”)
&'static str
The short network name (e.g., “mainnet”)

Genesis Parameters

i64
The fixed timestamp of the genesis block
u64
The genesis block coinbase target
u64
The genesis block proof target

Supply and Economics

u64
Starting supply of Aleo credits (1.5B)
u64
Maximum supply of Aleo credits (5B)
u32
Block height that upper bounds total supply to 5B
u64
Cost in microcredits per byte for deployment (1,000)
u64
Multiplier in microcredits for each constructor command (100)
u64
Cost in microcredits per constraint (25)
u64
Maximum microcredits that can be spent as a fee (1T)
[(ConsensusVersion, u64); 2]
Transaction spend limits by consensus version

Timing Parameters

u16
Expected time per block in seconds (10)
u16
Anchor time in seconds (25)
u32
Expected blocks to reach coinbase target (ANCHOR_TIME / BLOCK_TIME)
u32
Number of blocks per epoch (360 blocks ≈ 1 hour)

Data Limits

usize
Maximum number of entries in data (32)
usize
Maximum recursive depth of an entry (32)
u32
Maximum number of fields in data (must not exceed u16::MAX)
usize
Minimum number of entries in a struct (1)
usize
Maximum number of entries in a struct (32)
usize
Minimum number of elements in an array (1)
[(ConsensusVersion, usize); 3]
Maximum array elements by consensus version (32 → 512 → 2048)
usize
Minimum number of entries in a record (1, for owner)
usize
Maximum number of entries in a record (33)

Program Limits

[(ConsensusVersion, usize); 2]
Maximum program size in characters (100 kB → 512 kB)
usize
Maximum number of mappings in a program (31)
usize
Maximum number of functions in a program (31)
usize
Maximum number of structs in a program (310)
usize
Maximum number of records in a program (310)
usize
Maximum number of closures in a program (62)
usize
Maximum number of instructions in a closure/function (65,535)
usize
Maximum number of commands in finalize (65,535)
[(ConsensusVersion, u16); 2]
Maximum write commands in finalize (16 → 32)
usize
Maximum number of inputs per transition (16)
usize
Maximum number of outputs per transition (16)
usize
Maximum number of imports (64)
[(ConsensusVersion, usize); 2]
Maximum transaction size in bytes (128 kB → 768 kB)

Associated Types

type StateRoot: Bech32ID<Field<Self>>
The state root type
type BlockHash: Bech32ID<Field<Self>>
The block hash type
type RatificationID: Bech32ID<Field<Self>>
The ratification ID type
type TransactionID: Bech32ID<Field<Self>>
The transaction ID type
type TransitionID: Bech32ID<Field<Self>>
The transition ID type

Consensus Methods

fn CONSENSUS_VERSION(height: u32) -> Result<ConsensusVersion>
Returns the consensus version active at the given height
fn CONSENSUS_HEIGHT(version: ConsensusVersion) -> Result<u32>
Returns the height at which a consensus version becomes active
fn INCLUSION_UPGRADE_HEIGHT() -> Result<u32>
Returns the block height where the inclusion proof will be updated

Cryptographic Functions

Commitment Functions

fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 256-bit input hasher
fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 512-bit input hasher
fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 768-bit input hasher
fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 1024-bit input hasher
fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
Pedersen commitment for up to 64-bit input
fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
Pedersen commitment for up to 128-bit input

Hash Functions

fn hash_bhp256(input: &[bool]) -> Result<Field<Self>>
BHP hash with 256-bit input hasher
fn hash_bhp512(input: &[bool]) -> Result<Field<Self>>
BHP hash with 512-bit input hasher
fn hash_bhp768(input: &[bool]) -> Result<Field<Self>>
BHP hash with 768-bit input hasher
fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>>
BHP hash with 1024-bit input hasher
fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>>
Poseidon hash with input rate of 2
fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>>
Poseidon hash with input rate of 4
fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>>
Poseidon hash with input rate of 8
fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>>
Keccak hash with 256-bit output
fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>>
SHA-3 hash with 256-bit output

Hash to Group/Scalar

fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>>
Poseidon hash to group with input rate of 2
fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>>
Poseidon hash to group with input rate of 4
fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>>
Poseidon hash to group with input rate of 8
fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>>
Poseidon hash to scalar with input rate of 2
fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>>
Poseidon hash to scalar with input rate of 4
fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>>
Poseidon hash to scalar with input rate of 8

Merkle Trees

fn merkle_tree_bhp<const DEPTH: u8>(leaves: &[Vec<bool>]) -> Result<BHPMerkleTree<Self, DEPTH>>
Merkle tree with BHP leaf hasher (1024-bit) and path hasher (512-bit)
fn merkle_tree_psd<const DEPTH: u8>(leaves: &[Vec<Field<Self>>]) -> Result<PoseidonMerkleTree<Self, DEPTH>>
Merkle tree with Poseidon leaf hasher (rate 4) and path hasher (rate 2)
fn verify_merkle_path_bhp<const DEPTH: u8>(path: &MerklePath<Self, DEPTH>, root: &Field<Self>, leaf: &Vec<bool>) -> bool
Verifies a BHP Merkle path
fn verify_merkle_path_psd<const DEPTH: u8>(path: &MerklePath<Self, DEPTH>, root: &Field<Self>, leaf: &Vec<Field<Self>>) -> bool
Verifies a Poseidon Merkle path

Domain Separators

fn commitment_domain() -> Field<Self>
Returns the commitment domain constant
fn encryption_domain() -> Field<Self>
Returns the encryption domain constant
fn graph_key_domain() -> Field<Self>
Returns the graph key domain constant
fn serial_number_domain() -> Field<Self>
Returns the serial number domain constant

MainnetV0

The production Aleo network.

Example

Configuration

TestnetV0

The test network for development and testing.

Example

Configuration

CanaryV0

The canary network for testing upgrades.

Example

Configuration

Helper Types

BHPMerkleTree

Merkle tree using BHP hash functions.

PoseidonMerkleTree

Merkle tree using Poseidon hash functions.

Consensus Versions

Networks support multiple consensus versions:

Querying Consensus

Using Network Parameters

Example: Fee Calculation

Example: Using Cryptographic Functions

Example: Merkle Trees

See Also