Skip to main content

pessimistic_proof/
nullifier_tree.rs

1use agglayer_primitives::Digest;
2use agglayer_tries::utils::empty_hash_at_height;
3pub use pessimistic_proof_core::nullifier_tree::{
4    NullifierKey, NullifierPath, NULLIFIER_TREE_DEPTH,
5};
6use serde::{Deserialize, Serialize};
7use serde_with::serde_as;
8
9/// A commitment to the set of per-network nullifier trees maintained by the
10/// local network
11#[serde_as]
12#[derive(Clone, Debug, Serialize, Deserialize)]
13pub struct NullifierTree {
14    /// The Merkle Root of the nullifier tree
15    #[serde_as(as = "_")]
16    pub root: Digest,
17}
18
19impl Default for NullifierTree {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl NullifierTree {
26    pub fn new() -> Self {
27        // We add 1 to the depth here because the empty hash at height 0 is
28        // already set to Digest::ZERO.
29        let root = empty_hash_at_height::<{ NULLIFIER_TREE_DEPTH + 1 }>();
30        NullifierTree { root }
31    }
32
33    pub fn new_with_root(root: Digest) -> Self {
34        NullifierTree { root }
35    }
36}
37
38impl From<NullifierTree> for pessimistic_proof_core::nullifier_tree::NullifierTree {
39    fn from(tree: NullifierTree) -> Self {
40        Self { root: tree.root }
41    }
42}