Invertible Matrix Challenge
The article details the solution provided by the winner of the FHERMA Invertible Matrix challenge.
Author: Chi-Hieu Nguyen, University of Technology Sydney, Australia.
Introduction
Matrix inversion is a cornerstone of linear algebra, but performing it on encrypted data using HE presents unique challenges. The FHERMA Invertible Matrix Challenge tasked us with inverting a nonsingular 64x64 matrix efficiently—within approximately 30 minutes per matrix. The complexity arises from the deep computation circuits required for matrix operations over ciphertexts, which significantly increases both time and resource demands.
The Core Idea: Iterative Matrix Inversion
Based on a review of recent literature, we adopted an iterative algorithm proposed in [1], which combines Goldschmidt’s and Newton’s methods. This hybrid approach is ideal for HE, as it maintains a low multiplicative depth—a critical factor given the substantial overhead introduced by each ciphertext multiplication.
Below is the algorithm in Python:
""" Compute the inverse of a matrix A using the Goldschmidt algorithm. """
A_inv = np.linalg.inv(A) # Ground truth for comparison
I = np.eye(A.shape[0])
norm_A = 24 # Empirically chosen constant
X = A.T / (norm_A ** 2)
R = I - A @ A.T / (norm_A ** 2)
for iteration in range(max_iterations):
X = X @ (I + R)
R = R @ R
# Check for convergence
residual_norm = np.abs(X - A_inv).max()
if residual_norm < tolerance:
print(f"Converged in {iteration + 1} iterations.")
return X
In this context, the value norm_A represents the trace norm of the matrix product A @ A.T. However, to reduce computational overhead, we empirically substitute this value with a constant (24). Experimental results indicate that the algorithm converges within 26 iterations with high probability. Analyzing the inner loop of the algorithm reveals that each iteration incurs a multiplicative depth of only one, consistent with the claim in [1]. Nevertheless, due to the nature of matrix multiplication over encrypted data, additional multiplicative levels are required to perform slot masking and realignment within the ciphertexts of matrices X and R after each iteration.
Key Building Block: Ciphertext Matrix Multiplication with Tile Tensors
There is extensive research on ciphertext matrix-matrix multiplication. In this work, we adopt the tile tensor abstraction introduced in [2] and IBM HELayer SDK [3], owing to its clarity and implementation ease. For a detailed introduction to tile tensors and the set of operations supported on this data structure, please refer to [2].
Understanding Tile Tensors
Tile tensors split matrices into smaller "tiles" that fit into ciphertext slots. For a matrix of size , we encode it as , where are tiling dimensions. This structure supports operations like duplication, summation, and multiplication along specific axes.
Performing Matrix Multiplication
Given two matrices and , to compute , we encode and so the contracted dimension (the dimension over which the summation runs over) aligns in their tensor shapes. One possible encoding is and . The multiplication proceeds as:
where duplicates the tensor along the -th dimension, and sums over the -th dimension. The resulting tensor contains unknown values in the second dimension, denoted by . To enable further computations, we clear unused slots using the operator:
.
The operation involves multiplication with a plaintext mask, incurring one multiplicative level.
Matrix transposition, e.g., from to , is performed as follows:
where is the identity matrix of size .
The Encrypted Algorithm
We now construct the complete encrypted matrix inversion algorithm. The input ciphertext is encoded as a tile tensor of shape , with , , fitting slots. Following the cleartext algorithm, we first compute . We transpose to , then calculate:
Since and are symmetric, we can select either dimension (e.g., 1 or 3) as the contracted dimension for multiplications.
With and , we enter the iteration loop. At each iteration, is updated as , which is straightforward due to compatible shapes. However, updating requires transposing one of ’s dimensions (e.g., from to ) to enable multiplication. As mentioned earlier, transposition involves multiplying with an appropriately encoded identity matrix, resulting in two matrix products per iteration and doubling the multiplicative depth.
To address this, we use a simple optimization. Instead of maintaining one encoding of , we store three: , , and , which are derived from before the loop. Within the loop, these encodings are used pairwise to compute updates, e.g.: , and similarly for and . This keeps the multiplicative depth per iteration at 2 (equivalent to one matrix multiplication), at the cost of four matrix multiplications per iteration instead of two. This trade-off is justified, as the computational cost is lower than the savings from reduced depth. The total depth is: 26 (iterations) * 2 + 1 (scaling) + 4 (computing ) + 4 (reshaping result) = 61.
References
[1] Ahn, T.M., Lee, K.H., Yoo, J.S., Yoon, J.W. (2024). Cheap and Fast Iterative Matrix Inverse in Encrypted Domain. In: Tsudik, G., Conti, M., Liang, K., Smaragdakis, G. (eds) Computer Security – ESORICS 2023. Lecture Notes in Computer Science, vol 14344. Springer, Cham.
[2] Aharoni, E., Adir, A., Baruch, M., Drucker, N., Ezov, G., Farkash, A., Greenberg, L., Masalha, R., Moshkowich, G., Murik, D., Shaul, H., Soceanu, O. (2023). HeLayers: A Tile Tensors Framework for Large Neural Networks on Encrypted Data. Privacy Enhancing Technology Symposium (PETs).
CITING THIS WORK
This write-up documents a component of the FHERMA library. If it informs your work, cite the two papers below rather than the article URL.
- 01FHERMA Cookbook: FHE Components for Privacy-Preserving ApplicationsJanis Adamek, Aikata Aikata, Ahmad Al Badawi, Andreea Alexandru, Armen Arakelov, Philipp Binfet, Victor Correa, Jules Dumezy, Sergey Gomenyuk, Valentina Kononova, Dmitrii Lekomtsev, Vivian Maloney, Chi-Hieu Nguyen, Yuriy Polyakov, Daria Pianykh, Hayim Shaul, Moritz Schulze Darup, Dieter Teichrib, Dmitry Tronin, Gurgen ArakelovCryptology ePrint Archive, Paper 2025/1302 · doi:10.1145/3733811.3767313
- 02FHERMA: Building the Open-Source FHE Components Library for Practical UseGurgen Arakelov, Nikita Kaskov, Daria Pianykh, Yuriy PolyakovCryptology ePrint Archive, Paper 2024/612
