Skip to content

Commit 99904e0

Browse files
committed
Check result of computing Merkle Root of Mina Account
1 parent 458a55e commit 99904e0

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

batcher/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/mina_account/lib/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/mina_account/lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sha3 = "0.10.8"
3030
mina_bridge_core = { git = "https://github.com/lambdaclass/mina_bridge", rev = "884f28b834b62133384661fdf73c9db283f68c62" }
3131
bincode = "1.3.3"
3232
alloy = { version = "0.3.3", features = ["full"] }
33+
log = "0.4.21"
3334

3435
[patch.crates-io]
3536
ark-ff = { git = "https://github.com/lambdaclass/openmina_algebra", branch = "mina_bridge" }

operator/mina_account/lib/src/merkle_verifier.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use log::error;
12
use mina_bridge_core::proof::account_proof::MerkleNode;
23
use mina_curves::pasta::Fp;
34
use mina_p2p_messages::v2::hash_with_kimchi;
@@ -8,21 +9,28 @@ use std::fmt::Write;
89
pub fn verify_merkle_proof(merkle_leaf: Fp, merkle_path: Vec<MerkleNode>, merkle_root: Fp) -> bool {
910
let mut param = String::with_capacity(16);
1011

11-
let calculated_root =
12+
let Ok(calculated_root): Result<Fp, ()> =
1213
merkle_path
1314
.iter()
1415
.enumerate()
15-
.fold(merkle_leaf, |accum, (depth, path)| {
16+
.try_fold(merkle_leaf, |accum, (depth, path)| {
1617
let hashes = match path {
1718
MerkleNode::Left(right) => [accum, *right],
1819
MerkleNode::Right(left) => [*left, accum],
1920
};
2021

2122
param.clear();
22-
write!(&mut param, "MinaMklTree{:03}", depth).unwrap();
23+
write!(&mut param, "MinaMklTree{:03}", depth).map_err(|_| {
24+
error!("Failed to write depth parameter for hashing");
25+
})?;
2326

24-
hash_with_kimchi(param.as_str(), &hashes)
25-
});
27+
let root = hash_with_kimchi(param.as_str(), &hashes);
28+
29+
Ok(root)
30+
})
31+
else {
32+
return false;
33+
};
2634
calculated_root == merkle_root
2735
}
2836

0 commit comments

Comments
 (0)