← Latest papers
💻 computer science

GCD: Garbled, Corrected, Demonstrandum -- Fixing and Proving Go's Extended GCD Implementation

This paper identifies and fixes two critical deviations in Go's extended GCD implementation that compromise RSA key generation, subsequently proving the corrected code's correctness and termination using the Gobra and Lean verification tools while demonstrating how AI agents can assist in refining formal proofs.

Original authors: Linard Arquint

Published 2026-06-05
📖 4 min read☕ Coffee break read

Original authors: Linard Arquint

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are building a high-security digital vault (like the ones used for online banking or secure messaging). To lock and unlock this vault, you need a very specific, complex mathematical key. In the world of computer science, this key is generated using a recipe called the Extended Greatest Common Divisor (GCD) algorithm.

This paper is about a team of researchers who went into the "kitchen" of the Go programming language (a popular tool used to build software) to check if the recipe for this key was being followed correctly. They found that the recipe had been slightly altered, and they fixed it while proving mathematically that the new version works perfectly.

Here is the story of their discovery, broken down into simple parts:

1. The "Copy-Paste" Mistake

The Go developers wanted to update their software to meet strict government security standards. To do this, they took a recipe from a trusted, well-known source called BoringSSL (a secure library used by Google) and "ported" it (translated it) into Go.

Think of it like a famous chef giving you a secret recipe for a cake. You decide to rewrite the recipe in your own handwriting to make it easier to read. The paper claims that while rewriting it, the Go developers accidentally changed two important steps.

  • The Problem: The original recipe had a strict rule: "If you add these two numbers, and the result is too big, you must subtract a specific amount from both numbers at the exact same time." This keeps the cake from collapsing.
  • The Bug: The Go version did this "too big" check separately for each number. It was like checking the flour and the sugar independently. This broke the mathematical balance (the "invariants") that guarantees the key is correct.
  • The Surprise: Three different human experts reviewed the code and missed this mistake. It was so subtle that it slipped through the net.

2. The "Too Big" Ingredient

The second issue was about the size of the ingredients allowed.

  • The Rule: The original recipe said, "The first ingredient must always be smaller than the second."
  • The Change: The Go version allowed the first ingredient to be bigger than the second.
  • The Fix: The researchers didn't need to change the code for this one. Instead, they had to update the "proof" (the mathematical guarantee) to show that the recipe still works even with the bigger ingredients.

3. The Magic Detective (Gobra)

To prove they fixed the bugs, the researchers used a tool called Gobra.

  • The Analogy: Imagine a super-strict, hyper-attentive robot inspector. You feed it the code and a list of rules (specifications). The robot doesn't just run the code; it simulates every possible way the code could run, checking every single path to ensure it never breaks the rules.
  • The Result: The robot confirmed that once the "synchronization bug" was fixed, the code was 100% correct. In fact, because the fix removed unnecessary steps, the new code actually ran 24% faster than the buggy version.

4. The AI Assistant

The researchers didn't do all the heavy lifting alone. They used an AI agent (a smart computer program) to help them.

  • How it worked: The AI acted like a tireless apprentice. When the robot inspector (Gobra) said, "This part doesn't make sense," the AI would suggest changes to the rules or the code.
  • The Catch: The AI initially assumed the code was perfect and tried to force the math to fit. The human researchers had to tell the AI, "No, the code is actually wrong; look for the difference." Once the AI understood that, it became incredibly helpful, suggesting fixes and helping write the mathematical proofs.

5. The Takeaway

The paper concludes with three main lessons:

  1. Even experts make subtle mistakes: Three human reviewers missed a critical bug that a formal proof tool found.
  2. Formal verification is powerful: Using a tool like Gobra is like having a mathematical guarantee that your code works, rather than just hoping it works because it passed a few tests.
  3. AI is a great partner: AI can help humans write these complex proofs, but humans still need to guide the AI to question the code rather than just accept it.

In short: The researchers found a hidden flaw in a critical security algorithm in Go's standard library, fixed it, proved mathematically that the fix works, and showed that the fix actually made the software faster. They did this using a combination of human insight, automated proof tools, and AI assistance.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →