Documentation Index
Fetch the complete documentation index at: https://mintlify.com/provablehq/snarkvm/llms.txt
Use this file to discover all available pages before exploring further.
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
pub trait Network:
'static
+ Environment
+ Copy
+ Clone
+ Debug
+ Eq
+ PartialEq
+ core::hash::Hash
+ Serialize
+ DeserializeOwned
+ for<'a> Deserialize<'a>
+ Send
+ Sync
{
// Constants and methods
}
Identity Constants
The network ID (unique identifier)
The long network name (e.g., “Mainnet”)
The short network name (e.g., “mainnet”)
Genesis Parameters
The fixed timestamp of the genesis block
The genesis block coinbase target
The genesis block proof target
Supply and Economics
Starting supply of Aleo credits (1.5B)
Maximum supply of Aleo credits (5B)
Block height that upper bounds total supply to 5B
DEPLOYMENT_FEE_MULTIPLIER
Cost in microcredits per byte for deployment (1,000)
CONSTRUCTOR_FEE_MULTIPLIER
Multiplier in microcredits for each constructor command (100)
Cost in microcredits per constraint (25)
Maximum microcredits that can be spent as a fee (1T)
TRANSACTION_SPEND_LIMIT
[(ConsensusVersion, u64); 2]
Transaction spend limits by consensus version
Timing Parameters
Expected time per block in seconds (10)
Anchor time in seconds (25)
Expected blocks to reach coinbase target (ANCHOR_TIME / BLOCK_TIME)
Number of blocks per epoch (360 blocks ≈ 1 hour)
Data Limits
Maximum number of entries in data (32)
Maximum recursive depth of an entry (32)
Maximum number of fields in data (must not exceed u16::MAX)
Minimum number of entries in a struct (1)
Maximum number of entries in a struct (32)
Minimum number of elements in an array (1)
MAX_ARRAY_ELEMENTS
[(ConsensusVersion, usize); 3]
Maximum array elements by consensus version (32 → 512 → 2048)
Minimum number of entries in a record (1, for owner)
Maximum number of entries in a record (33)
Program Limits
MAX_PROGRAM_SIZE
[(ConsensusVersion, usize); 2]
Maximum program size in characters (100 kB → 512 kB)
Maximum number of mappings in a program (31)
Maximum number of functions in a program (31)
Maximum number of structs in a program (310)
Maximum number of records in a program (310)
Maximum number of closures in a program (62)
Maximum number of instructions in a closure/function (65,535)
Maximum number of commands in finalize (65,535)
MAX_WRITES
[(ConsensusVersion, u16); 2]
Maximum write commands in finalize (16 → 32)
Maximum number of inputs per transition (16)
Maximum number of outputs per transition (16)
Maximum number of imports (64)
MAX_TRANSACTION_SIZE
[(ConsensusVersion, usize); 2]
Maximum transaction size in bytes (128 kB → 768 kB)
Associated Types
StateRoot
type StateRoot: Bech32ID<Field<Self>>
The state root type
BlockHash
type BlockHash: Bech32ID<Field<Self>>
The block hash type
RatificationID
type RatificationID: Bech32ID<Field<Self>>
The ratification ID type
TransactionID
type TransactionID: Bech32ID<Field<Self>>
The transaction ID type
TransitionID
type TransitionID: Bech32ID<Field<Self>>
The transition ID type
Consensus Methods
CONSENSUS_VERSION
fn CONSENSUS_VERSION(height: u32) -> Result<ConsensusVersion>
Returns the consensus version active at the given height
CONSENSUS_HEIGHT
fn CONSENSUS_HEIGHT(version: ConsensusVersion) -> Result<u32>
Returns the height at which a consensus version becomes active
INCLUSION_UPGRADE_HEIGHT
fn INCLUSION_UPGRADE_HEIGHT() -> Result<u32>
Returns the block height where the inclusion proof will be updated
Cryptographic Functions
Commitment Functions
commit_bhp256
fn commit_bhp256(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 256-bit input hasher
commit_bhp512
fn commit_bhp512(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 512-bit input hasher
commit_bhp768
fn commit_bhp768(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 768-bit input hasher
commit_bhp1024
fn commit_bhp1024(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
BHP commitment with 1024-bit input hasher
commit_ped64
fn commit_ped64(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
Pedersen commitment for up to 64-bit input
commit_ped128
fn commit_ped128(input: &[bool], randomizer: &Scalar<Self>) -> Result<Field<Self>>
Pedersen commitment for up to 128-bit input
Hash Functions
hash_bhp256
fn hash_bhp256(input: &[bool]) -> Result<Field<Self>>
BHP hash with 256-bit input hasher
hash_bhp512
fn hash_bhp512(input: &[bool]) -> Result<Field<Self>>
BHP hash with 512-bit input hasher
hash_bhp768
fn hash_bhp768(input: &[bool]) -> Result<Field<Self>>
BHP hash with 768-bit input hasher
hash_bhp1024
fn hash_bhp1024(input: &[bool]) -> Result<Field<Self>>
BHP hash with 1024-bit input hasher
hash_psd2
fn hash_psd2(input: &[Field<Self>]) -> Result<Field<Self>>
Poseidon hash with input rate of 2
hash_psd4
fn hash_psd4(input: &[Field<Self>]) -> Result<Field<Self>>
Poseidon hash with input rate of 4
hash_psd8
fn hash_psd8(input: &[Field<Self>]) -> Result<Field<Self>>
Poseidon hash with input rate of 8
hash_keccak256
fn hash_keccak256(input: &[bool]) -> Result<Vec<bool>>
Keccak hash with 256-bit output
hash_sha3_256
fn hash_sha3_256(input: &[bool]) -> Result<Vec<bool>>
SHA-3 hash with 256-bit output
Hash to Group/Scalar
hash_to_group_psd2
fn hash_to_group_psd2(input: &[Field<Self>]) -> Result<Group<Self>>
Poseidon hash to group with input rate of 2
hash_to_group_psd4
fn hash_to_group_psd4(input: &[Field<Self>]) -> Result<Group<Self>>
Poseidon hash to group with input rate of 4
hash_to_group_psd8
fn hash_to_group_psd8(input: &[Field<Self>]) -> Result<Group<Self>>
Poseidon hash to group with input rate of 8
hash_to_scalar_psd2
fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Result<Scalar<Self>>
Poseidon hash to scalar with input rate of 2
hash_to_scalar_psd4
fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Result<Scalar<Self>>
Poseidon hash to scalar with input rate of 4
hash_to_scalar_psd8
fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Result<Scalar<Self>>
Poseidon hash to scalar with input rate of 8
Merkle Trees
merkle_tree_bhp
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)
merkle_tree_psd
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)
verify_merkle_path_bhp
fn verify_merkle_path_bhp<const DEPTH: u8>(path: &MerklePath<Self, DEPTH>, root: &Field<Self>, leaf: &Vec<bool>) -> bool
Verifies a BHP Merkle path
verify_merkle_path_psd
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
commitment_domain
fn commitment_domain() -> Field<Self>
Returns the commitment domain constant
encryption_domain
fn encryption_domain() -> Field<Self>
Returns the encryption domain constant
graph_key_domain
fn graph_key_domain() -> Field<Self>
Returns the graph key domain constant
serial_number_domain
fn serial_number_domain() -> Field<Self>
Returns the serial number domain constant
MainnetV0
The production Aleo network.
Example
use snarkvm_console::network::{MainnetV0, Network};
type CurrentNetwork = MainnetV0;
println!("Network ID: {}", CurrentNetwork::ID);
println!("Network Name: {}", CurrentNetwork::NAME);
println!("Block Time: {}s", CurrentNetwork::BLOCK_TIME);
println!("Max Supply: {} credits", CurrentNetwork::MAX_SUPPLY);
Configuration
// Network identity
ID: 0
NAME: "Mainnet"
SHORT_NAME: "mainnet"
// Genesis parameters
GENESIS_TIMESTAMP: specific timestamp
GENESIS_COINBASE_TARGET: specific target
GENESIS_PROOF_TARGET: specific target
TestnetV0
The test network for development and testing.
Example
use snarkvm_console::network::{TestnetV0, Network};
type CurrentNetwork = TestnetV0;
// Use TestnetV0 for development
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
Configuration
// Network identity
ID: 1
NAME: "Testnet"
SHORT_NAME: "testnet"
// Same limits as mainnet but different genesis parameters
CanaryV0
The canary network for testing upgrades.
Example
use snarkvm_console::network::{CanaryV0, Network};
type CurrentNetwork = CanaryV0;
Configuration
// Network identity
ID: 2
NAME: "Canary"
SHORT_NAME: "canary"
Helper Types
BHPMerkleTree
pub type BHPMerkleTree<N, const DEPTH: u8> =
MerkleTree<N, BHP1024<N>, BHP512<N>, DEPTH>;
Merkle tree using BHP hash functions.
PoseidonMerkleTree
pub type PoseidonMerkleTree<N, const DEPTH: u8> =
MerkleTree<N, Poseidon4<N>, Poseidon2<N>, DEPTH>;
Merkle tree using Poseidon hash functions.
Consensus Versions
Networks support multiple consensus versions:
pub enum ConsensusVersion {
V1,
V10,
V11,
V14,
// etc.
}
Querying Consensus
use snarkvm_console::network::{MainnetV0, Network, ConsensusVersion};
type CurrentNetwork = MainnetV0;
// Get consensus version at a specific height
let version = CurrentNetwork::CONSENSUS_VERSION(1000)?;
// Get height when a version activates
let height = CurrentNetwork::CONSENSUS_HEIGHT(ConsensusVersion::V14)?;
// Get latest max array elements
let max_array = CurrentNetwork::LATEST_MAX_ARRAY_ELEMENTS();
Using Network Parameters
Example: Fee Calculation
use snarkvm_console::network::{MainnetV0, Network};
type CurrentNetwork = MainnetV0;
// Calculate deployment fee
let program_size = 50_000; // 50 kB
let deployment_fee = program_size as u64 * CurrentNetwork::DEPLOYMENT_FEE_MULTIPLIER;
println!("Deployment fee: {} microcredits", deployment_fee);
// Check transaction size limit
let tx_size = 100_000;
assert!(tx_size <= CurrentNetwork::LATEST_MAX_TRANSACTION_SIZE());
Example: Using Cryptographic Functions
use snarkvm_console::network::{MainnetV0, Network};
use snarkvm_console::types::{Field, Scalar};
type CurrentNetwork = MainnetV0;
// Hash data
let data = vec![true, false, true, true];
let hash = CurrentNetwork::hash_bhp256(&data)?;
// Commit with randomizer
let randomizer = Scalar::<CurrentNetwork>::rand(&mut rng);
let commitment = CurrentNetwork::commit_bhp512(&data, &randomizer)?;
// Poseidon hash
let fields = vec![Field::from_u64(1), Field::from_u64(2)];
let hash = CurrentNetwork::hash_psd2(&fields)?;
Example: Merkle Trees
use snarkvm_console::network::{MainnetV0, Network};
type CurrentNetwork = MainnetV0;
// Create BHP Merkle tree
let leaves = vec![
vec![true, false, true],
vec![false, true, false],
];
let tree = CurrentNetwork::merkle_tree_bhp::<3>(&leaves)?;
// Get root and proof
let root = tree.root();
let proof = tree.prove(0, &leaves[0])?;
// Verify proof
assert!(CurrentNetwork::verify_merkle_path_bhp(&proof, &root, &leaves[0]));
See Also