From e47b65cc4f4649710f9466b5702d8e74e2852527 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 28 May 2024 15:34:28 +0900 Subject: [PATCH 1/2] fix(target_chains/fuel): fuel merkle verification --- .../pyth-contract/src/data_structures/price.sw | 2 +- .../contracts/pyth-contract/src/pyth_merkle_proof.sw | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/target_chains/fuel/contracts/pyth-contract/src/data_structures/price.sw b/target_chains/fuel/contracts/pyth-contract/src/data_structures/price.sw index f60894874e..df3cd9fde3 100644 --- a/target_chains/fuel/contracts/pyth-contract/src/data_structures/price.sw +++ b/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 diff --git a/target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw b/target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw index 0f1e0f0a26..1a7170be26 100644 --- a/target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw +++ b/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 } From 56c1207882927cecff47afd358bd429644fec3b2 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 28 May 2024 15:36:53 +0900 Subject: [PATCH 2/2] fix pre-commit --- .../fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw b/target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw index 1a7170be26..d73c7805a4 100644 --- a/target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw +++ b/target_chains/fuel/contracts/pyth-contract/src/pyth_merkle_proof.sw @@ -57,7 +57,7 @@ pub fn validate_proof( let current_digest_b256: b256 = current_digest.into(); let root_b256: b256 = root.into(); - + require(current_digest_b256 == root_b256, PythError::InvalidProof); proof_offset