snarkvm_console_program/state_path/configuration/mod.rs
1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use snarkvm_console_collections::merkle_tree::MerklePath;
17use snarkvm_console_network::BHPMerkleTree;
18
19/// The depth of the Merkle tree for the blocks.
20pub const BLOCKS_DEPTH: u8 = 32;
21/// The depth of the Merkle tree for the block header.
22pub const HEADER_DEPTH: u8 = 3;
23/// The depth of the Merkle tree for finalize operations in a transaction.
24pub const FINALIZE_ID_DEPTH: u8 = TRANSACTION_DEPTH + 4; // '+ 4' is to support 16 finalize operations per transition.
25/// The depth of the Merkle tree for finalize operations in a block.
26pub const FINALIZE_OPERATIONS_DEPTH: u8 = TRANSACTIONS_DEPTH;
27/// The depth of the Merkle tree for the ratifications in a block.
28pub const RATIFICATIONS_DEPTH: u8 = 16;
29/// The depth the Merkle tree for the subdag certificates in a block.
30pub const SUBDAG_CERTIFICATES_DEPTH: u8 = 16;
31/// The depth of the Merkle tree for transactions in a block.
32/// Note: The technical limit is 2^20 - 1 transactions, to allow compatibility with the
33/// finalize operations tree, which requires 1 leaf for the ratified finalize ID.
34pub const TRANSACTIONS_DEPTH: u8 = 20;
35/// The depth of the Merkle tree for the transaction.
36pub const TRANSACTION_DEPTH: u8 = 5;
37/// The depth of the Merkle tree for the transition.
38pub const TRANSITION_DEPTH: u8 = 5;
39
40/// The Merkle tree for the block state.
41pub type BlockTree<N> = BHPMerkleTree<N, BLOCKS_DEPTH>;
42/// The Merkle path for the state tree blocks.
43pub type BlockPath<N> = MerklePath<N, BLOCKS_DEPTH>;
44
45/// The Merkle tree for the block header.
46pub type HeaderTree<N> = BHPMerkleTree<N, HEADER_DEPTH>;
47/// The Merkle path for the block header.
48pub type HeaderPath<N> = MerklePath<N, HEADER_DEPTH>;
49
50/// The Merkle tree for ratifications in a block.
51pub type RatificationsTree<N> = BHPMerkleTree<N, RATIFICATIONS_DEPTH>;
52/// The Merkle path for a ratification in a block.
53pub type RatificationsPath<N> = MerklePath<N, RATIFICATIONS_DEPTH>;
54
55/// The Merkle tree for transactions in a block.
56pub type TransactionsTree<N> = BHPMerkleTree<N, TRANSACTIONS_DEPTH>;
57/// The Merkle path for a transaction in a block.
58pub type TransactionsPath<N> = MerklePath<N, TRANSACTIONS_DEPTH>;
59
60/// The Merkle tree for the execution.
61pub type ExecutionTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
62/// The Merkle tree for the deployment.
63pub type DeploymentTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
64/// The Merkle tree for the transaction.
65pub type TransactionTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
66/// The Merkle path for a function or transition in the transaction.
67pub type TransactionPath<N> = MerklePath<N, TRANSACTION_DEPTH>;
68
69/// The Merkle tree for the transition.
70pub type TransitionTree<N> = BHPMerkleTree<N, TRANSITION_DEPTH>;
71/// The Merkle path for an input or output ID in the transition.
72pub type TransitionPath<N> = MerklePath<N, TRANSITION_DEPTH>;
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77 use snarkvm_console_network::Network;
78
79 type CurrentNetwork = snarkvm_console_network::MainnetV0;
80
81 #[test]
82 fn test_transaction_depth_is_correct() {
83 // We ensure 2^TRANSACTION_DEPTH - 1 == MAX_FUNCTIONS.
84 // The "- 1" is for the fee transition.
85 assert_eq!((2u32.checked_pow(TRANSACTION_DEPTH as u32).unwrap() - 1) as usize, CurrentNetwork::MAX_FUNCTIONS);
86 }
87
88 #[test]
89 fn test_transition_depth_is_correct() {
90 // We ensure 2^TRANSITION_DEPTH == (MAX_INPUTS + MAX_OUTPUTS).
91 assert_eq!(
92 2u32.checked_pow(TRANSITION_DEPTH as u32).unwrap() as usize,
93 CurrentNetwork::MAX_INPUTS + CurrentNetwork::MAX_OUTPUTS
94 );
95 }
96}