GCD: Garbled, Corrected, Demonstrandum -- Fixing and Proving Go's Extended GCD Implementation
Pith reviewed 2026-06-28 00:38 UTC · model grok-4.3
The pith
Go's extended GCD implementation contained two invariant-breaking deviations from BoringSSL that were fixed and then formally proven correct and terminating.
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
Core claim
After repairing the coefficient-update deviation, the Go extendedGCD function satisfies its specification for the declared input domain; the repaired program is both partially correct and terminating. The argument is obtained by mechanically porting and extending a prior BoringSSL proof, with Gobra handling the imperative Go code and Lean supplying the necessary non-linear arithmetic facts.
What carries the argument
Gobra deductive verifier for Go together with the ported and extended BoringSSL extended-GCD proof and imported Lean lemmas on arithmetic.
If this is right
- The repaired implementation can be used for RSA key-pair generation with a mechanically checked guarantee of correctness.
- Termination of the fixed code is now established, eliminating the possibility of non-termination on any valid input.
- The same port-and-extend strategy can be reused for other BoringSSL-derived cryptographic primitives in Go.
- AI-assisted refinement of invariants, guided by Gobra error messages, can accelerate similar verification tasks.
Where Pith is reading between the lines
- Other language ports of the same BoringSSL GCD routine may contain analogous coefficient-update errors.
- Embedding Gobra-style verification in the Go standard-library release process could catch future deviations before they ship.
- The observed 24 percent speedup indicates that correctness fixes can also improve performance when they remove unnecessary operations.
Load-bearing premise
The two deviations identified in the paper are the only ones that break the algorithm invariants, and the BoringSSL proof can be ported and extended to the larger input domain without introducing new gaps.
What would settle it
An input pair inside the documented domain for which the repaired Go code returns coefficient pairs that fail the extended-GCD relation a*x + b*y = gcd would falsify the claim.
Figures
read the original abstract
We verify the 'extendedGCD' implementation in Go's standard library ('crypto/internal/fips140/bigmod'), which plays a crucial role in the generation of RSA key pairs. Even though the Go implementation is supposedly a direct port from BoringSSL's implementation, we uncovered two deviations that each break the algorithm's invariants: (1) the Go implementation deviates in the way coefficients are updated, and (2) it permits a larger input domain. We address both deviations; the first by fixing the Go implementation, which results in an on average 24% speedup, and the second deviation by porting an existing proof for BoringSSL and extending it to cover the larger input domain. We prove correctness and termination of the fixed Go implementation using Gobra, a deductive program verifier for Go. Where necessary, we used Lean to prove key lemmata on non-linear arithmetic, which we import into Gobra. Our verification effort reveals three key insights: subtle bugs can slip into even well-reviewed code with surprising ease; formal verification is a powerful tool for uncovering them; and AI agents can facilitate the verification process by iteratively refining invariants and lemmata based on Gobra's error messages.
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The paper identifies two deviations between Go's extendedGCD implementation in crypto/internal/fips140/bigmod and the BoringSSL version from which it was ported: an incorrect update rule for the coefficients and an expanded input domain. The authors correct the coefficient update (yielding an average 24% speedup), port the existing BoringSSL proof, and extend it to the larger domain. They establish correctness and termination of the repaired Go code via a machine-checked proof in Gobra, importing auxiliary Lean lemmata for the non-linear arithmetic that arises from the domain extension. The work also reports three meta-insights on the ease with which subtle bugs enter reviewed code, the utility of formal verification, and the role of AI agents in invariant refinement.
Significance. If the machine-checked proof is sound, the contribution is significant: it supplies a verified, faster implementation of a core primitive used in RSA key generation, demonstrates that deductive verification (Gobra + Lean) can scale to non-linear arithmetic arising from realistic input domains, and furnishes concrete evidence that formal methods can detect deviations invisible to conventional review. The explicit reuse and extension of a prior BoringSSL proof, together with the machine-checked status of both the program and the supporting arithmetic lemmata, strengthens the result.
minor comments (2)
- [Abstract] Abstract: the claim that the two deviations are exhaustive would benefit from an explicit statement (in the body) that the authors performed a systematic comparison of the two code bases rather than relying solely on the two observed failures.
- The description of how the Lean lemmata are imported into Gobra (e.g., via trusted axioms or a verified embedding) is only sketched; a short paragraph or appendix entry would improve reproducibility.
Simulated Author's Rebuttal
We thank the referee for the positive assessment of our work on verifying and correcting Go's extendedGCD implementation, including the recognition of its significance for RSA key generation and the value of the machine-checked proof. We appreciate the recommendation to accept.
Circularity Check
No significant circularity; machine-checked proof against external spec
full rationale
The paper's central claim is a deductive verification of a fixed Go extendedGCD implementation using Gobra (with Lean lemmata for non-linear arithmetic). It ports and extends an existing BoringSSL proof to a larger input domain. This is self-contained against external benchmarks: the specification, BoringSSL reference, and proof tools are independent of the present manuscript. No step reduces by construction to a fitted parameter, self-defined quantity, or load-bearing self-citation chain. The two identified deviations and the fix are justified by direct comparison to the external BoringSSL code, not by internal redefinition.
Axiom & Free-Parameter Ledger
axioms (2)
- domain assumption Soundness of Gobra deductive verifier and Lean theorem prover for the imported lemmata
- standard math Standard properties of non-linear integer arithmetic
Reference graph
Works this paper leans on
-
[1]
José Bacelar Almeida, Manuel Barbosa, Gilles Barthe, Arthur Blot, Benjamin Grégoire, Vincent Laporte, Tiago Oliveira, Hugo Pacheco, Benedikt Schmidt, and Pierre-Yves Strub. 2017. Jasmin: High-Assurance and High-Speed Cryptography. InCCS. ACM, 1807–1823. doi:10.1145/3133956.3134078
-
[2]
José Bacelar Almeida, Denis Firsov, Tiago Oliveira, and Dominique Unruh. 2023. Schnorr Protocol in Jasmin. Cryptology ePrint Archive, Paper 2023/752. https: //eprint.iacr.org/2023/752
2023
-
[3]
Linard Arquint. 2026. crypto/internal/fips140/bigmod: Fix ‘extendedGCD’ Imple- mentation Mismatch. https://go-review.googlesource.com/c/go/+/770380
2026
-
[4]
Linard Arquint. 2026. Verification of extendedGCD. https://github.com/arquintl/ go-gcd
2026
-
[5]
Linard Arquint. 2026. Verification of extendedGCD – Continuous Verification. https://github.com/arquintl/go-gcd/actions/workflows/verify-gcd.yml
2026
-
[6]
Koenig, Joey Dodds, Daniel Kroening, and Peter Müller
Linard Arquint, Samarth Kishor, Jason R. Koenig, Joey Dodds, Daniel Kroening, and Peter Müller. 2026. The Secrets Must Not Flow: Scaling Security Verification to Large Codebases. InS&P. IEEE, 492–511. doi:10.1109/SP63933.2026.00026 To appear
-
[7]
Linard Arquint, Malte Schwerhoff, Vaibhav Mehta, and Peter Müller. 2023. A Generic Methodology for the Modular Verification of Security Protocol Imple- mentations. InCCS. ACM, 1377–1391. doi:10.1145/3576915.3623105
-
[8]
Linard Arquint, Felix A. Wolf, Joseph Lallemand, Ralf Sasse, Christoph Sprenger, Sven N. Wiesner, David A. Basin, and Peter Müller. 2023. Sound Verification of Security Protocols: From Design to Interoperable Implementations. InS&P. IEEE, 1077–1093. doi:10.1109/SP46215.2023.10179325
-
[9]
Gilles Barthe, Benjamin Grégoire, Sylvain Heraud, and Santiago Zanella-Béguelin
-
[10]
Computer-Aided Security Proofs for the Working Cryptographer. In CRYPTO (LNCS, Vol. 6841). Springer, 71–90. doi:10.1007/978-3-642-22792-9_5
-
[11]
David Benjamin. 2018. Add a Constant-Time Binary Extended GCD Algorithm. https://github.com/mit-plv/fiat-crypto/pull/333
2018
-
[12]
Rustan M
Barry Bond, Chris Hawblitzel, Manos Kapritsos, K. Rustan M. Leino, Jacob R. Lorch, Bryan Parno, Ashay Rane, Srinath T. V. Setty, and Laure Thompson. 2017. Vale: Verifying High-Performance Cryptographic Assembly Code. InUSENIX Security Symposium. USENIX Association, 917–934
2017
-
[13]
John Boyland. 2003. Checking Interference with Fractional Permissions. InSAS (LNCS, Vol. 2694). Springer, 55–72. doi:10.1007/3-540-44898-5_4
-
[14]
Cryspen. 2020. libcrux - A High-Assurance Cryptographic Library in Rust. https://github.com/cryspen/libcrux
2020
-
[15]
Andres Erbsen, Jade Philipoom, Jason Gross, Robert Sloan, and Adam Chlipala
-
[16]
Simple High-Level Code for Cryptographic Arithmetic - With Proofs, Without Compromises. InS&P. IEEE, 1202–1219. doi:10.1109/SP.2019.00005
-
[17]
Go developers. 2026. testing.B.Loop Documentation. https://pkg.go.dev/testing# B.Loop
2026
-
[18]
Secure two- party quantum evaluation of unitaries against specious adversaries,
K. Rustan M. Leino. 2010. Dafny: An Automatic Program Verifier for Functional Correctness. InLPAR (Dakar) (LNCS). Springer, 348–370. doi:10.1007/978-3-642- 17511-4_20
-
[19]
Alfred Menezes, Paul C. van Oorschot, and Scott A. Vanstone. 1996.Handbook of Applied Cryptography. CRC Press. doi:10.1201/9781439821916
-
[20]
Peter Müller, Malte Schwerhoff, and Alexander J. Summers. 2016. Viper: A Verification Infrastructure for Permission-Based Reasoning. InVMCAI (LNCS, Vol. 9583). Springer, 41–62. doi:10.1007/978-3-662-49122-5_2
-
[21]
2019.FIPS PUB 140-3: Secu- rity Requirements for Cryptographic Modules
National Institute of Standards and Technology. 2019.FIPS PUB 140-3: Secu- rity Requirements for Cryptographic Modules. Federal Information Processing Standards Publication 140-3. National Institute of Standards and Technology. doi:10.6028/NIST.FIPS.140-3
-
[22]
João C. Pereira, Tobias Klenze, Sofia Giampietro, Markus Limbeck, Dionysios Spiliopoulos, Felix Wolf, Marco Eilers, Christoph Sprenger, David A. Basin, Peter Müller, and Adrian Perrig. 2025. Protocols to Code: Formal Verification of a Secure Next-Generation Internet Router. InCCS. ACM, 1469–1483. doi:10.1145/ 3719027.3765104
arXiv 2025
-
[23]
Jade Philipoom. 2023. Add a Constant-Time Binary Extended GCD Algorithm. https://github.com/mit-plv/fiat-crypto/pull/1597
2023
-
[24]
Jonathan Protzenko, Bryan Parno, Aymeric Fromherz, Chris Hawblitzel, Marina Polubelova, Karthikeyan Bhargavan, Benjamin Beurdouche, Joonwon Choi, An- toine Delignat-Lavaud, Cédric Fournet, Natalia Kulatova, Tahina Ramananandro, Aseem Rastogi, Nikhil Swamy, Christoph M. Wintersteiger, and Santiago Zanella Béguelin. 2020. EverCrypt: A Fast, Verified, Cross-...
-
[25]
John C. Reynolds. 2002. Separation Logic: A Logic for Shared Mutable Data Structures. InLICS. IEEE, 55–74. doi:10.1109/LICS.2002.1029817
-
[26]
Junyang Shao. 2025. More Predictable Benchmarking with testing.B.Loop. https: //go.dev/blog/testing-b-loop
2025
-
[27]
Nikhil Swamy, Catalin Hritcu, Chantal Keller, Aseem Rastogi, Antoine Delignat- Lavaud, Simon Forest, Karthikeyan Bhargavan, Cédric Fournet, Pierre-Yves Strub, Markulf Kohlweiss, Jean Karim Zinzindohoue, and Santiago Zanella Béguelin
-
[28]
Dependent Types and Multi-Monadic Effects in F*. InPOPL. ACM, 256–270. doi:10.1145/2837614.2837655
-
[29]
The Formosa team. [n. d.]. Formosa Crypto. https://formosa-crypto.org
-
[30]
Filippo Valsorda. 2024. crypto/internal/fips140/bigmod: Add Nat.InverseVarTime. https://go-review.googlesource.com/c/go/+/632415
2024
-
[31]
Filippo Valsorda. 2025. crypto/internal/fips140/bigmod: Explicitly Clear Expanded Limbs on Reset. https://go-review.googlesource.com/c/go/+/655056
2025
-
[32]
Challenges in Survey Re- search
Felix A. Wolf, Linard Arquint, Martin Clochard, Wytse Oortwijn, João Carlos Pereira, and Peter Müller. 2021. Gobra: Modular Specification and Verification of Go Programs. InCA V (LNCS, Vol. 12759). Springer, 367–379. doi:10.1007/978-3- 030-81685-8_17
-
[33]
Jean Karim Zinzindohoué, Karthikeyan Bhargavan, Jonathan Protzenko, and Benjamin Beurdouche. 2017. HACL*: A Verified Modern Cryptographic Library. InCCS. ACM, 1789–1806. doi:10.1145/3133956.3134043 9
discussion (0)
Sign in with ORCID, Apple, or X to comment. Anyone can read and Pith papers without signing in.