snarkvm_console_program/state_path/configuration/mod.rs
1// Copyright (c) 2019-2026 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.
24/// A transaction can include at most `2^FINALIZE_ID_DEPTH` finalize operations total (across *all* transitions).
25/// Note that `MAX_WRITES * MAX_TRANSITIONS` can exceed that Merkle-tree capacity.
26pub const FINALIZE_ID_DEPTH: u8 = TRANSACTION_DEPTH + 4; // '+ 4' is to support an average of 16 finalize operations per transition.
27/// The depth of the Merkle tree for finalize operations in a block.
28pub const FINALIZE_OPERATIONS_DEPTH: u8 = TRANSACTIONS_DEPTH;
29/// The depth of the Merkle tree for the ratifications in a block.
30pub const RATIFICATIONS_DEPTH: u8 = 16;
31/// The depth the Merkle tree for the subdag certificates in a block.
32pub const SUBDAG_CERTIFICATES_DEPTH: u8 = 16;
33/// The depth of the Merkle tree for transactions in a block.
34/// Note: The technical limit is 2^20 - 1 transactions, to allow compatibility with the
35/// finalize operations tree, which requires 1 leaf for the ratified finalize ID.
36pub const TRANSACTIONS_DEPTH: u8 = 20;
37/// The depth of the Merkle tree for the transaction.
38pub const TRANSACTION_DEPTH: u8 = 5;
39/// The depth of the Merkle tree for the transition.
40pub const TRANSITION_DEPTH: u8 = 5;
41
42/// The Merkle tree for the block state.
43pub type BlockTree<N> = BHPMerkleTree<N, BLOCKS_DEPTH>;
44/// The Merkle path for the state tree blocks.
45pub type BlockPath<N> = MerklePath<N, BLOCKS_DEPTH>;
46
47/// The Merkle tree for the block header.
48pub type HeaderTree<N> = BHPMerkleTree<N, HEADER_DEPTH>;
49/// The Merkle path for the block header.
50pub type HeaderPath<N> = MerklePath<N, HEADER_DEPTH>;
51
52/// The Merkle tree for ratifications in a block.
53pub type RatificationsTree<N> = BHPMerkleTree<N, RATIFICATIONS_DEPTH>;
54/// The Merkle path for a ratification in a block.
55pub type RatificationsPath<N> = MerklePath<N, RATIFICATIONS_DEPTH>;
56
57/// The Merkle tree for transactions in a block.
58pub type TransactionsTree<N> = BHPMerkleTree<N, TRANSACTIONS_DEPTH>;
59/// The Merkle path for a transaction in a block.
60pub type TransactionsPath<N> = MerklePath<N, TRANSACTIONS_DEPTH>;
61
62/// The Merkle tree for the transaction.
63pub type TransactionTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
64/// The Merkle path for a function or transition in the transaction.
65pub type TransactionPath<N> = MerklePath<N, TRANSACTION_DEPTH>;
66
67/// The Merkle tree for the execution.
68pub type ExecutionTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
69/// The Merkle tree for the deployment.
70pub type DeploymentTree<N> = BHPMerkleTree<N, TRANSACTION_DEPTH>;
71
72/// The Merkle tree for the transition.
73pub type TransitionTree<N> = BHPMerkleTree<N, TRANSITION_DEPTH>;
74/// The Merkle path for an input or output ID in the transition.
75pub type TransitionPath<N> = MerklePath<N, TRANSITION_DEPTH>;
76
77#[cfg(test)]
78mod tests {
79 use super::*;
80 use snarkvm_console_network::Network;
81
82 type CurrentNetwork = snarkvm_console_network::MainnetV0;
83
84 #[test]
85 fn test_transaction_depth_is_correct() {
86 // We ensure 2^TRANSACTION_DEPTH - 1 == MAX_FUNCTIONS.
87 // The "- 1" is for the fee transition.
88 assert_eq!((2u32.checked_pow(TRANSACTION_DEPTH as u32).unwrap() - 1) as usize, CurrentNetwork::MAX_FUNCTIONS);
89 }
90
91 #[test]
92 fn test_transition_depth_is_correct() {
93 // We ensure 2^TRANSITION_DEPTH == (MAX_INPUTS + MAX_OUTPUTS).
94 assert_eq!(
95 2u32.checked_pow(TRANSITION_DEPTH as u32).unwrap() as usize,
96 CurrentNetwork::MAX_INPUTS + CurrentNetwork::MAX_OUTPUTS
97 );
98 }
99}