Skip to content

Commit

Permalink
Fix leaf_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
xqft committed Sep 13, 2024
1 parent 17ba105 commit 912387a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions operator/mina_account/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use merkle_verifier::verify_merkle_proof;
use mina_bridge_core::proof::account_proof::{MinaAccountProof, MinaAccountPubInputs};
use mina_p2p_messages::hash::MinaHash;
use mina_tree::Account;

mod merkle_verifier;

Expand Down Expand Up @@ -34,7 +34,9 @@ pub extern "C" fn verify_account_inclusion_ffi(
}
};

let leaf_hash = account.hash();
// the hash function for MinaBaseAccountBinableArgStableV2 produces a panic every
// time it's called. So we use Account's one.
let leaf_hash = Account::from(&account).hash();

// TODO(xqft): when the needed account GraphQL query is done, do:
// 1. send encoded account as part of the proof
Expand Down
7 changes: 4 additions & 3 deletions operator/mina_account/lib/src/merkle_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use mina_bridge_core::proof::account_proof::MerkleNode;
use mina_curves::pasta::Fp;
use mina_p2p_messages::v2::hash_with_kimchi;
use mina_p2p_messages::v2::{hash_with_kimchi, LedgerHash};
use std::fmt::Write;

/// Based on OpenMina's implementation
Expand All @@ -23,6 +23,7 @@ pub fn verify_merkle_proof(merkle_leaf: Fp, merkle_path: Vec<MerkleNode>, merkle

hash_with_kimchi(param.as_str(), &hashes)
});
println!("{}", LedgerHash::from_fp(calculated_root));
calculated_root == merkle_root
}

Expand All @@ -36,8 +37,8 @@ mod test {
fn test_verify_merkle_proof() {
let merkle_leaf = Fp::from(0);
let merkle_path = vec![
MerklePath::Left(Fp::from(0)),
MerklePath::Right(Fp::from(0)),
MerkleNode::Left(Fp::from(0)),
MerkleNode::Right(Fp::from(0)),
];
let merkle_root = Fp::deserialize(
&[
Expand Down

0 comments on commit 912387a

Please sign in to comment.