Skip to content

Commit

Permalink
Double-hash leaves in beefy-merkle-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
doubledup committed Jan 9, 2023
1 parent c778099 commit f788f5e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions frame/beefy-mmr/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
let iter = leaves.into_iter().map(|l| <H as HashT>::hash(l.as_ref()));
let iter = leaves.into_iter().map(|l| <H as HashT>::hash(<H as HashT>::hash(l.as_ref()).as_ref()));
merkelize::<H, _, _>(iter, &mut ()).into()
}

Expand Down Expand Up @@ -149,7 +149,7 @@ where
{
let mut leaf = None;
let iter = leaves.into_iter().enumerate().map(|(idx, l)| {
let hash = <H as HashT>::hash(l.as_ref());
let hash = <H as HashT>::hash(<H as HashT>::hash(l.as_ref()).as_ref());
if idx == leaf_index {
leaf = Some(l);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ where
}

let leaf_hash = match leaf.into() {
Leaf::Value(content) => <H as HashT>::hash(content),
Leaf::Value(content) => <H as HashT>::hash(<H as HashT>::hash(content).as_ref()),
Leaf::Hash(hash) => hash,
};

Expand Down Expand Up @@ -396,7 +396,7 @@ mod tests {
// then
assert_eq!(
array_bytes::bytes2hex("", out.as_ref()),
"aeb47a269393297f4b0a3c9c9cfd00c7a4195255274cf39d83dabc2fcc9ff3d7"
"3c137409c513c2a370698ff7e042154c00ce1d1a2f98dc630366637a798bbb76"
);
}

Expand All @@ -415,7 +415,7 @@ mod tests {
// then
assert_eq!(
array_bytes::bytes2hex("", out.as_ref()),
"697ea2a8fe5b03468548a7a413424a6292ab44a82a6f5cc594c3fa7dda7ce402"
"4f54979717a78e07c0730c45f96ce77a3d9f4d55ab3bcdbbd8d8daf58932daa8"
);
}

Expand All @@ -430,22 +430,22 @@ mod tests {
};

test(
"5842148bc6ebeb52af882a317c765fccd3ae80589b21a9b8cbf21abb630e46a7",
"ec5728bad90d3185989eddaae1e83be5f3e03ad9f48bd743df58dad4b7625505",
vec!["a", "b", "c"],
);

test(
"7b84bec68b13c39798c6c50e9e40a0b268e3c1634db8f4cb97314eb243d4c514",
"9e0a460a09c8bec16bd24a3a88e7c4a0c63a1a0e83146d0b1c261b5197095bfc",
vec!["a", "b", "a"],
);

test(
"dc8e73fe6903148ff5079baecc043983625c23b39f31537e322cd0deee09fa9c",
"0eddd6bcda73a09e07b81108e219f13ed34ab0a9bee6f9477dc99b0e0f760e07",
vec!["a", "b", "a", "b"],
);

test(
"cc50382cfd3c9a617741e9a85efee8752b8feb95a2cbecd6365fb21366ce0c8c",
"65db6ad4efda46af046d7ecfe41dc4f29012e2968cbdac705e07b7fb1e14bd12",
vec!["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
);
}
Expand Down Expand Up @@ -763,7 +763,7 @@ mod tests {
"0xc26B34D375533fFc4c5276282Fa5D660F3d8cbcB",
];
let root: H256 = array_bytes::hex2array_unchecked(
"7b2c6eebec6e85b2e272325a11c31af71df52bc0534d2d4f903e0ced191f022e",
"9ecb057963d989c798e96adbc3279e639d26fed5e2d85d36222d4902ca38dceb",
)
.into();

Expand Down Expand Up @@ -800,19 +800,19 @@ mod tests {
root,
proof: vec![
array_bytes::hex2array_unchecked(
"340bcb1d49b2d82802ddbcf5b85043edb3427b65d09d7f758fbc76932ad2da2f"
"4b30a34ddaf2c978393cfaaff86b63a70dd528a1206720a72cc4f1e7c4b868ba"
)
.into(),
array_bytes::hex2array_unchecked(
"ba0580e5bd530bc93d61276df7969fb5b4ae8f1864b4a28c280249575198ff1f"
"841ab2af60ad43be1d28693431012681cba4ac997900d67c7cb228da59a9a91a"
)
.into(),
array_bytes::hex2array_unchecked(
"1fad92ed8d0504ef6c0231bbbeeda960a40693f297c64e87b582beb92ecfb00f"
"b1316e36d2b5bda678ad074255653bcc29b68273dc4d0693c922533fd71fe09d"
)
.into(),
array_bytes::hex2array_unchecked(
"0b84c852cbcf839d562d826fd935e1b37975ccaa419e1def8d219df4b83dcbf4"
"8e5deae2101af5e99a1e1e447e66afa51a0a71605b4112897962b5e66720e648"
)
.into(),
],
Expand Down

0 comments on commit f788f5e

Please sign in to comment.