TL;DR
This paper introduces TEECHAT, a novel protocol and prototype for secure, end-to-end encrypted chat with cloud-hosted Large Language Models (LLMs) using Trusted Execution Environments (TEEs). It demonstrates that TEEs can enable private LLM interactions with minimal latency overhead, especially for larger models, addressing a critical privacy gap in current cloud-based AI services.
What Problem Does This Paper Address?
The widespread adoption of cloud-based LLM assistants presents a significant privacy challenge. User prompts, which can contain sensitive personal, medical, or legal information, are sent to cloud servers in plaintext. This exposes this data to cloud providers, infrastructure operators, and any malicious actors who might gain access to the servers. Existing privacy solutions are often inadequate: PII removal can degrade model quality, while advanced cryptographic techniques like Fully Homomorphic Encryption (FHE) introduce prohibitive latency, making real-time chat impractical. The paper aims to bridge this gap by exploring the use of hardware-based TEEs to secure LLM inference while maintaining practical performance.
Methods
The core of this work is the TEECHAT protocol, a research prototype designed to secure the communication between a local client and a cloud-hosted LLM running within a nested TEE environment (specifically, a confidential NVIDIA H100 GPU within an AMD SEV-SNP CPU-based confidential VM). TEECHAT comprises four key steps:
- Ephemeral Key Exchange: A unique session key is established between the client and the TEE using a Diffie-Hellman key exchange over HTTPS.
- Remote Attestation: The client verifies the authenticity and integrity of the TEE by requesting a hardware-signed quote that proves the correct confidential hardware and software are running.
- Encrypted & Authenticated Transport: All subsequent communication between the client and the TEE is encrypted and authenticated using the established session key, with nonces to prevent replay attacks.
- Nested-TEE Inference: Prompts are decrypted only within the CPU enclave, which then launches kernels on the confidential GPU. Intermediate activations and responses remain encrypted within the TEE, and outputs are re-encrypted before leaving the enclave.
The authors also investigated performance bottlenecks by benchmarking micro-operations like matrix multiplication (GEMM) and host-to-GPU data transfers within confidential VMs. They explored kernel-level optimizations like FlashAttention-2, CUDA Graph replay, and on-GPU fused sampling to mitigate these bottlenecks.
Datasets
The paper does not discuss training datasets. For evaluation, they used publicly available LLM models:
- LLAMA3.2-3B-INSTRUCT
- QWEN3-8B
- QWEN3-32B
These models were run on an Azure ND H100 v5 confidential VM.
Key Insights and Ideas
- TEE as a Practical Middle Ground: TEEs offer a compelling alternative to existing privacy solutions, providing hardware-backed security without the extreme performance penalties of FHE or the potential quality degradation of PII removal.
- CPU-GPU Communication is the Bottleneck: The initial naive implementation of LLMs within confidential VMs showed significant slowdowns (1.87x) primarily due to CPU-GPU encryptions and data transfers, rather than just compute.
- Kernel Optimizations are Crucial: Fusing kernels, using CUDA Graphs, and keeping data in SRAM (e.g., with FlashAttention-2) are essential for achieving near-standard performance within TEEs.
- Latency Scales with Model Size: The overhead introduced by TEEs becomes negligible for larger LLMs (over 30B parameters) because the LLM inference time itself dominates the overall processing time.
- End-to-End Security is Achievable: TEECHAT successfully extends TEE guarantees to the entire client-to-cloud communication channel, providing a comprehensive privacy solution.
Key Results
- Naive TEE Performance: Without optimizations, confidential VMs with nested CPU-GPU enclaves were 1.87x slower than standard VMs. CPU-GPU encryptions caused up to 67% slower kernel launches and up to 1200% slower CPU-GPU I/O.
- TEECHAT Overhead: For models over 30B parameters, TEECHAT adds only 1% latency. For smaller models (3B), the overhead was around 13.9%.
- Message Encryption Overhead: Encryption and decryption for messages added a negligible ~10 ms overhead.
- Optimal Batch Size: A batch size of < 16 was found to be optimal for CGPU utilization.
- Kernel Optimization Impact: Enabling three key optimizations (FlashAttention-2, CUDA Graph, On-GPU fused sampling) reduced overhead by approximately 5.6x.
Limitations and Future Work
- Proof-of-Concept: The authors explicitly state that TEECHAT is a research prototype, not a production-ready secure system.
- Trust in Azure: The experimental setup relies on Azure's virtualization stack, which is closed-source. The authors note that if users could inspect this stack, they wouldn't need to trust the cloud provider.
- CPU Attestation Not Timed: While GPU attestation was measured, the time for CPU attestation was not included in the key exchange latency measurement.
- Future Work: The authors suggest that as LLMs and workloads evolve, future research should focus on expanding these security methods to distributed and heterogeneous environments. They also imply that making the virtualization stack more transparent would enhance trust.
Summary updated