Repository navigation
DSA parameter search on RISC-V - #4278
Conversation
2b8b3a2 to
3341ab6
Compare
3341ab6 to
6df7185
Compare
|
This pull request has conflicts with Posted by |
Implementation, framework, controller, entry, dispatch, prime test and hash pieces; key-space, seed and finish proofs still in progress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…(work in progress) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
… and the contract (work in progress) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…r check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…tration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…m table Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
6df7185 to
c03979e
Compare
…n the contract Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…SA modules it uses (work in progress) Main's dead-code removals (#4305, #4336, #4344, #4367) deleted RISC-V modules and declarations that only this search uses. Restore them as they were before each removal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…me_out beside their use #4344 removed them from Proof/Rsa/RISCV64/KeyLayout.lean as dead; only this search uses them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…s a module of its own Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…rch does not need restored Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
…lean, which the search does not need restored Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
|
What is going on here? Why have you had to punish innumerable times to get passing CI? What local validations are you not doing that you're supposed to... |
Regenerated with the full emitter (lake env lean --run Emit.lean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
|
You're right. This was my process failing, not CI. After rebasing onto
Each of those pushes started a full CI run that was certain to fail, and was then cancelled by the next push.
From now on I push once per change, and only after that whole list passes locally. If Generated by Claude Code |
|
This pull request has conflicts with Posted by |
Resolves the conflict with #4508: src/dsa/parameters/search.rs and its tests take main's dispatchers, and riscv64 joins search.rs's module gate. The RISC-V crate is regenerated with the full emitter, which picks up #4514's Montgomery code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
|
This pull request has conflicts with Posted by |
The RISC-V crate's generated dsa.rs conflicted: it takes main's side and is regenerated with the full emitter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
|
This pull request has conflicts with Posted by |
The RISC-V crate's generated dispatch/dsa.rs conflicted: it takes main's side and is regenerated with the full emitter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
|
This pull request has conflicts with Posted by |
Since #4654 the emitter reads no registration file under Generic/, so the search's registration moves to Artifacts/DsaParameters/RISCV64.lean, as PPC64LE's, mapping over Proof.Variants.MillerRabin.RISCV64.variants. The RISC-V crate's generated dispatch/dsa.rs conflicted: it takes main's side and is regenerated with the full emitter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
|
This pull request has conflicts with Posted by |
- Registration: since #4794 an algorithm's registrations on a target are one file, and since #4806 a registration states no features, so the search joins Artifacts/Dsa/RISCV64.lean as PPC64LE's does, mapping over Proof.Variants.MillerRabin.RISCV64.variants. - #5059 folded Blinded/CTBase.lean, then imported only by RsaKeyGen/RISCV64/Cand/CTMr.lean, into CTMr. This PR restores CTBase.lean (8781344^), which the restored modules and the DSA prime test import too, so CTMr.lean is its version before #5059 again, importing CTBase instead of declaring its theorems a second time. - Blinded/Witness.lean and Search/MontPrep.lean stay byte-identical to 8781344^, without the text merge of #5048's omega rewrites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
|
This pull request has conflicts with Posted by |
The RISC-V crate's generated vg_rsa_keygen_candidate.rs conflicted after #5099, which prints each straight-line instruction as bytes: it takes main's side, and the crate is regenerated with the full emitter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
Since #5121 registration files never state `stack`: the search's registration drops `stack := 512`, which the default, `stack_of`, finds in the contract `params_verified` proves. The generated crates are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
#4278 restored the RISC-V Miller–Rabin search to main (`Impl/MillerRabin/RISCV64/Search.lean`, `Proof/MillerRabin/RISCV64/Search/`) with the same definitions this branch had kept as FFDH-only copies. Those copies go: the candidate uses main's definitions and main's `montPrep_ok`, `r2Any_r2Ok` and `roundCall_ct`. Only the sieve's proofs, which main lacks, stay, in their one user `ParameterCandidate/Shape.lean`. The registration no longer states `stack` (#5121). The regenerated crate takes `vg_miller_rabin_round` from DSA's module, where #4278 put it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHEKNw8eCDhgbwoFBL
`wp_seq_assoc` and `wp_block_prefix_seq` are main's, in `Proof/MillerRabin/RISCV64/Core.lean` since #4278; the local copies go. `mask_sub` stays: main's is about Miller–Rabin's own `mask`, not `ModExpWin`'s `Win.mask`, which these proofs use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHEKNw8eCDhgbwoFBL
This ports the refillable-tape DSA parameter search to RISC-V (riscv64gc, base RV64GC only, no new CPU-feature variants). It adds
vg_dsa_parameter_search_initandvg_dsa_parameter_search, proven againstSpec.Dsa.parameterInitContractandSpec.Dsa.parameterSearchContract, the bounded-request form from #4266. Before this, RISC-V had no DSA parameter generation.This was stacked on #4234, which has now been squash-merged into
main. The branch was restacked ontomain, rebased after the PPC64LE, i686, AArch64 and ARMv7 parameter searches (#4293, #4295, #4297, #4296), and has since hadmainmerged into it (as of2798ece9), so the diff is only the RISC-V port. It builds on #4234's Rust driver (src/dsa/parameters/search.rs,entropy::serve) and its target-independent lemmas (Proof/Dsa/Generation/RefillSeed.lean,RefillSearch.lean,GeneratorCount.lean).There are no changes to
TCB/orSpec/. Outside the RISC-V DSA and Miller–Rabin code it changes one file,Proof/RsaKeyGen/RISCV64/Cand/CTMr.lean(see "Restored from main's history").Code (
Impl/Dsa/RISCV64/)ParameterSearch.lean:codesaves the caller's registers inscratch's header and dispatches onstate[1]to one search per width (1024/160 with SHA-1, 2048/256 and 3072/256 with SHA-256), then restores them.searchruns seeds over the one tape. A seed is:qand its probable-prime test;pcandidates and their tests;hcandidates from the tape after the seed's witnesses;vg_dsa_check_parameters.finishwritesout,usedandstateand returns 0, 1 or 3.Entropy.request's formula (2 · max(available, 256 · p_len), capped at the budget), as on x86-64.initwrites[4096, p_len, 32769 · p_len, 512 · p_len].ProbablePrime.lean:vg_dsa_probable_prime_{160,256,1024,2048,3072}, internal functions that run trial division (TrialTable32), then the witnesses through the shared Miller–Rabin round (Variants/MillerRabin/RISCV64).Proofs
Target-independent:
Proof/Dsa/Generation/RefillTraj.lean. The controller's trajectory over the tape:pos, the position after each iteration, anditers, the number of iterations;stAt, each iteration's status, andres_pos, the spec's result as seen from a position.The iteration count is a function of public data, which the constant-time argument for the loop uses.
Prime tests:
Proof/Dsa/RISCV64/Prime/.CorrectandCTlead toVerifiedagainstProof.Dsa.ProbablePrime.contract(stack ≤ 512).The search:
Proof/Dsa/RISCV64/PSearch/. It follows PPC64LE'sProof/Dsa/PPC64LE/Gen/, with pieces that are proven correct and constant time together (VP):Base,Frame,Bytes: the call's public parameters, the header's words, the states of the search and the copies withinscratch;Entry,Ctl,Top,Finish: the entry and exit, the controller's loop (loop_vp), the dispatch andfinish, withFinishproving that the request meets the bound (requested_requests);Hash/HashInst/Pre,QPart,PX/PArith/PPart,KS/Power/GCheck: one seed's q, p and generator;Attempt: one seed againstrefillAttempt(attempt_ok);Verified:body_vp,code_ok,code_ctandsearch_verified, withSatas the precondition's witness;Instances: the three widths (geoOk1–3) andparams_verified.Init:
Proof/Dsa/RISCV64/ParameterSearchInit.leanprovesinit_verified.Hygiene: the proofs use no
sorry,native_decide,bv_decide, new axioms ormaxHeartbeats, and every declaration fits the default heartbeat limit.Registration
Artifacts/Dsa/RISCV64.leanaddsparameterInitApi, andparameterSearchApifor each RISC-V Miller–Rabin implementation, mapping overProof.Variants.MillerRabin.RISCV64.variants(only the baseline exists), asArtifacts/Dsa/PPC64LE.leandoes. It states noconsts(they come from the contract,TrialTable32), nofeatures(TCB: an artifact's CPU features are those its code requires #4806) and nostack(Registration files never state stack #5121): the contractparams_verifiedproves gives 512. The search was registered in a file of its own until Variants are lists; generic callers are ordinary registration files #4654 and Registrations: one file per algorithm and target #4794 made generic callers part of their algorithm's one registration file per target.lake env lean --run Emit.lean). The sharedvg_miller_rabin_roundnow lives in thedsamodule, andvg_rsa_keygen_candidaterefers to it there.python3 ci/algorithms_table.pymarks DSA parameter generation as supported on RISC-V.Restored from main's history
While this PR was open,
main's dead-code sweeps removed RISC-V code that only this PR now uses. It is restored here, and only what this PR reaches. Every restored or reverted file is byte-identical to its last version onmain(git show <commit>^:<path>), but for the one line noted below. Nothing inTCB/,Spec/orProof/Framework/changed to fit them. Where a file still exists onmainbut lost declarations this PR uses, it is reverted to that version only wheremain's version fails to build with this PR (tested file by file;Search/Sieve.leanandSearch/Prep.leankeepmain's).878134437), restored from878134437^:Impl/MillerRabin/RISCV64/Blinded.lean;Proof/MillerRabin/RISCV64/Blinded/Ctx.lean,Load.lean,LoadCT.lean,LoopCT.lean,Round.lean,RoundCT.lean,WitnessCT.lean;Proof/MillerRabin/RISCV64/Blinded/CTBase.lean, which FFDH/Miller-Rabin: remove dead declarations and modules #4336 cut down and Proofs: fold 2,650 modules into the one module that imports each #5059 then folded into its only importer onmain,Proof/RsaKeyGen/RISCV64/Cand/CTMr.lean. Here CTBase has several importers again (the restored modules and the DSA prime test), soCTMr.leanis its version before Proofs: fold 2,650 modules into the one module that imports each #5059 (9ab920bf4^), importingCTBaserather than declaring its two theorems a second time;Impl/MillerRabin/RISCV64/Search.lean,Proof/MillerRabin/RISCV64/Blinded/Loop.lean,Witness.lean,Proof/MillerRabin/RISCV64/Search/MontPrep.lean,RoundCallCT.lean. They keep plainomegawheremain's Proofs: give omega the facts it needs at each call #5048 rewrote it asomega_using, which a text merge would have mixed into code it was not compiled with.577fc2022), restored from577fc2022^:Proof/Dsa/RISCV64/ParamsVerified.lean(vg_dsa_check_parameters'Verified) andParamsImplies.lean.ParamsVerified.leangains one line,-- separate module: …, whichcheck_lean_single_importernow requires.dd2337b51):Rsa.RISCV64.Keys.Frame.outsideandWs.frame_out, fromProof/Rsa/RISCV64/KeyLayout.lean. Their two declarations are copied intoProof/Dsa/RISCV64/PSearch/KS.lean, their only user, rather than restoring the module.bc1b10f67):Bignum.wordsVal_frame, fromProof/Bignum/PackedRead.lean. Its one-line proof is copied intoProof/Dsa/RISCV64/PSearch/Bytes.lean, its only user.Rust
The Rust and tests are unchanged except for their architecture gates. Since #4508, the search calls the generated dispatchers (
vg_dsa_parameter_search_auto,vg_dsa_parameter_search_init_auto), so RISC-V needs no backend choice of its own:riscv64is added to the module gates ofsrc/dsa/parameters.rsandsearch.rs, and tobench/benches/primitives/dsa_parameters.rs.src/dsa.rsre-exportsParameterson riscv64 too: its#[cfg(not(target_arch = "riscv64"))], there because RISC-V had no parameter generation, is gone.The existing CAVP known-answer test, the error tests and the searcher's own tests now run on RISC-V. No tests were added, split or weakened.
Checks
Run on the head before pushing it (
3254d73b):lake buildand the full emitter, then its--check;Static checksstep, withcheck_lean_single_importer --base origin/main;ci/check_lean_public_imports.pyon the 48 changed and restored Lean files: "Imports OK (45 modules)";ci/rust_lint.py run libraryforriscv64gc-unknown-linux-gnuand x86-64, andrun benchmarksfor x86-64. The RISC-V benchmarks lint needs a RISC-V OpenSSL, which CI's lint image has;CI time
From this PR's CI run at
3254d73b, after mergingmainat2798ece9(run 43764275937).Rust: job "Rust (Linux, RISC-V, host)"
(a) Tests this change enables on RISC-V: 16.05 CPU-seconds, summed from the job log's per-test times:
dsa::parameters::tests::cavp_generated_parametersdsa::parameters::tests::generated_parameters_with_os_randomnessdsa::parameters::tests::generation_widthsdsa::parameters::tests::parameter_generation_errorsdsa::parameters::search::tests::stepsdsa::parameters::search::tests::init_wordsThe library's unit-test binary took 15.94 s of wall time, so
cavp_generated_parametersis its longest test (the next,sha384'sincremental, took 4.4 s). Earlier runs of the same tests took 15.2 to 19.2 CPU-seconds, which is the board's speed varying between runs.(b) Wall time against
main: this job took 241 s. The last 6 successful merge-queue runs of the same job onmaintook 238, 241, 242, 247, 254 and 255 s, a median of 244.5 s. That is 3.5 s (1.4%) less: the 16 s the new tests take is within the 25–45% that the RISC-V board's speed varies between runs.(c) Against the other Rust jobs: RISC-V is the longest Rust job in this run. The next longest, "Rust (native, ubuntu-26.04-arm, arm)", took 149 s, so the RISC-V job's 241 s is 162% of it.
Lean: job "Lean: plan and build"
The PR's Lean build rebuilt 82 modules on top of
main's cache: 223 CPU-seconds, summed from the log's per-module times, in an 86 s build step on 6 threads. The job took 241 s;main's last 6 merge-queue runs took 25 to 259 s, depending on what their own merges changed, so they are not like for like. Of the 223 CPU-seconds:PSearch/Power(13 s) andPSearch/GCheck(10 s);Search/MontPrep(10 s) andBlinded/Witness(6 s);CTMr.leanand the registration among them), the largestRsaKeyGen/RISCV64/Cand/Setup(7 s), with the emitter.That is a one-time cost of the PR's own CI run: once merged, these modules are in
main's cache, and only a change to them or to what they import rebuilds them.Where the time goes
cavp_generated_parametersruns the three published vectors. Theirpsearches take 326, 106 and 858 candidates, as their counters say, and 39, 17 and 103 of those composites survive trial division. Each survivor costs one Miller–Rabin round, and each acceptedpcosts the spec'sprimeChecks: 64 rounds up to 2048 bits and 128 at 3072. Weighting each modexp by about the cube of its width, about 97% of the test is these rounds, about 89% at 3072 bits. Trial division, hashing and the candidates' arithmetic come to about 3 modexps' worth.Impl/Bignum/RISCV64/MontMul.lean,MontSqr.lean), not code this PR adds.Benchmark
Benchmarks run 43762540697 on
b65ad795:arches: riscv64,modules: dsa,groups: dsa_generate_parameters, with no base, since RISC-V had no parameter generation before. It ran only the parameter-generation group, because this PR leaves the DSA key and signature functions' code unchanged. Each size searches from its median tape (#4301): of the seedsbitstobits + 8, the one whose search is the median.dsa_generate_parameters/1024dsa_generate_parameters/2048dsa_generate_parameters/3072The head's medians are tight (each 95% interval within 0.7% of the median), since it searches the same tape every time. OpenSSL draws its own candidates on every run, so its times spread widely (at 2048 bits, a 95% interval of 4.7 to 8.0 s around its median), and the comparison is not like for like. The current head,
3254d73b, only dropsstack := 512from the registration after mergingmain: the generated RISC-V crate is byte-identical tob65ad795's, so the run measures it.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A