Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 198 additions & 44 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rustls = "0.22.4"
webpki-roots = "0.26.6"
reqwest = "0.12.9"
thiserror = "2.0.12"
clap = "3.2"

untrusted-host = { path = "crates/untrusted-host" }

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ When you run the application (e.g., using cargo sgx run), the following steps oc
- **Cryptographic Hashing & Attestation**: Generates individual hashes for each data component, combines them, and produces a final attestation report using Intel SGX DCAP.
- **File Outputs**: Writes outputs to files (e.g., pairs.bin, prices.bin, timestamps.bin, sgx_quote.bin).

### Description of use:
```shell
./zktls-pairs --help

enclave v0
Diffuse

USAGE:
zktls-pairs [OPTIONS]

OPTIONS:
-h, --help Print help information
--pairs-file-path <PAIRS_FILE_PATH> Path to the file with pairs [default: pairs/list.txt]
-V, --version Print version information

```

## Community and Support

For any questions, discussions, or contributions, join our [Telegram Channel](https://t.me/zkdiffuse). We're active there and ready to help!
1 change: 1 addition & 0 deletions bin/zktls-pairs/sgx/enclave.edl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enclave {
);

void ocall_read_from_file(
[in, string] const char* filename_bytes,
[out, size=pairs_list_buffer_len] char* pairs_list_buffer,
size_t pairs_list_buffer_len,
[out] size_t* pairs_list_actual_len
Expand Down
1 change: 0 additions & 1 deletion bin/zktls-pairs/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate mock_lib;

use automata_sgx_sdk::types::SgxStatus;

automata_sgx_sdk::enclave! {
Expand Down
1 change: 1 addition & 0 deletions crates/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ tracing-subscriber = { workspace = true, features = ["env-filter"]}

serde = { workspace = true, features = ["derive"]}
tiny-keccak = { workspace = true, features = ["sha3", "keccak"]}
clap = { workspace = true, features = ["derive"] }
17 changes: 16 additions & 1 deletion crates/enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ mod parser;
mod tcp_stream_oc;
mod tls;

use std::{fmt::Debug, string::String};
use std::{ffi::CString, fmt::Debug, string::String};

use automata_sgx_sdk::types::SgxStatus;
use clap::Parser;
use ethabi::{Token, Uint};
use serde_json::json;
use tiny_keccak::{Hasher, Keccak};
Expand All @@ -32,6 +33,7 @@ extern "C" {
);

fn ocall_read_from_file(
filename_bytes: *const u8,
pairs_list_buffer: *mut u8,
pairs_list_buffer_len: usize,
pairs_list_actual_len: *mut usize,
Expand All @@ -41,8 +43,18 @@ extern "C" {
pub(crate) const BINANCE_API_HOST: &str = "data-api.binance.vision";
pub(crate) const HARDCODED_DECIMALS: u32 = 8;

#[derive(Parser)]
#[clap(author = "Diffuse", version = "v0", about)]
struct ZkTlsPairs {
/// Path to the file with pairs
#[clap(long, default_value = "pairs/list.txt")]
pairs_file_path: String,
}

#[no_mangle]
pub unsafe extern "C" fn trusted_execution() -> SgxStatus {
let cli = ZkTlsPairs::parse();

let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));

Expand All @@ -54,8 +66,11 @@ pub unsafe extern "C" fn trusted_execution() -> SgxStatus {
// data can be passed betwen enclave and outer world only with byte arrays
let mut pairs_list_buffer: [u8; 8192] = [0; 8192];
let mut pairs_list_actual_len: usize = 0;
let cstr = CString::new(cli.pairs_file_path).expect("CString::new failed");
let path_bytes = cstr.as_ptr() as *const u8;

ocall_read_from_file(
path_bytes,
pairs_list_buffer.as_mut_ptr(),
pairs_list_buffer.len(),
&mut pairs_list_actual_len as *mut usize,
Expand Down
15 changes: 12 additions & 3 deletions crates/untrusted-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,31 @@ pub unsafe fn ocall_write_to_file(

#[no_mangle]
pub unsafe fn ocall_read_from_file(
filename_bytes: *const u8,
pairs_list_buffer: *mut u8,
pairs_list_buffer_len: usize,
pairs_list_actual_len: *mut usize,
) {
tracing::debug!("=============== Untrusted read_from_file =================");

let pairs_list_path = "pairs/list.txt";
let cstr = CStr::from_ptr(filename_bytes as *const c_char);
let filename = match cstr.to_str() {
Ok(s) => s,
Err(_) => {
tracing::error!("Failed to read filename from buffer");
return;
}
};

let pairs_list = fs::read(pairs_list_path).expect("Unable to read file");
tracing::info!("Reading from file: {}", filename);
let pairs_list = fs::read(filename).expect("Unable to read file");

assert!(
pairs_list.len() <= pairs_list_buffer_len,
"pairs list does not fit into pairs_list_buffer!"
);
ptr::copy_nonoverlapping(pairs_list.as_ptr(), pairs_list_buffer, pairs_list.len());
*pairs_list_actual_len = pairs_list.len();
ptr::write_unaligned(pairs_list_actual_len, pairs_list.len());

tracing::debug!("=============== End of untrusted read_from_file =================");
}