Fully Homomorphic Encryption (FHE) enables computations directly on encrypted data, but its high computational cost remains a significant barrier. Writing efficient FHE code is a complex task requiring cryptographic expertise, and finding the optimal sequence of program transformations is often intractable. In this paper, we propose CHEHAB RL, a novel framework that leverages deep reinforcement learning (RL) to automate FHE code optimization. Instead of relying on predefined heuristics or combinatorial search, our method trains an RL agent to learn an effective policy for applying a sequence of rewriting rules to automatically vectorize scalar FHE code while reducing instruction latency and noise growth. The proposed approach supports the optimization of both structured and unstructured code. To train the agent, we synthesize a diverse dataset of computations using a large language model (LLM). We integrate our proposed approach into the CHEHAB FHE compiler and evaluate it on a suite of benchmarks, comparing its performance against Coyote, a state-of-the-art vectorizing FHE compiler. The results show that our approach generates code that is $5.3\times$ faster in execution, accumulates $2.54\times$ less noise, while the compilation process itself is $27.9\times$ faster than Coyote (geometric means).
翻译:全同态加密(FHE)支持直接在加密数据上进行计算,但其高昂的计算成本仍是主要瓶颈。编写高效的FHE代码是一项需要密码学专业知识的复杂任务,而寻找最优的程序转换序列通常难以实现。本文提出CHEHAB RL——一种利用深度强化学习(RL)实现FHE代码自动优化的新型框架。该方法不依赖预定义启发式规则或组合搜索,而是训练一个RL智能体来学习有效的策略,通过应用一系列重写规则自动实现标量FHE代码的向量化,同时降低指令延迟与噪声增长。所提出的方法支持结构化与非结构化代码的优化。为训练智能体,我们使用大语言模型(LLM)合成了多样化的计算数据集。我们将该方法集成至CHEHAB FHE编译器中,并通过基准测试套件进行评估,与当前最先进的向量化FHE编译器Coyote进行性能对比。结果表明:本方法生成的代码执行速度提升$5.3\times$,噪声累积降低$2.54\times$,且编译过程本身比Coyote快$27.9\times$(几何平均值)。