- The paper provides a complete Lean-based formalization of Shor's algorithm that rigorously verifies quantum attacks on RSA-2048 and P-256 with concrete resource estimates.
- It details an agentic workflow that integrates mathematical proofs, quantum circuit design, and classical post-processing to achieve end-to-end verification.
- The work offers practical cryptanalytic insights by establishing explicit bounds on qubits, Toffoli gates, and circuit depth for both RSA-2048 and P-256 attacks.
Overview
The paper "Building Shor's Algorithm in Lean: An Agentic Formalization of Quantum Attacks on RSA-2048 and P-256" (2607.14082) provides a rigorous Lean formalization of the mathematical reductions, quantum circuits, and classical post-processing procedures for Shor-type attacks against two cryptographically significant problems: integer factorization for RSA-2048 and discrete logarithms for the standardized P-256 elliptic curve. The methodology leverages agentic formalization, wherein software agents undertake decompositional proof development and source aligning, with verification established via the Lean proof assistant and oversight by domain experts.
Agentic formalization orchestrates artifact flow from mathematical claims and literature sources through decomposition, Lean code generation, machine-checking, and integration into manuscript claims. This division enforces a trust boundary, ensuring that all formalized components—including quantum and classical operations—are subject to Lean's kernel checking, while resource measures and scientific judgment remain with human curators.

Figure 1: Agentic formalization workflow, delineating the trust boundary and the responsibilities for claim selection, source analysis, Lean code development, machine checking, human review, and integration.
The approach directly supports modular provenance tracing in formal libraries, making theorem assumptions, dependencies, and composability accessible to both software agents and researchers.
Main Results: Resource-Explicit Quantum Cryptanalysis
RSA-2048 Factorization
The formalization covers the quantum-to-classical chain in integer factorization for RSA-2048, encompassing order-finding circuits, reversible modular arithmetic, factor recovery via continued fractions, and resource tallies—logical qubits, Toffoli gates, circuit depth, and classical operations. The principal theorem states that a quantum algorithm constructed via Lean returns a prime factor d∈{p,q} with a probability ≥$2/3$, bounded by 6.19×103 logical qubits, 8.1×109 Toffoli gates, 6.42×109 circuit depth, and 3.69×104 classical arithmetic steps. These parameters originate from the Ekerå–Håstad short discrete logarithm construction and gate-level analysis [gidney2019factor].
P-256 Elliptic-Curve Discrete Logarithm
For P-256, the formalization extends to affine prime-field arithmetic, elliptic-curve operations, controlled point additions, and scalar recovery, integrating circuit-level resource estimates. The corresponding theorem certifies scalar recovery with probability ≥$2/3$, using 2.33×103 logical qubits, 1.26×1011 Toffoli gates, 1.16×1011 maximal Toffoli-gate depth, with only $2/3$0 classical operations required for post-processing, as obtained from gate-level analysis [roetteler2017ecdlp].
Machine-Checked Proof Chain and Modular Abstraction
The Lean development constructs reusable abstractions bridging number-theoretic reductions, quantum circuit semantics, classical validation (e.g., continued fractions, GCDs), and explicit resource accounting. Proof obligations are decomposed into:
- Modular circuit arithmetic—reversible addition, multiplication, exponentiation, and division;
- Quantum circuit scheduling—controlled modular exponentiation, phase estimation, quantum Fourier transform, and coherent group actions for discrete logs;
- Post-processing—continued fraction validation, classical recovery checks, candidate solution selection;
- Resource certificates—logical qubit footprint, Toffoli gate counts, maximal circuit depth, and classical operation budgets.
All steps are formalized and verified in Lean, with interfaces permitting explicit bridges, certificates, and resource provenance.

Figure 2: Dependency map of Lean formalization for RSA-2048 and P-256, showing implemented paths (solid) and certificate boundaries/interfaces (dashed) culminating in terminal public theorems.
The paper situates its formalization among prior works in quantum-program verification (Qbricks, Qafny, Coq/CoqQ, Quantum Hoare Logic), noting that Lean achieves end-to-end coverage: constructing gate-level arithmetic, order-finding, success probability bounds, quantum and classical resources, and requiring no abstract arithmetic oracles for its claims.
Strong numerical results are explicitly stated:
- RSA-2048 attack: $2/3$1 Toffoli gates, $2/3$2 circuit depth for three sequential attempts, with success ≥$2/3$3.
- P-256 attack: $2/3$4 Toffoli gates, depth $2/3$5, $2/3$6 qubits per run, success ≥$2/3$7.
These claims contradict the often asymptotic resource descriptions seen elsewhere, providing concrete, machine-checked tuples compatible with cryptanalytic simulation and benchmarking.
Practical and Theoretical Implications
The modular, agentic approach supports future automation of quantum cryptanalysis, with explicit mathematical and circuit-level provenance. The Lean formalization lays a foundation for AI-assisted quantum algorithm design and verification, enabling retrieval, schematic comparison, and reuse of theorem components. The work exposes certificate boundaries for resource claims and output equality, highlighting explicit assumptions and supporting reproducibility and auditability.
Extensions and implications include:
- Integration of resource analysis from approximate arithmetic and fault-tolerant quantum architectures (e.g., LDPC code-based reduction, space-efficient arithmetic circuits).
- Expansion of formal coverage to other cryptographically relevant algorithms (e.g., ECC variants, alternate number-theoretic schemes).
- Systematic derivation of correctness, probability distributions, and resource models from unified formal executions, given only public cryptographic data.
Conclusion
The paper achieves a robust Lean-based formalization of quantum attacks against RSA-2048 and P-256, recording both mathematical reductions and high-fidelity circuit resource estimates. Modular abstractions, agentic source decomposition, and certificate-bound claims collectively advance the reliability and auditability of quantum cryptanalytic modeling. Future directions target integration of circuit noise, fault-tolerance, and space-depth tradeoffs within formal systems, fostering deeper connections between quantum algorithm verification and cryptanalytic benchmarking.