Jelajahi Sumber

fix(target_chains/fuel): fuel merkle verification (#1620)

* fix(target_chains/fuel): fuel merkle verification

* fix pre-commit
Daniel Chew 1 tahun lalu
induk
melakukan
6695289ca9

+ 1 - 1
target_chains/fuel/contracts/pyth-contract/src/data_structures/price.sw

@@ -297,7 +297,7 @@ impl PriceFeed {
         let (_, slice) = encoded_proof.split_at(current_offset);
         let (encoded_message, _) = slice.split_at(message_size);
         current_offset += message_size;
-        let end_offset = validate_proof(encoded_proof, encoded_message, current_offset, digest);
+        let end_offset = validate_proof(encoded_proof, current_offset, digest, encoded_message);
         // Message type of 0 is a Price Feed
         require(
             encoded_message

+ 5 - 5
target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw

@@ -37,9 +37,9 @@ fn node_hash(child_a: Bytes, child_b: Bytes) -> Bytes {
 
 pub fn validate_proof(
     encoded_proof: Bytes,
-    leaf_data: Bytes,
     ref mut proof_offset: u64,
     root: Bytes,
+    leaf_data: Bytes,
 ) -> u64 {
     let mut current_digest = leaf_hash(leaf_data);
 
@@ -51,14 +51,14 @@ pub fn validate_proof(
         let (_, slice) = encoded_proof.split_at(proof_offset);
         let (sibling_digest, _) = slice.split_at(20);
         proof_offset += 20;
-
         current_digest = node_hash(current_digest, sibling_digest);
-
         i += 1;
     }
 
-    // TODO: investigate failing require statement on the accumulator update path.
-    // require(current_digest == root, PythError::InvalidProof);
+    let current_digest_b256: b256 = current_digest.into();
+    let root_b256: b256 = root.into();
+
+    require(current_digest_b256 == root_b256, PythError::InvalidProof);
 
     proof_offset
 }