Skip to content

Commit

Permalink
fix: safely insert sibling paths (#10423)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasRidhuan authored Dec 5, 2024
1 parent ed972f3 commit 41f7645
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion yarn-project/simulator/src/avm/avm_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,12 @@ export class EphemeralAvmTree {
for (let i = 0; i < siblingPath.length; i++) {
// Flip(XOR) the last bit because we are inserting siblings of the leaf
const sibIndex = index ^ 1n;
this.updateLeaf(siblingPath[i], sibIndex, this.depth - i);
const node = this.getNode(sibIndex, this.depth - i);
// If we are inserting a sibling path and we already have a branch at that index in our
// ephemeral tree, we should not overwrite it
if (node === undefined || node.tag === TreeType.LEAF) {
this.updateLeaf(siblingPath[i], sibIndex, this.depth - i);
}
index >>= 1n;
}
}
Expand Down

0 comments on commit 41f7645

Please sign in to comment.