Skip to content

Commit 9e8eac3

Browse files
committed
fix: merkle tree construction
1 parent fbc0b96 commit 9e8eac3

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

aggregation_mode/aggregation_programs/risc0/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ impl IsMerkleTreeBackend for Risc0ImageIdAndPubInputs {
4242

4343
fn hash_new_parent(child_1: &Self::Node, child_2: &Self::Node) -> Self::Node {
4444
let mut hasher = Keccak::v256();
45-
hasher.update(child_1);
46-
hasher.update(child_2);
47-
45+
if child_1 < child_2 {
46+
hasher.update(child_1);
47+
hasher.update(child_2);
48+
} else {
49+
hasher.update(child_2);
50+
hasher.update(child_1);
51+
}
4852
let mut hash = [0u8; 32];
4953
hasher.finalize(&mut hash);
5054
hash

aggregation_mode/aggregation_programs/sp1/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ impl IsMerkleTreeBackend for SP1VkAndPubInputs {
3939

4040
fn hash_new_parent(child_1: &Self::Node, child_2: &Self::Node) -> Self::Node {
4141
let mut hasher = Keccak256::new();
42-
hasher.update(child_1);
43-
hasher.update(child_2);
42+
if child_1 < child_2 {
43+
hasher.update(child_1);
44+
hasher.update(child_2);
45+
} else {
46+
hasher.update(child_2);
47+
hasher.update(child_1);
48+
}
4449
hasher.finalize().into()
4550
}
4651
}

aggregation_mode/src/aggregators/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,13 @@ impl IsMerkleTreeBackend for AlignedProof {
152152

153153
fn hash_new_parent(child_1: &Self::Node, child_2: &Self::Node) -> Self::Node {
154154
let mut hasher = Keccak256::new();
155-
hasher.update(child_1);
156-
hasher.update(child_2);
155+
if child_1 < child_2 {
156+
hasher.update(child_1);
157+
hasher.update(child_2);
158+
} else {
159+
hasher.update(child_2);
160+
hasher.update(child_1);
161+
}
157162
hasher.finalize().into()
158163
}
159164
}

batcher/aligned-sdk/src/sdk/aggregation.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ impl IsMerkleTreeBackend for Hash32 {
7272

7373
fn hash_new_parent(child_1: &Self::Node, child_2: &Self::Node) -> Self::Node {
7474
let mut hasher = Keccak256::new();
75-
hasher.update(child_1);
76-
hasher.update(child_2);
75+
if child_1 < child_2 {
76+
hasher.update(child_1);
77+
hasher.update(child_2);
78+
} else {
79+
hasher.update(child_2);
80+
hasher.update(child_1);
81+
}
7782
hasher.finalize().into()
7883
}
7984
}

0 commit comments

Comments
 (0)