pub fn finalize(mut self, final_entry: &TreeEntryWithProof) -> ValueHash {
        self.update(final_entry.base);

        let full_path = self
            .hasher
            .inner
            .extend_merkle_path(&final_entry.merkle_path);
        let zipped_paths = self.left_contour.into_iter().zip(full_path);
        let mut hash = self
            .hasher
            .hash_leaf(&final_entry.base.value, final_entry.base.leaf_index);
        for (depth, (left, right)) in zipped_paths.enumerate() {
            hash = if final_entry.base.key.bit(depth) {
                self.hasher.hash_branch(&left, &hash)
            } else {
                self.hasher.hash_branch(&hash, &right)
            };
        }
        hash
    }
Finalizes this digest and returns the root hash of the tree.

# Panics

Panics if the provided `final_key` is not greater than the previous key provided to this digest.
core/lib/merkle_tree/src/hasher/proofs.rs