From 912387ace202acea52e2e204e930052b791cf2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9fano=20Bargas?= Date: Thu, 5 Sep 2024 15:14:27 -0300 Subject: [PATCH] Fix leaf_hash --- operator/mina_account/lib/src/lib.rs | 6 ++++-- operator/mina_account/lib/src/merkle_verifier.rs | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/operator/mina_account/lib/src/lib.rs b/operator/mina_account/lib/src/lib.rs index f089f1c9b..f05ce2ec3 100644 --- a/operator/mina_account/lib/src/lib.rs +++ b/operator/mina_account/lib/src/lib.rs @@ -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; @@ -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 diff --git a/operator/mina_account/lib/src/merkle_verifier.rs b/operator/mina_account/lib/src/merkle_verifier.rs index 923cd8f17..ef8c27301 100644 --- a/operator/mina_account/lib/src/merkle_verifier.rs +++ b/operator/mina_account/lib/src/merkle_verifier.rs @@ -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 @@ -23,6 +23,7 @@ pub fn verify_merkle_proof(merkle_leaf: Fp, merkle_path: Vec, merkle hash_with_kimchi(param.as_str(), &hashes) }); + println!("{}", LedgerHash::from_fp(calculated_root)); calculated_root == merkle_root } @@ -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( &[