How diffuse-fi/zktls-enclave works
Project Overview
• The project is a Rust-based implementation of an Intel SGX enclave that provides privacy-preserving TLS connections (“zkTLS”). It is a fork of an SGX scaffold and is structured to facilitate secure communication with external APIs (e.g., Binance) while performing cryptographic operations inside a secure enclave.
• The application is composed of multiple Rust crates and uses an SGX runtime. The sensitive code (TLS, cryptography, data parsing) is running inside an enclave, while secret operations that cannot be executed in an untrusted context are isolated.
Main Components
a. Main Application (bin/zktls-pairs):
• This is the entrypoint which orchestrates the application logic.
• It reads input data (e.g., currency pairs from pairs/list.txt), triggers TLS connections, handles output file writes, and initiates enclave operations.
b. SGX Enclave (crates/enclave):
• Contains the core secure logic (TLS implementation, cryptographic hashing, attestation logic, etc.).
• Implements secure operations within the isolated enclave boundary.
• Contains files such as lib.rs, tls.rs, tcp_stream_oc.rs, parser.rs, and error handling.
c. Untrusted Host Library (crates/untrusted-host):
• Provides the OCALL implementations that interface between the enclave and non-enclave (host) code.
• Acts as the glue to handle operations that must be performed outside the secure enclave.
d. External Dependencies and Services:
• Binance API: The system makes outbound TLS requests to Binance’s API.
• File I/O: Using pairs/list.txt for reading input and outputting files like pairs.bin, prices.bin, timestamps.bin, and sgx_quote.bin.
e. Build and Deployment:
• Docker configurations (in the docker folder) for Ubuntu environments indicate containerized development/testing.
• The presence of Dockerfiles and docker-compose files suggests that environment consistency and ease of deployment are factors.
• Cargo configurations (Cargo.toml at the workspace level and per-crate) ensure proper dependency management.
Relationships and Interactions
• The main application initiates the workflow:
◦ It reads currency pair configurations.
◦ It establishes a TLS connection via enclave functionality.
• The enclave (crates/enclave) is responsible for executing secure computations:
◦ It uses secure APIs to perform TLS connection and cryptographic operations.
◦ It interacts with the untrusted-host for necessary outside calls (via OCALLs).
• Data Flow:
◦ Input: Pairs list is ingested into the main app.
◦ Processing: The main app communicates with the enclave, which in turn processes the TLS connection and performs secure operations.
◦ Output: The enclave and/or main app writes processed outputs (e.g., binary attestation reports) to files.
Architectural Patterns and Key Technologies
• The project follows a clear separation between trusted (enclave) and untrusted code (host application and OCALL library), a typical pattern in SGX applications.
• It leverages the Intel SGX SDK and DCAP for attestation and secure enclave management.
• Rust is used throughout, with Cargo and workspace configurations to manage dependencies.
• Docker containerization is used for deploying/testing in Ubuntu environments.