Fast Batch Matrix Multiplication in Ciphertexts

Jung Hee Cheon, Minsik Kang, Junho LeeIACR ePrint 2025

Abstract

Fully Homomorphic Encryption (FHE) is a cornerstone for privacy-preserving machine learning (PPML), yet the computational overhead of matrix multiplication remains a significant barrier. This paper presents a novel encoding technique, Slots-in-Coefficient (SinC), designed to optimize batched matrix multiplication on encrypted data. By mapping encrypted operations to standard plaintext matrix multiplications (PPMM), the proposed framework achieves up to 205× speedups for small-to-medium matrices. This approach effectively bridges the gap between theoretical FHE capabilities and the practical requirements of modern AI models like Transformers and Large Language Models (LLMs).

Introduction

The ability to perform computations on encrypted data without decryption, known as Fully Homomorphic Encryption (FHE), offers a "holy grail" solution for data privacy. However, the core operation of most AI models—Matrix Multiplication (MM)—is notoriously slow in the encrypted domain. Existing "reduction-based" algorithms attempt to convert encrypted MM into standard plaintext MM (PPMM) to leverage optimized libraries like OpenBLAS.

A major limitation of current methods is their inefficiency when matrix dimensions ($d$) do not align with the encryption scheme's ring dimension ($N$). For instance, when processing small or medium-sized matrices (e.g., $64 \times 64$), these methods underutilize the available "slots" in a ciphertext, leading to significant performance waste.

Methodology: Slots-in-Coefficient (SinC) Encoding

The authors introduce three primary innovations to overcome these bottlenecks:

1. SinC Encoding

Unlike traditional FHE encoding that places data into discrete "slots," SinC represents matrix entries using the coefficients of a polynomial. Specifically, each coefficient corresponds to the Discrete Fourier Transform (DFT) of matrix entries across different batch instances. This allows for packing multiple small matrix multiplications into a single large ciphertext operation, maximizing the utilization of the ring dimension.

Overview of the SinC encoding process, transforming a message stack into plaintext and ciphertext components.

2. Reduction to PPMM

By employing SinC, the authors demonstrate that a batch of encrypted matrix multiplications can be reduced to a small number of standard plaintext matrix multiplications—two for ciphertext-plaintext (CPMM) and four for ciphertext-ciphertext (CCMM). This reduction allows the system to offload the heavy lifting to highly optimized, hardware-level BLAS libraries.

3. The TWEAK Algorithm

To address the "ciphertext matrix transpose" (CMT) operation—a necessary step for multiplying two encrypted matrices—the authors developed TWEAK, a Cooley-Tukey-style algorithm. TWEAK significantly accelerates the rearrangement of data within encrypted polynomials, reducing a major computational overhead.

4. Support for Rectangular Matrices

The framework is extended to handle lopsided rectangular matrices (e.g., $64 \times 2048$), which are ubiquitous in the attention mechanisms of Transformers and LLMs.

Performance Evaluation

The implementation utilizes the HEaaN library for FHE operations and FLINT for modular matrix arithmetic. Benchmarks were conducted on square matrices (up to $512 \times 512$) and highly unbalanced rectangular matrices.

Key Results

  • Massive Speedups: For 128 batches of $64 \times 64$ matrices, the SinC method is 205× faster for CPMM (0.20s) and 64× faster for CCMM (0.91s) compared to previous state-of-the-art methods.
  • LLM Scalability: In a simulated Transformer layer operation ($64 \times 2048$ by $2048 \times 2048$), the algorithm completes in 7.8 seconds, representing a 28× speedup.
  • Key Efficiency: The method drastically reduces the size of evaluation keys, often requiring 0 MB for CPMM, whereas prior methods required gigabytes of key storage.

Discussion and Future Work

A unique advantage of SinC encoding is its "zero-cost" conversion. Because the encoding is mathematically similar to the internal steps of FHE "bootstrapping," the conversion can be integrated into the bootstrapping process with negligible extra cost. This makes the approach highly flexible, allowing matrix dimensions and batch sizes to vary independently of the ring size.

However, some limitations remain. SinC encoding introduces slightly more noise than traditional methods, resulting in a precision of approximately 14-17 bits. While sufficient for many machine learning tasks, it may be a constraint for high-precision applications. Additionally, while TWEAK improves performance, the ciphertext transpose remains a primary bottleneck. Future research may explore integrating sub-cubic complexity algorithms, such as Strassen’s, to further enhance scalability.

Conclusion

The SinC encoding framework represents a significant leap forward for privacy-preserving machine learning. By transforming complex encrypted operations into standard linear algebra problems, it unlocks the performance of optimized BLAS libraries for FHE, making the deployment of encrypted LLMs and Transformers increasingly feasible.

Summary updated

BibTeX
@article{cheon2025fast,
  author = {Jung Hee Cheon and Minsik Kang and Junho Lee},
  title = {{Fast Batch Matrix Multiplication in Ciphertexts}},
  journal = {IACR Cryptol. ePrint Arch.},
  year = {2025},
}
Figure