From d5918ebef4f83cdc5d2b3358a39d606141225569 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 23 Sep 2025 10:10:47 +0200 Subject: [PATCH 1/5] enable ipfs ocall test but only write and forget --- enclave-runtime/src/test/ipfs_tests.rs | 22 +++++++++++----------- enclave-runtime/src/test/tests_main.rs | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/enclave-runtime/src/test/ipfs_tests.rs b/enclave-runtime/src/test/ipfs_tests.rs index f1f94d3696..fb10612ccd 100644 --- a/enclave-runtime/src/test/ipfs_tests.rs +++ b/enclave-runtime/src/test/ipfs_tests.rs @@ -28,15 +28,15 @@ fn test_ocall_read_write_ipfs() { let cid = OcallApi.write_ipfs(enc_state.as_slice()).unwrap(); - OcallApi.read_ipfs(&cid).unwrap(); - - let cid_str = std::str::from_utf8(&cid.0).unwrap(); - let mut f = File::open(cid_str).unwrap(); - let mut content_buf = Vec::new(); - f.read_to_end(&mut content_buf).unwrap(); - info!("reading file {:?} of size {} bytes", f, &content_buf.len()); - - let mut ipfs_content = IpfsContent::new(cid_str, content_buf); - let verification = ipfs_content.verify(); - assert!(verification.is_ok()); + // OcallApi.read_ipfs(&cid).unwrap(); + // + // let cid_str = std::str::from_utf8(&cid.0).unwrap(); + // let mut f = File::open(cid_str).unwrap(); + // let mut content_buf = Vec::new(); + // f.read_to_end(&mut content_buf).unwrap(); + // info!("reading file {:?} of size {} bytes", f, &content_buf.len()); + // + // let mut ipfs_content = IpfsContent::new(cid_str, content_buf); + // let verification = ipfs_content.verify(); + // assert!(verification.is_ok()); } diff --git a/enclave-runtime/src/test/tests_main.rs b/enclave-runtime/src/test/tests_main.rs index 8f8881176b..aea834c23c 100644 --- a/enclave-runtime/src/test/tests_main.rs +++ b/enclave-runtime/src/test/tests_main.rs @@ -166,7 +166,7 @@ pub extern "C" fn test_main_entrance() -> size_t { // ipfs::test_creates_ipfs_content_struct_works, // ipfs::test_verification_ok_for_correct_content, // ipfs::test_verification_fails_for_incorrect_content, - // test_ocall_read_write_ipfs, + test_ocall_read_write_ipfs, // Teeracle tests run_teeracle_tests, @@ -429,7 +429,8 @@ fn test_create_state_diff() { assert_eq!( sender_acc_info.data.free, ita_stf::test_genesis::ENDOWED_ACC_FUNDS - - TX_AMOUNT - 1_000_000_000_000 / ita_stf::STF_TX_FEE_UNIT_DIVIDER + - TX_AMOUNT + - 1_000_000_000_000 / ita_stf::STF_TX_FEE_UNIT_DIVIDER ); } From cb82c12cde26bfe1b692afd11f24d28791e6506d Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 23 Sep 2025 10:44:24 +0200 Subject: [PATCH 2/5] fixes --- enclave-runtime/src/test/ipfs_tests.rs | 4 ++-- enclave-runtime/src/test/tests_main.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/enclave-runtime/src/test/ipfs_tests.rs b/enclave-runtime/src/test/ipfs_tests.rs index fb10612ccd..fb730dcd81 100644 --- a/enclave-runtime/src/test/ipfs_tests.rs +++ b/enclave-runtime/src/test/ipfs_tests.rs @@ -22,9 +22,9 @@ use log::*; use std::{fs::File, io::Read, vec::Vec}; #[allow(unused)] -fn test_ocall_read_write_ipfs() { +pub fn test_ocall_read_write_ipfs() { info!("testing IPFS read/write. Hopefully ipfs daemon is running..."); - let enc_state: Vec = vec![20; 4 * 512 * 1024]; + let enc_state: Vec = vec![20; 10]; let cid = OcallApi.write_ipfs(enc_state.as_slice()).unwrap(); diff --git a/enclave-runtime/src/test/tests_main.rs b/enclave-runtime/src/test/tests_main.rs index aea834c23c..8c54e4895c 100644 --- a/enclave-runtime/src/test/tests_main.rs +++ b/enclave-runtime/src/test/tests_main.rs @@ -25,6 +25,7 @@ use crate::{ fixtures::test_setup::{ enclave_call_signer, test_setup, TestStf, TestStfExecutor, TestTopPoolAuthor, }, + ipfs_tests, mocks::types::TestStateKeyRepo, sidechain_aura_tests, sidechain_event_tests, state_getter_tests, top_pool_tests, }, @@ -166,7 +167,7 @@ pub extern "C" fn test_main_entrance() -> size_t { // ipfs::test_creates_ipfs_content_struct_works, // ipfs::test_verification_ok_for_correct_content, // ipfs::test_verification_fails_for_incorrect_content, - test_ocall_read_write_ipfs, + ipfs_tests::test_ocall_read_write_ipfs, // Teeracle tests run_teeracle_tests, From 1247e765eb65fdbfd6036cd5ed504bbdf1247b79 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 23 Sep 2025 11:07:07 +0200 Subject: [PATCH 3/5] return ocall early if failing to add --- service/src/ocall_bridge/ipfs_ocall.rs | 127 +++++++++++++------------ 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/service/src/ocall_bridge/ipfs_ocall.rs b/service/src/ocall_bridge/ipfs_ocall.rs index 8cc25f85d7..662c41a8d1 100644 --- a/service/src/ocall_bridge/ipfs_ocall.rs +++ b/service/src/ocall_bridge/ipfs_ocall.rs @@ -21,82 +21,85 @@ use futures::TryStreamExt; use ipfs_api::IpfsClient; use log::*; use std::{ - fs::File, - io::{Cursor, Write}, - str, - sync::mpsc::channel, + fs::File, + io::{Cursor, Write}, + str, + sync::mpsc::channel, }; pub struct IpfsOCall; impl IpfsBridge for IpfsOCall { - fn write_to_ipfs(&self, data: &'static [u8]) -> OCallBridgeResult { - debug!(" Entering ocall_write_ipfs"); - Ok(write_to_ipfs(data)) - } - - fn read_from_ipfs(&self, cid: Cid) -> OCallBridgeResult<()> { - debug!("Entering ocall_read_ipfs"); - - let result = read_from_ipfs(cid); - match result { - Ok(res) => { - let filename = str::from_utf8(&cid).unwrap(); - create_file(filename, &res).map_err(OCallBridgeError::IpfsError) - }, - Err(_) => Err(OCallBridgeError::IpfsError("failed to read from IPFS".to_string())), - } - } + fn write_to_ipfs(&self, data: &'static [u8]) -> OCallBridgeResult { + debug!(" Entering ocall_write_ipfs"); + Ok(write_to_ipfs(data)) + } + + fn read_from_ipfs(&self, cid: Cid) -> OCallBridgeResult<()> { + debug!("Entering ocall_read_ipfs"); + + let result = read_from_ipfs(cid); + match result { + Ok(res) => { + let filename = str::from_utf8(&cid).unwrap(); + create_file(filename, &res).map_err(OCallBridgeError::IpfsError) + } + Err(_) => Err(OCallBridgeError::IpfsError("failed to read from IPFS".to_string())), + } + } } fn create_file(filename: &str, result: &[u8]) -> Result<(), String> { - match File::create(filename) { - Ok(mut f) => f - .write_all(result) - .map_or_else(|e| Err(format!("failed writing to file: {}", e)), |_| Ok(())), - Err(e) => Err(format!("failed to create file: {}", e)), - } + match File::create(filename) { + Ok(mut f) => f + .write_all(result) + .map_or_else(|e| Err(format!("failed writing to file: {}", e)), |_| Ok(())), + Err(e) => Err(format!("failed to create file: {}", e)), + } } #[tokio::main] async fn write_to_ipfs(data: &'static [u8]) -> Cid { - // Creates an `IpfsClient` connected to the endpoint specified in ~/.ipfs/api. - // If not found, tries to connect to `localhost:5001`. - let client = IpfsClient::default(); - - match client.version().await { - Ok(version) => info!("version: {:?}", version.version), - Err(e) => eprintln!("error getting version: {}", e), - } - - let datac = Cursor::new(data); - let (tx, rx) = channel(); - - match client.add(datac).await { - Ok(res) => { - info!("Result Hash {}", res.hash); - tx.send(res.hash.into_bytes()).unwrap(); - }, - Err(e) => eprintln!("error adding file: {}", e), - } - let mut cid: Cid = [0; 46]; - cid.clone_from_slice(&rx.recv().unwrap()); - cid + // Creates an `IpfsClient` connected to the endpoint specified in ~/.ipfs/api. + // If not found, tries to connect to `localhost:5001`. + let client = IpfsClient::default(); + + match client.version().await { + Ok(version) => info!("version: {:?}", version.version), + Err(e) => eprintln!("error getting version: {}", e), + } + + let datac = Cursor::new(data); + let (tx, rx) = channel(); + + match client.add(datac).await { + Ok(res) => { + info!("Result Hash {}", res.hash); + tx.send(res.hash.into_bytes()).unwrap(); + } + Err(e) => { + eprintln!("error adding file: {}", e); + return [0; 46]; + } + } + let mut cid: Cid = [0; 46]; + cid.clone_from_slice(&rx.recv().unwrap()); + cid } #[tokio::main] pub async fn read_from_ipfs(cid: Cid) -> Result, String> { - // Creates an `IpfsClient` connected to the endpoint specified in ~/.ipfs/api. - // If not found, tries to connect to `localhost:5001`. - let client = IpfsClient::default(); - let h = str::from_utf8(&cid).unwrap(); - - info!("Fetching content from: {}", h); - - client - .cat(h) - .map_ok(|chunk| chunk.to_vec()) - .map_err(|e| e.to_string()) - .try_concat() - .await + // Creates an `IpfsClient` connected to the endpoint specified in ~/.ipfs/api. + // If not found, tries to connect to `localhost:5001`. + let client = IpfsClient::default(); + let h = str::from_utf8(&cid).unwrap(); + + info!("Fetching content from: {}", h); + + client + .cat(h) + .map_ok(|chunk| chunk.to_vec()) + .map_err(|e| e.to_string()) + .try_concat() + .await } From 2d00405de31e58b6bc9e64312be29692517cba56 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 23 Sep 2025 13:01:33 +0200 Subject: [PATCH 4/5] increase payload to 1kB --- enclave-runtime/src/test/ipfs_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enclave-runtime/src/test/ipfs_tests.rs b/enclave-runtime/src/test/ipfs_tests.rs index fb730dcd81..0a0a9cf714 100644 --- a/enclave-runtime/src/test/ipfs_tests.rs +++ b/enclave-runtime/src/test/ipfs_tests.rs @@ -24,7 +24,7 @@ use std::{fs::File, io::Read, vec::Vec}; #[allow(unused)] pub fn test_ocall_read_write_ipfs() { info!("testing IPFS read/write. Hopefully ipfs daemon is running..."); - let enc_state: Vec = vec![20; 10]; + let enc_state: Vec = vec![20; 1024]; let cid = OcallApi.write_ipfs(enc_state.as_slice()).unwrap(); From 0f24bd0eaee4dd69903e6b39e07eee9637fbbe47 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 23 Sep 2025 13:18:29 +0200 Subject: [PATCH 5/5] increase payload to 100kB --- enclave-runtime/src/test/ipfs_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enclave-runtime/src/test/ipfs_tests.rs b/enclave-runtime/src/test/ipfs_tests.rs index 0a0a9cf714..f22ed1e2ac 100644 --- a/enclave-runtime/src/test/ipfs_tests.rs +++ b/enclave-runtime/src/test/ipfs_tests.rs @@ -24,7 +24,7 @@ use std::{fs::File, io::Read, vec::Vec}; #[allow(unused)] pub fn test_ocall_read_write_ipfs() { info!("testing IPFS read/write. Hopefully ipfs daemon is running..."); - let enc_state: Vec = vec![20; 1024]; + let enc_state: Vec = vec![20; 100*1024]; let cid = OcallApi.write_ipfs(enc_state.as_slice()).unwrap();