From 206a4b4e55c004a4347737a522d113c2ab56c38d Mon Sep 17 00:00:00 2001 From: Hamza Khalid <36852564+hmzakhalid@users.noreply.github.com> Date: Wed, 4 Sep 2024 19:42:12 +0500 Subject: [PATCH] chore(imt): Add methods to retrieve nodes and zeroes in IMT (#50) ## Description The code changes introduce two new getter methods, `nodes()` and `zeroes()`, to the IMT struct. These methods are necessary for accessing the internal structure of the IMT, particularly for cases where the intermediate tree states and padding values are required. The `nodes()` method provides access to the current state of the tree's nodes, which is useful for debugging and verifying the structure of the Merkle tree during construction. The `zeroes()` method allows retrieval of the precomputed zero nodes, which are critical for correctly padding incomplete levels when combining batch roots in parallel Merkle tree construction. ## Other Information I needed access to the zeroes without re-generating them, and the intermediate nodes are useful for debugging during parallelization. ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] My changes generate no new warnings - [x] New and existing unit tests pass locally with my changes --- crates/imt/src/imt.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/imt/src/imt.rs b/crates/imt/src/imt.rs index 8ae7d01..741c384 100644 --- a/crates/imt/src/imt.rs +++ b/crates/imt/src/imt.rs @@ -73,6 +73,14 @@ impl IMT { self.depth } + pub fn nodes(&self) -> Vec> { + self.nodes.clone() + } + + pub fn zeroes(&self) -> Vec { + self.zeroes.clone() + } + pub fn leaves(&self) -> Vec { self.nodes[0].clone() }