Repository navigation
cryptificate init, doctor and a cryptificate.json project configuration - #12
Merged
Merged
Conversation
…n-zero Actions runs a composite step's bash with -e, so a policy failure (exit 1) or an error (exit 2) of cryptificate check ended the step before it wrote the SARIF and JUnit files and the exit-code and outcome outputs, and the later steps saw no result. The exit status is now captured with || and the report renderings, which exit with the recorded policy's status, no longer stop the step. A test runs the step with bash -e against the fake engine.
Without input arguments, cryptificate check reads the nearest cryptificate.json (the working directory or a parent), or the file named with --config: inputs, failOn, claims, target, format, output and bundleDir. Paths in the file are relative to its directory, and so are the input paths in the result and the SARIF locations. Options on the command line override the file; inputs on the command line replace it, and then the file is not read unless --config names it. The file is validated against the keys and values of the new schemas/project-config.schema.json; an unknown key, a wrong value or an unknown claim id is a usage error (exit 2) that lists every problem with its JSON Pointer. A test keeps the schema and the validator in step.
The inputs input is no longer required. Left empty, the action runs cryptificate check without input arguments, so the inputs, the policy and the claim scope come from the nearest cryptificate.json; its format, output and bundleDir are replaced by the action's result files. fail-on now defaults to empty: the file's failOn when inputs is empty, otherwise refuted as before, so existing workflows keep their policy.
…orkflow cryptificate init [dir] writes cryptificate.json (inputs, failOn, the claim scope and bundleDir), a starting design under cryptificate/designs taken from the example designs (aes, aes-row-scaled, poseidon2-bn254), optionally with the example's reference circuit as a request file, a short README and .gitignore for the folder, and .github/workflows/cryptificate.yml, which runs the action on pull requests that touch these files and uploads the SARIF result to code scanning. On a terminal it asks for the model, the starting design, the circuit, the policy and the workflow, and confirms the file list; --model, --preset, --circuit/--no-circuit, --fail-on, --ci and --action answer from the command line, and --yes or a non-terminal stdin takes the defaults. It writes nothing when one of its files exists, unless --force is given. In a subdirectory of a git repository the workflow goes to the repository root with working-directory set. The claim scope is the model's design claims and, with a circuit, circuit.equivalence and native.correctness; rust.refinement and native.timing are left out. Tests check the presets against the example files and run check on a freshly scaffolded project.
…ixes doctor checks Node.js 20 or later, elan, that the Lean toolchain pinned in lean/lean-toolchain is installed, lake, the Mathlib build, that lake build Cryptificate is up to date (lake build --no-build, which builds nothing and is not started while the pinned toolchain is missing), that the engine reports the Cargo workspace version, has the subcommands check needs and the native backend and is not older than crates/, rustc, that the state directory is writable, the free disk space there, and whether a service answers at --url. Each failed or warned check carries the command that fixes it. Exit 0 when no check failed, 1 otherwise; --json prints the checklist as cryptificate-doctor/v1. Tests use a fake elan, lake and engine and injected probes for the service, the disk and Node.js.
The README's start section shows the three commands an adopter runs in their own repository. The adopter guide gains a section on init (questions, flags, the files written and the claim scope) and describes each doctor check, which problems are warnings and which are failures. docs/ci.md describes the project configuration, its precedence over and under command-line options, and the action's new defaults for inputs, fail-on and claims.
…he repository root check records in its JSON result the directory that the input paths are relative to (base: the working directory, or the directory of cryptificate.json when the inputs came from it). report resolves the input paths of a saved check result against it, so a result written with the config in a parent directory still finds its files and keeps the line regions of its SARIF locations. check, verify and report take --uri-base DIR, which makes SARIF file locations relative to DIR instead of the working directory. The action passes --uri-base "$GITHUB_WORKSPACE", so the locations are relative to the repository root, as code scanning reads them, when working-directory is a subdirectory (as init writes it) or the config is in a parent of it.
check took the policy none when cryptificate.json set no failOn, so the action with empty inputs and fail-on never failed the job, not even on a refuted claim. A loaded cryptificate.json now defaults the policy to refuted, which is also the action's default with explicit inputs; a failOn or --fail-on in force still wins, and without the file the command-line default stays none. The action logs a warning when the policy in force is none.
The workflow written by init now emits working-directory, the paths filters and the push branch as YAML double-quoted strings, so a directory name with "#", ": ", quotes or a leading "*", "&", "!" or "[" stays one string. The push trigger names the default branch recorded for the origin remote (refs/remotes/origin/HEAD), else main or master when the repository has one, else the branch checked out, instead of falling back to main. A .git file (a linked worktree or a submodule) is followed to its git directory and to the common directory that holds the refs.
The cd commands doctor prints for the Mathlib cache, the certificate library, the engine build and the local service now quote the checkout path for a POSIX shell, so they work when it holds spaces or shell characters.
A question left without a valid answer (end of input, or five invalid answers) cancels init with exit status 2; the usage line named only usage errors and existing files.
…fault of cryptificate.json docs/ci.md says how the action places SARIF locations at the repository root, that working-directory only sets where the command runs, that check results record the base of their input paths and report resolves against it, that failOn defaults to refuted in cryptificate.json, and that the action warns under the policy none. The adopter guide states where the SARIF locations point after init in a subdirectory and how the push branch is chosen.
Resolve the overlap with the branches merged before it, as in the release/v0.2.0 integration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #10 (
feat/ci-gate); review and merge that one first.Summary
Adopting Cryptificate in another repository now takes three commands:
cryptificate initscaffolds a checked project and its GitHub workflow,cryptificate doctorsays what is missing on the machine and how to fix it, andcryptificate checkwith no arguments applies the project'scryptificate.json. The GitHub Action reads the same file when itsinputsis empty, so one file holds the inputs, the policy and the claim scope for local runs and for CI.The branch also fixes a bug in the action on
feat/ci-gate: Actions runs a composite step's bash with-e, so whencryptificate checkexited 1 (policy failed) or 2 (error), the step stopped before it wrote the SARIF and JUnit files and theexit-code/outcomeoutputs. The repository's ownactionCI job, which expectsexit-code1 for the refuted design, would have failed on that.Review fixes on this branch: the action's SARIF locations are now relative to the repository root, also when
working-directoryis a subdirectory (asinitwrites it) orcryptificate.jsonis in a parent of it; acryptificate.jsonwithoutfailOngates onrefutedinstead of silently disabling the gate; the workflow quotes its paths for YAML and names the repository's default branch; doctor's fix commands quote paths for the shell; the usage text lists every init exit 2 case.Base:
feat/ci-gate. Twelve commits:fix:keep the action's check step going when check or report exits non-zerofeat(server):check reads its inputs and policy from cryptificate.jsonfeat:the GitHub Action reads cryptificate.json when inputs is emptyfeat(server):cryptificate init scaffolds a checked project and its workflowfeat(server):cryptificate doctor checks the machine and prints the fixesdocs:describe init, doctor and cryptificate.jsonfix(server):place SARIF locations from the recorded input base and the repository rootfix:a cryptificate.json without failOn gates on refuted claimsfix(server):init quotes workflow paths and finds the default branchfix(server):doctor quotes the paths in its fix commandsdocs(server):list every init exit status 2 case in the usage textdocs:describe --uri-base, the recorded input base and the refuted default of cryptificate.jsonWhat is proved / changed (precise)
No Lean code, Lean theorem, template, claim, acceptance rule or engine code changes. What a claim's status is, and how it is established, is unchanged. Nothing new is proved. The changes affect which inputs are checked and which policy applies, and they add setup tooling.
cryptificate.jsonandcheck(apps/server/src/project.ts,schemas/project-config.schema.json)inputs(required),failOn,claims,target,format,output,bundleDir,$schema(ignored). Unknown keys are rejected.checkwith no input arguments uses the nearestcryptificate.jsonin the working directory or a parent.--config FILEnames the file explicitly; its settings then also apply to inputs given on the command line. When inputs are given without--config, no file is read, even an invalid one.failOndefaults torefutedwhen acryptificate.jsonis in use (found, or named with--config). Without the file the command-line default staysnone.check --format jsonresult (cryptificate-check/v1) gains an optionalbasefield: the absolute directory its relative input paths are relative to (the config's directory, or the working directory for command-line inputs).reportresolves the input paths of a saved check result againstbase, so it finds the files (and gives SARIF locations their line regions) from any working directory; the results it writes name the inputs relative to its own working directory. A saved result withoutbaseis read as before, relative to the working directory.check,verifyandreporttake--uri-base DIR: SARIF file locations are made relative toDIR(resolved against the working directory) instead of the working directory; a file outside it gets afile://URI, as before.FAIL_ON, formats, targets, every known claim id).verifyandreportdo not read the file.Action (
action.yml)inputsis no longer required. When it is empty, the action runscheckwithout inputs, so the inputs come fromcryptificate.json. The action still passes--format json --output … --bundle-dir …, which replace the file'sformat,outputandbundleDir.fail-onnow defaults to empty. With emptyinputsthe action passes no--fail-on, so the file'sfailOnapplies (refutedif the file sets none). With explicitinputsit passes--fail-on refuted, as before, so existing workflows keep their policy. When the policy in force isnone(set explicitly), the step logs a::warning::.report … --format sarifis run with--uri-base "$GITHUB_WORKSPACE", so the SARIF locations are relative to the repository root, which is how code scanning reads them, whateverworking-directoryis and wherevercryptificate.jsonsits above it.-efix:node … || code=$?, andreport … || truefor the SARIF and JUnit renderings, which exit with the recorded policy's status.init [dir](init.ts,presets.ts,prompt.ts)cryptificate.json,cryptificate/designs/<preset>.json,cryptificate/README.md,cryptificate/.gitignore(evidence/) and, with--ci github(the default),.github/workflows/cryptificate.yml.aes,aes-row-scaled(bothaes-like) andposeidon2-bn254(hades). Each is identical to a file inexamples/designs, and a test checks this; the AES-like presets therefore have 4 rounds. With--circuit, the design file is a request file that also holds the example's reference circuit:aes-known-shared-sum, orposeidon2-external-shared-sumfor the external matrix.circuit.equivalenceandnative.correctnesswhen a circuit is included.rust.refinementis left out: the action does not build the refinement proofs, and for BN254 the claim is unsupported.native.timingis left out because only experiments measure it.workflow_dispatch. The push branch is the origin remote's default branch when git has recorded it (refs/remotes/origin/HEAD), elsemainormasterwhen the repository has one (loose or packed ref), else the branch checked out, elsemain; a.gitfile (linked worktree, submodule) is followed to its git directory and itscommondir. It hassecurity-events: writeand uses4waan/Cryptificate@mainwithupload-sarif: "true"and noinputs.--action OWNER/REPO@SHApins it. Inside a git repository, the workflow goes to the repository root; when the init directory is a subdirectory,working-directoryis set and the path filters are prefixed with it.working-directory, the path filters and the branch are written as YAML double-quoted strings (JSON string syntax).--yesis not given, init asks for the model, the preset, the circuit (only when the preset has one), the policy and the workflow, then confirms the file list. Flags answer their own questions. With a non-terminal stdin or--yes, init takes the defaults (aes, no circuit,refuted, a workflow) without asking.--forceis given. Exit status: 0 written, 1 declined at the prompt, 2 usage error, existing file, or a question left without a valid answer (end of input or five invalid answers); the usage text now says so.doctor(doctor.ts)enginesinpackage.json.lean/lean-toolchainpin appears inelan toolchain list.Mathlib.oleanis present.lake build --no-build Cryptificateexits 0. It is skipped while lake, the pinned toolchain or Mathlib is missing, so elan never downloads a toolchain as a side effect.--versionequalscryptificate-engine <Cargo workspace version>; it hasvalidate,diagnoseandemit-lean(a failure otherwise); it hasnative(a warning otherwise); its mtime is not older thancrates/**/*.rs,Cargo.tomlorCargo.lock(a warning otherwise).GET <url>/api/capabilities(defaulthttp://127.0.0.1:4173): a warning when the service is unreachable or runs a different checker version, becausecheck,verifyandreportdo not need the service.cd …commands are quoted for a POSIX shell when they hold characters other than letters, digits and_/.,:@%+=-. The command exits 0 when no check failed and 1 otherwise.--jsonprintscryptificate-doctor/v1.Docs: README "Start in one step" (own-repository commands) and "Use it in CI";
docs/adopter-guide.mdgets the doctor checks after install, a new section 2 on init (including where the SARIF locations point after init in a subdirectory and how the push branch is chosen), and the later sections renumbered;docs/ci.mdgets a new "Project configuration" section (therefuteddefault offailOn, the recordedbase) and updates the action input defaults, theworking-directoryrow, the gate options (--uri-base) and thecheckargument description; the schema'sfailOndescription; the help text of the command;apps/server/README.md.Tests run
npm ci(worktree).npm run build: exit 0 (schema, server, web).npm test: exit 0.packages/schema: 14 pass. The new schema file passes the existing$id/$schema/$reftest.apps/server: 90 pass, 5 skipped. The skipped tests are the existing integration tests, which needCRYPTIFICATE_INTEGRATION=1and a built Lean library.apps/web: 53 pass.project.test.ts(8): validator, schema agreement, lookup from a subdirectory, precedence,--config, error messages, therefuteddefault of a file withoutfailOn(andnonewithout the file), andreporton a result saved with the config in a parent directory: the recordedbase, line regions found fromsub/deeper,--uri-baseforreportandcheck, input paths rewritten relative toreport's directory.init.test.ts(8): presets equal the examples, non-interactive init followed bycheckon the scaffolded project (pass, then exit 1 after adding a weak design), refusal to overwrite and--force, the interactive flow on a stream withisTTY(re-ask, decline, end of input,--yes), the git-subdirectory workflow, usage errors, the default-branch choice (checked-outdevelop, packedmaster,origin/HEAD→trunk, a linked worktree withcommondir, a malformed.gitfile), and a directory named*odd #dir: "x" [y]whoseworking-directoryand path filters parse back to the exact strings.doctor.test.ts(6): fake elan, lake and engine, with injected service, disk and Node probes;shellQuoteround-trips paths with spaces, quotes,;,&&,$and backticks throughbash -c.action.test.ts(4): extracts the "Check the inputs" step fromaction.ymland runs it withbash -eagainst the built command and the fake engine. One test fails on the base branch'saction.yml, which confirms the-ebug. The other cases: config-driven inputs and policy, a config withoutfailOn(refuted, exit 1, no warning) and thenonewarning; working-directorycrypto/under the workspace (SARIF uricrypto/cryptificate/designs/identity.jsonwith a region, for config and explicit inputs); config insub/with working-directorysub/deeper(resultbaseissub, SARIF urisub/designs/identity.jsonwith a region, JUnit names../designs/identity.json).python3 -m unittest discover -s python/tests -t python: OK. The Python client is unchanged; this run is a sanity check.cryptificate init --yes --preset aes --circuitin a scratch git repository, thencryptificate checkwith the real engine and Lean (CRYPTIFICATE_ROOTset to a built checkout). Exit 0 in about 30 s: all six in-scope claims proved, including 9,214 native correctness cases; a bundle was written tocryptificate/evidence/.cryptificate initon a real pseudo-terminal (script): the answers were read and the process exited cleanly.cryptificate doctorin this worktree, whose Lean library is not built. It reportedlake build Cryptificate is not up to datewith the fix, warned that the engine binary is older than the checked-outcrates/sources, warned that no service was running, and exited 1.cargo test --workspace,lake build,check_examples.pyandclaims.py --check. No Rust, Lean, example or refinement file changed.Scope and limits
apps/server/dist/src/cli.js; the docs show an alias.initanddoctordo not install anything;doctorprints the commands, andscripts/setup.shinstalls everything.crates/without changing it gives a warning, never a failure. The engine version check compares--versionagainst the Cargo workspace version, so it cannot detect two builds of the same version from different sources.scripts/setup.shrun needs several GB more.doctorwrites and removes a probe file in an existing state directory. lake may refresh its own configuration cache underlean/.lakewhen it answers--no-build.inituses4waan/Cryptificate@mainunless--actionpins a SHA; init prints a reminder. Itspull_requestpath filter coverscryptificate.jsonandcryptificate/**only; inputs added elsewhere need the filter extended, as a comment in the file says.claims. An input of the other model family (for example a HADES design under an AES-like scope) is an error (exit 2) under a policy, asdocs/ci.mdalready describes.refs/remotes/origin/HEADand withoutmainormastergets the branch checked out at init time, which may not be the default branch. The adopter guide says to check it in the written workflow. Path filters are GitHub glob patterns, so a directory name containing*,?,[or!is quoted correctly for YAML but still read as a glob by GitHub's filter.--uri-baseand the recordedbaseare plain path arithmetic (path.relative/path.resolve); symbolic links between$GITHUB_WORKSPACEand the working directory are not resolved. On GitHub-hosted runners the workspace path has none.baseis an absolute path of the machine that rancheck; a result moved to another machine falls back to resolving against the original absolute paths, which then do not exist there (the SARIF locations then lose their regions, as any missing file does).Generated by Claude Code