<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BAder82t</title>
    <description>The latest articles on DEV Community by BAder82t (@bader82t).</description>
    <link>https://dev.to/bader82t</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3879131%2F622c76be-a4c2-4127-aab9-3c770adb2770.png</url>
      <title>DEV Community: BAder82t</title>
      <link>https://dev.to/bader82t</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bader82t"/>
    <language>en</language>
    <item>
      <title>We benchmarked 5 FHE libraries on identical math. OpenFHE is 140,000 more precise than TenSEAL</title>
      <dc:creator>BAder82t</dc:creator>
      <pubDate>Tue, 21 Apr 2026 23:34:36 +0000</pubDate>
      <link>https://dev.to/bader82t/we-benchmarked-5-fhe-libraries-on-identical-math-openfhe-is-140000x-more-precise-than-tenseal-hpp</link>
      <guid>https://dev.to/bader82t/we-benchmarked-5-fhe-libraries-on-identical-math-openfhe-is-140000x-more-precise-than-tenseal-hpp</guid>
      <description>&lt;p&gt;Fully Homomorphic Encryption (FHE) lets you compute on encrypted data. The math is exact in theory. In practice, every CKKS implementation ships a slightly different rescaling strategy, and those differences don't show up until you look hard at worst-case inputs.&lt;/p&gt;

&lt;p&gt;We built an adversarial precision tester — &lt;a href="https://github.com/BAder82t/fhe-oracle-oss" rel="noopener noreferrer"&gt;FHE Oracle&lt;/a&gt; — and pointed it at the three main CKKS libraries. The results surprised us.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Every library runs the &lt;strong&gt;exact same circuit&lt;/strong&gt;: &lt;code&gt;(w·x + b)²&lt;/code&gt; over real inputs in &lt;code&gt;[-3, 3]^8&lt;/code&gt;, multiplicative depth 2. Same CKKS ring dimension (16384), same coefficient-modulus chain (&lt;code&gt;[60, 40, 40, 40, 40, 60]&lt;/code&gt;), same inputs, same threshold.&lt;/p&gt;

&lt;p&gt;The tester is &lt;code&gt;AutoOracle&lt;/code&gt; with a 500-evaluation budget and a noise-aware CMA-ES fitness function. It doesn't sample uniformly — it &lt;em&gt;searches&lt;/em&gt; for the inputs most likely to break precision. 5 random seeds, threshold &lt;code&gt;1e-2&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The leaderboard — CKKS (real-valued)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rank&lt;/th&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Scheme&lt;/th&gt;
&lt;th&gt;Fail rate&lt;/th&gt;
&lt;th&gt;Median max-err&lt;/th&gt;
&lt;th&gt;Wall&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🥇 1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;OpenFHE 1.5+&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;CKKS&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0% (0/5)&lt;/strong&gt; ✅&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.57e-08&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;21.2 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🥈 2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Pyfhel 3.5.0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;CKKS&lt;/td&gt;
&lt;td&gt;100% (5/5)&lt;/td&gt;
&lt;td&gt;1.30e-03&lt;/td&gt;
&lt;td&gt;43.9 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🥉 3&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;TenSEAL 0.3.16&lt;/strong&gt; (SEAL CKKS wrapper)&lt;/td&gt;
&lt;td&gt;CKKS&lt;/td&gt;
&lt;td&gt;100% (5/5)&lt;/td&gt;
&lt;td&gt;2.20e-03&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;17.7 s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;OpenFHE is the only library that passes. Across five seeds, the oracle couldn't drive its max error above &lt;code&gt;2.7e-08&lt;/code&gt;. TenSEAL and Pyfhel both FAIL every seed at &lt;code&gt;~1–2e-3&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;On identical math: &lt;strong&gt;OpenFHE is ~140,000× more precise than TenSEAL&lt;/strong&gt; and &lt;strong&gt;~80,000× more precise than Pyfhel&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The hypothesized cause: OpenFHE rescales after every ciphertext multiplication by default; TenSEAL defers rescales. Scalar smoke tests agree to six decimal places across all three libraries — the divergence only shows up at worst-case inputs that uniform random sampling almost never hits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why random testing misses this
&lt;/h2&gt;

&lt;p&gt;The inputs that trigger FHE precision failure sit in narrow regions of the input space. Those regions scale with multiplicative depth and the magnitude of intermediate ciphertexts. Uniformly sampling your training distribution will almost never find them.&lt;/p&gt;

&lt;p&gt;On our patent-reference benchmark (a CKKS logistic regression with a polynomial sigmoid approximation):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Random sampling, 500 evaluations: max error &lt;strong&gt;3.5e-4&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Adversarial CMA-ES, 500 evaluations: max error &lt;strong&gt;1.50&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ratio: &lt;strong&gt;4,259×&lt;/strong&gt;. Same budget, same circuit, same seed. Random testing found zero diverging inputs. The oracle found them in under a second.&lt;/p&gt;

&lt;h2&gt;
  
  
  The methodology note that matters
&lt;/h2&gt;

&lt;p&gt;CKKS libraries get compared to BGV/BFV/TFHE libraries all the time. That comparison is broken, and we want to be clear about why.&lt;/p&gt;

&lt;p&gt;CKKS is real-valued with bounded approximation error. Its natural circuit is &lt;code&gt;(w·x + b)²&lt;/code&gt; on real inputs. BGV/BFV/TFHE are exact integer arithmetic. Their natural circuit is &lt;code&gt;(w_int·x_int + b_int)² mod p&lt;/code&gt; on quantized integers. Forcing integer schemes to approximate real-valued math injects quantization error (order &lt;code&gt;1/s²&lt;/code&gt;) that dominates any library-level signal. Conversely, running CKKS on a modular-integer circuit wastes its precision.&lt;/p&gt;

&lt;p&gt;So we ran two leaderboards. The CKKS table above. And a separate integer/quantized table on its own circuit:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rank&lt;/th&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Scheme&lt;/th&gt;
&lt;th&gt;Fail rate&lt;/th&gt;
&lt;th&gt;Median max-err&lt;/th&gt;
&lt;th&gt;Wall&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🥇 1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;OpenFHE BFV 1.5+&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;BFV&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0%&lt;/strong&gt; (0/5)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;12.7 s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🥈 2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;OpenFHE BGV 1.5+&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;BGV&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0%&lt;/strong&gt; (0/5)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;15.6 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🥉 3&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Concrete ML 1.9.0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;TFHE&lt;/td&gt;
&lt;td&gt;33% (1/3)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0.6 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;BGV/BFV are bit-exact by design — zero divergence on every seed. Concrete ML's 33% FAIL is a quantization-boundary crossing effect, not an algorithmic error. TFHE wins on wall-clock by 20×; the tradeoff is that it operates on small fixed-width integers while BGV/BFV handle larger ranges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Picking a library
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Integer / PIR / encrypted SQL&lt;/strong&gt; → &lt;strong&gt;OpenFHE BFV&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantized ML inference&lt;/strong&gt; → &lt;strong&gt;Concrete ML&lt;/strong&gt; (TFHE)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-valued CKKS (LR, neural net, SHAP)&lt;/strong&gt; → &lt;strong&gt;OpenFHE&lt;/strong&gt; if you need precision, &lt;strong&gt;TenSEAL&lt;/strong&gt; if you need 1.2× speed and can tolerate ~140,000× more worst-case error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The TenSEAL-vs-OpenFHE tradeoff is real, not a bug. If you're doing CKKS smoke tests and shipping to production at scale, that precision gap will bite you eventually. If you're prototyping on benign data, TenSEAL's ergonomics and speed are fine. Pick deliberately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# CKKS unified (w·x+b)^2 benchmark (any Python venv with TenSEAL)&lt;/span&gt;
pip &lt;span class="nb"&gt;install &lt;/span&gt;fhe-oracle tenseal
python benchmarks/library_comparison.py &lt;span class="nt"&gt;--circuit&lt;/span&gt; unified-squared-dot &lt;span class="nt"&gt;--libs&lt;/span&gt; tenseal

&lt;span class="c"&gt;# Full leaderboard (OpenFHE BGV/BFV/CKKS) via Linux/amd64 Docker&lt;/span&gt;
docker build &lt;span class="nt"&gt;--platform&lt;/span&gt; linux/amd64 &lt;span class="nt"&gt;-t&lt;/span&gt; fhe-oracle-bench &lt;span class="nb"&gt;.&lt;/span&gt;
docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;--platform&lt;/span&gt; linux/amd64 fhe-oracle-bench &lt;span class="se"&gt;\&lt;/span&gt;
    python benchmarks/library_comparison.py &lt;span class="nt"&gt;--circuit&lt;/span&gt; unified-squared-dot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Full code, adapters, and raw results:&lt;br&gt;
&lt;strong&gt;&lt;a href="https://github.com/BAder82t/fhe-oracle-oss" rel="noopener noreferrer"&gt;github.com/BAder82t/fhe-oracle-oss&lt;/a&gt;&lt;/strong&gt; (AGPL-3.0)&lt;br&gt;
&lt;code&gt;pip install fhe-oracle&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What FHE Oracle does, in one paragraph
&lt;/h2&gt;

&lt;p&gt;It tests black-box semantic divergence between a plaintext function and its FHE-compiled counterpart using CMA-ES search with a noise-aware fitness (divergence + ciphertext noise-budget consumption + multiplicative-depth utilization). Adapters for OpenFHE, Microsoft SEAL, Concrete ML, and TenSEAL turn on noise-guided mode; a pure-divergence fallback runs without any native FHE library for CI. It does &lt;em&gt;not&lt;/em&gt; verify the cryptographic security of the FHE scheme, test for side-channel leaks, or replace formal verification. A PASS means the adversarial search didn't find a divergence in its budget, not that none exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats worth naming
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pyfhel's middle-of-the-pack result likely reflects its API wrapper, not the underlying SEAL.&lt;/strong&gt; Pyfhel requires manual &lt;code&gt;rescale_to_next&lt;/code&gt; / &lt;code&gt;mod_switch_to_next&lt;/code&gt; management per multiplication. On this depth-2 circuit it works. On Taylor-3 polynomials it fails with &lt;code&gt;scale out of bounds&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lattigo (Go)&lt;/strong&gt; would be interesting to add — it ships a built-in noise estimator — but it needs a subprocess wrapper to call from Python. Tracked as future work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concrete ML's 33% rate on the integer board&lt;/strong&gt; is quantization-boundary behavior, not an algorithmic bug. We note this in the table to avoid misreading the number.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why we built this
&lt;/h2&gt;

&lt;p&gt;CKKS circuits that pass on 99,999 random inputs can return garbage on the 100,000th. If you're deploying FHE ML to production (credit scoring, medical inference, privacy-preserving recommendation), random precision testing isn't enough — you need an adversary searching for the inputs that break you. That's what the oracle does.&lt;/p&gt;

&lt;p&gt;PRs welcome. Add a library by writing one adapter; leaderboard updates on re-run.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Bader Alissaei — VaultBytes. A patent application on the method (&lt;code&gt;PCT/IB2026/053378&lt;/code&gt;) has been filed; the code is AGPL-3.0. Commercial licences via &lt;a href="mailto:b@vaultbytes.com"&gt;b@vaultbytes.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cryptography</category>
      <category>security</category>
      <category>python</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
