mirror of https://github.com/zcash/halo2.git
tree.rs: MerklePath.root(): Fix missing bitmask in swap calculation
Co-authored-by: Jack Grigg <jack@electriccoin.co>
This commit is contained in:
parent
18535894d6
commit
e8e22886f4
13
src/tree.rs
13
src/tree.rs
|
@ -39,17 +39,12 @@ impl MerklePath {
|
|||
}
|
||||
|
||||
pub fn root(&self, cmx: ExtractedNoteCommitment) -> Anchor {
|
||||
// Initialize `node` to the first hash.
|
||||
let init_node = {
|
||||
let pos = self.position % 2 == 1;
|
||||
hash_layer(0, cond_swap(pos, *cmx, self.auth_path[0]))
|
||||
};
|
||||
let node = self.auth_path[1..]
|
||||
let node = self
|
||||
.auth_path
|
||||
.iter()
|
||||
.enumerate()
|
||||
.fold(init_node, |node, (i, sibling)| {
|
||||
let l_star = i + 1;
|
||||
let swap = (self.position >> l_star) == 1;
|
||||
.fold(*cmx, |node, (l_star, sibling)| {
|
||||
let swap = self.position & (1 << l_star) != 0;
|
||||
hash_layer(l_star, cond_swap(swap, node, *sibling))
|
||||
});
|
||||
Anchor(node.to_bytes())
|
||||
|
|
Loading…
Reference in New Issue