Browse Source

add changes

Ali Behjati 1 year ago
parent
commit
4ff004a9c6

+ 1 - 1
target_chains/fuel/contracts/Cargo.lock

@@ -2995,7 +2995,7 @@ dependencies = [
 
 [[package]]
 name = "pythnet-sdk"
-version = "2.0.0"
+version = "2.1.0"
 dependencies = [
  "bincode",
  "borsh",

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

@@ -1,11 +1,26 @@
 library;
 
-use std::{bytes::Bytes, hash::{Hash, keccak256}};
+use std::{hash::{Hash, keccak256}};
+use std::{array_conversions::u32::*, bytes::Bytes};
 use ::errors::PythError;
 
 pub const MERKLE_LEAF_PREFIX = 0u8;
 pub const MERKLE_NODE_PREFIX = 1u8;
 
+const ACCUMULATOR_MAGIC: u32 = 0x12345678;
+
+pub fn accumulator_magic_bytes() -> Bytes {
+    let accumulator_magic_array = ACCUMULATOR_MAGIC.to_be_bytes();
+
+    let mut accumulator_magic_bytes = Bytes::with_capacity(4);
+    accumulator_magic_bytes.push(accumulator_magic_array[0]);
+    accumulator_magic_bytes.push(accumulator_magic_array[1]);
+    accumulator_magic_bytes.push(accumulator_magic_array[2]);
+    accumulator_magic_bytes.push(accumulator_magic_array[3]);
+
+    accumulator_magic_bytes
+}
+
 fn leaf_hash(data: Bytes) -> Bytes {
     let mut bytes = Bytes::new();
     bytes.push(MERKLE_LEAF_PREFIX);
@@ -41,6 +56,9 @@ pub fn validate_proof(
     ref mut proof_offset: u64,
     root: Bytes,
 ) -> u64 {
+    let test_bytes = accumulator_magic_bytes();
+    log(test_bytes);
+
     let mut current_digest = leaf_hash(leaf_data);
 
     let proof_size = encoded_proof.get(proof_offset).unwrap().as_u64();
@@ -58,7 +76,7 @@ pub fn validate_proof(
     }
 
     // TODO: investigate failing require statement on the accumulator update path.
-    // require(current_digest == root, PythError::InvalidProof);
+    require(current_digest == root, PythError::InvalidProof);
 
     proof_offset
 }

+ 25 - 0
target_chains/fuel/contracts/tests/utils/interface/pyth_core.rs

@@ -1,7 +1,10 @@
+use std::{net::AddrParseError, sync::Arc};
+
 use fuels::{
     accounts::wallet::WalletUnlocked,
     prelude::{Bytes, CallParameters, TxPolicies},
     programs::call_response::FuelCallResponse,
+    types::errors::Error,
     types::Bits256,
 };
 
@@ -129,6 +132,28 @@ pub(crate) async fn update_price_feeds(
         .unwrap()
         .call()
         .await
+        .map_err(|e| {
+            if let Error::RevertTransactionError {
+                reason: _,
+                revert_id: _,
+                ref receipts,
+            } = e
+            {
+                for r in receipts {
+                    match r {
+                        fuels::tx::Receipt::Log { ra, .. } => {
+                            println!("{:?}", ra);
+                        }
+                        fuels::tx::Receipt::LogData { data, .. } => {
+                            println!("{:?}", hex::encode(data.clone().unwrap()));
+                        }
+                        _ => {}
+                    }
+                }
+            }
+
+            e
+        })
         .unwrap()
 }