guldo-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- guldo/__init__.py +0 -0
- guldo/_src/COMPILER.md +329 -0
- guldo/_src/DEPLOY.md +200 -0
- guldo/_src/LAUNCH.md +85 -0
- guldo/_src/PROTOCOL.md +294 -0
- guldo/_src/RULES.md +25 -0
- guldo/_src/SUBMIT.md +170 -0
- guldo/_src/__init__.py +0 -0
- guldo/_src/attest.py +257 -0
- guldo/_src/build_site.py +958 -0
- guldo/_src/bundle_templates/check.py +1382 -0
- guldo/_src/bundle_templates/qcheck.py +253 -0
- guldo/_src/bundle_templates/qscore.py +402 -0
- guldo/_src/bundle_templates/score.py +649 -0
- guldo/_src/certificate.py +828 -0
- guldo/_src/certs_site.py +108 -0
- guldo/_src/claims.py +343 -0
- guldo/_src/compile_domain.py +1312 -0
- guldo/_src/compile_quality.py +286 -0
- guldo/_src/count_runner.py +248 -0
- guldo/_src/counted.py +274 -0
- guldo/_src/declared.py +215 -0
- guldo/_src/deploy/Caddyfile +48 -0
- guldo/_src/deploy/ledger-backup.service +9 -0
- guldo/_src/deploy/ledger-backup.sh +73 -0
- guldo/_src/deploy/ledger-backup.timer +10 -0
- guldo/_src/deploy/ledger-export.service +12 -0
- guldo/_src/deploy/ledger-export.timer +9 -0
- guldo/_src/deploy/ledger-web.service +38 -0
- guldo/_src/deploy/pin_cpu.sh +34 -0
- guldo/_src/deploy/provision_eval.sh +128 -0
- guldo/_src/deploy_smoke.py +148 -0
- guldo/_src/dlog_experiment.py +165 -0
- guldo/_src/domains/aidecode/compiled.json +586 -0
- guldo/_src/domains/aidecode/decl.py +134 -0
- guldo/_src/domains/aidecode/reference.py +73 -0
- guldo/_src/domains/aiinfer/compiled.json +722 -0
- guldo/_src/domains/aiinfer/decl.py +91 -0
- guldo/_src/domains/aiinfer/reference.py +42 -0
- guldo/_src/domains/dlog/compiled.json +248 -0
- guldo/_src/domains/dlog/decl.py +41 -0
- guldo/_src/domains/dlog/reference.py +10 -0
- guldo/_src/domains/maxcut/compiled.json +291 -0
- guldo/_src/domains/maxcut/decl.py +46 -0
- guldo/_src/domains/maxcut/reference.py +16 -0
- guldo/_src/drift_check.py +89 -0
- guldo/_src/export_bundle.py +750 -0
- guldo/_src/extrapolate.py +326 -0
- guldo/_src/families.py +53 -0
- guldo/_src/gen_cheat_table.py +36 -0
- guldo/_src/gpu_meter.py +634 -0
- guldo/_src/gpu_runner.py +63 -0
- guldo/_src/harness.py +273 -0
- guldo/_src/instances.py +86 -0
- guldo/_src/instances_factor.py +40 -0
- guldo/_src/instances_mlwe.py +69 -0
- guldo/_src/judge.py +278 -0
- guldo/_src/limits_plan.py +158 -0
- guldo/_src/official.py +189 -0
- guldo/_src/ops.py +281 -0
- guldo/_src/portal.py +313 -0
- guldo/_src/portal_core.py +57 -0
- guldo/_src/power.py +174 -0
- guldo/_src/prereg.py +173 -0
- guldo/_src/public_portal.py +500 -0
- guldo/_src/quality_core.py +126 -0
- guldo/_src/recheck.py +236 -0
- guldo/_src/remeasure.py +88 -0
- guldo/_src/report_html.py +493 -0
- guldo/_src/results/.keep +0 -0
- guldo/_src/rounds.py +846 -0
- guldo/_src/runner.py +52 -0
- guldo/_src/sandbox/Dockerfile +11 -0
- guldo/_src/sandbox/Dockerfile.v2 +19 -0
- guldo/_src/sandbox/README.md +40 -0
- guldo/_src/sandbox/linux_selftest.py +117 -0
- guldo/_src/sandbox/meter.py +89 -0
- guldo/_src/sandbox/meter_core.py +28 -0
- guldo/_src/site_assets.py +176 -0
- guldo/_src/site_live_check.py +79 -0
- guldo/_src/solvers/aidecode_flops_kv.py +73 -0
- guldo/_src/solvers/aidecode_flops_lossy.py +73 -0
- guldo/_src/solvers/aidecode_flops_ref.py +64 -0
- guldo/_src/solvers/aidecode_kv.py +76 -0
- guldo/_src/solvers/aidecode_kv_f32.py +77 -0
- guldo/_src/solvers/aidecode_lossy.py +76 -0
- guldo/_src/solvers/aidecode_repeat.py +5 -0
- guldo/_src/solvers/aiinfer_batched.py +40 -0
- guldo/_src/solvers/aiinfer_f32.py +41 -0
- guldo/_src/solvers/aiinfer_gpu_batched.py +42 -0
- guldo/_src/solvers/aiinfer_gpu_ref.py +45 -0
- guldo/_src/solvers/aiinfer_lossy.py +42 -0
- guldo/_src/solvers/baseline_bkz.py +14 -0
- guldo/_src/solvers/cheat_lookup.py +24 -0
- guldo/_src/solvers/cheat_table.json +1 -0
- guldo/_src/solvers/cheat_table_v1_stale.json +1 -0
- guldo/_src/solvers/daemon_cpu_hider.py +17 -0
- guldo/_src/solvers/dlog_bsgs.py +19 -0
- guldo/_src/solvers/dlog_stride4.py +18 -0
- guldo/_src/solvers/egg_base.py +11 -0
- guldo/_src/solvers/egg_eightaxis.py +68 -0
- guldo/_src/solvers/egg_template.py +11 -0
- guldo/_src/solvers/factor_brent.py +34 -0
- guldo/_src/solvers/factor_floyd.py +19 -0
- guldo/_src/solvers/factor_trial_fast_py.py +21 -0
- guldo/_src/solvers/factor_trial_np.py +21 -0
- guldo/_src/solvers/factor_trial_py.py +12 -0
- guldo/_src/solvers/fixed_overhead_ref.py +21 -0
- guldo/_src/solvers/fork_bomb.py +18 -0
- guldo/_src/solvers/gpu_noop.py +6 -0
- guldo/_src/solvers/hostile_probe.py +36 -0
- guldo/_src/solvers/kill_meter.py +27 -0
- guldo/_src/solvers/memory_bomb.py +10 -0
- guldo/_src/solvers/noop.py +5 -0
- guldo/_src/solvers/orphan_cpu_hider.py +16 -0
- guldo/_src/solvers/planted_peek.py +23 -0
- guldo/_src/solvers/sleeping_daemon_hang.py +12 -0
- guldo/_src/solvers/small_n_trick.py +22 -0
- guldo/_src/solvers/starter_template.py +21 -0
- guldo/_src/solvers/stdout_flood.py +9 -0
- guldo/_src/solvers/tmp_fill.py +10 -0
- guldo/_src/solvers/tuned_bkz.py +25 -0
- guldo/_src/static_check.py +214 -0
- guldo/_src/submit_check.py +166 -0
- guldo/_src/svp.py +889 -0
- guldo/_src/tensorops.py +304 -0
- guldo/_src/tflops.py +453 -0
- guldo/_src/tflops_runner.py +134 -0
- guldo/cli.py +60 -0
- guldo_cli-0.1.0.dist-info/METADATA +30 -0
- guldo_cli-0.1.0.dist-info/RECORD +134 -0
- guldo_cli-0.1.0.dist-info/WHEEL +5 -0
- guldo_cli-0.1.0.dist-info/entry_points.txt +2 -0
- guldo_cli-0.1.0.dist-info/top_level.txt +1 -0
guldo/_src/RULES.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Competition rules (DRAFT, version draft-1)
|
|
2
|
+
|
|
3
|
+
**This is a draft written by the developer of the software, not legal advice. The operator must decide the bracketed items and
|
|
4
|
+
have the text reviewed before publishing it. The submission form refers to it as "draft-1".**
|
|
5
|
+
|
|
6
|
+
1. **What you submit.** One Python file that defines `solve` for the round's family (see the Compete page). You may submit up to 3
|
|
7
|
+
files per round under one handle. You need the file's rights to submit it.
|
|
8
|
+
2. **How it is run.** While a round is open your file is only parsed, never run. After the round closes it is run in a sandbox
|
|
9
|
+
without network or file access, on instances generated from seeds whose hashes were published before the round opened, against
|
|
10
|
+
a reference solver, with a CPU cap per instance. The seeds are revealed after evaluation.
|
|
11
|
+
3. **What counts.** Credit is a statistical lower bound on speedup, taken as the minimum over at least three seeds (PROTOCOL.md).
|
|
12
|
+
A result the method cannot separate from noise is reported as inconclusive. [Prize, if any, and how it is decided: operator to fill in.]
|
|
13
|
+
4. **Fair play.** Do not try to leave the sandbox, read the judge's files or seeds, hide CPU use from the meter, detect that you are
|
|
14
|
+
being measured, or attack the service. Such a submission is disqualified and may be reported. Do not test against the live
|
|
15
|
+
service for vulnerabilities without the operator's written permission; [security contact: operator to fill in].
|
|
16
|
+
5. **What is published.** Your handle, the SHA-256 of each file, the time it was received and its result are public and permanent
|
|
17
|
+
(the log is append-only). Your source is published after the seeds are revealed **only if you tick the box** when you submit.
|
|
18
|
+
[Licence you grant for the source you choose to publish: operator to choose.]
|
|
19
|
+
6. **What is collected.** The handle and the file. No account, email or IP address is stored by this software. The operator's web
|
|
20
|
+
server or proxy may keep its own logs: [operator to state].
|
|
21
|
+
7. **Your token.** The token shown at your first submission is the only proof a handle is yours. We cannot recover it.
|
|
22
|
+
8. **Removal.** Before the deadline you cannot withdraw a submission from the log (that would defeat the log), but you can submit
|
|
23
|
+
another. After the reveal you may ask for your published source to be removed; its hash stays in the log.
|
|
24
|
+
9. **No guarantee.** Results are measurements on specific hardware and may be provisional or inconclusive. The operator may pause,
|
|
25
|
+
cancel or rerun a round, and says so in the log when it does. [Governing law and venue: operator to fill in.]
|
guldo/_src/SUBMIT.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Submit a solver and verify the result, from the command line
|
|
2
|
+
|
|
3
|
+
Everything below is `svp.py`: standard library only, one file, no browser. It talks to a round's public service (`public_portal.py`) over
|
|
4
|
+
HTTP(S) and checks everything it can on your own machine.
|
|
5
|
+
|
|
6
|
+
python3 svp.py --help
|
|
7
|
+
|
|
8
|
+
It needs Python 3.9 or newer on macOS or Linux (the protocol code it shares with the operator tools uses POSIX file locking; Windows is not supported).
|
|
9
|
+
Set the server once: `export SVP_SERVER=https://ledger.example.org` (or pass `--server` each time). Your receipts and tokens are kept in
|
|
10
|
+
`$SVP_HOME` (default `~/.svp`, mode 0600).
|
|
11
|
+
|
|
12
|
+
## 1. Try your solver first (no server)
|
|
13
|
+
|
|
14
|
+
python3 submit_check.py my_solver.py --family dlog # lint + well-formed on tiny public practice questions (seconds)
|
|
15
|
+
python3 svp.py practice my_solver.py --family dlog # prints the plan and its cost, runs nothing
|
|
16
|
+
python3 svp.py practice my_solver.py --family dlog --yes --n 12 --budget 60
|
|
17
|
+
|
|
18
|
+
`practice` evaluates your solver on three seeds **of your own** in bare local mode, builds a certificate, and verifies it. The result is
|
|
19
|
+
PROVISIONAL by construction (you knew the seeds, and nothing ran in the sandbox), but it is a real, re-checkable file: `svp.py verify FILE`.
|
|
20
|
+
It writes only the certificate; the temporary ladders and seeds it creates are removed.
|
|
21
|
+
|
|
22
|
+
## 2. Submit to a round
|
|
23
|
+
|
|
24
|
+
svp.py rounds # what the server runs
|
|
25
|
+
svp.py round winter-1 # deadline, family, the seed fingerprints, who has submitted
|
|
26
|
+
svp.py submit my_solver.py --round winter-1 --handle alice --accept-rules [--publish-source]
|
|
27
|
+
|
|
28
|
+
What `submit` does, in order: lints your file locally (so a rejection costs nothing), reads the round and refuses unless it is open, uploads, then
|
|
29
|
+
**checks the server's answer instead of trusting it**: the hash the server stored must equal the hash of your file, and your receipt must appear
|
|
30
|
+
in the server's public log, whose hash chain it verifies itself. It saves the receipt, and the handle's token (shown once), on your machine.
|
|
31
|
+
|
|
32
|
+
* `--accept-rules` is required: you confirm you read `RULES.md`.
|
|
33
|
+
* `--publish-source` makes your source public after the seeds are revealed, and your public certificate carries it, so anyone can re-run it. **Without it your
|
|
34
|
+
solver stays private** (see "Private solvers" below): the public certificate carries only its hash.
|
|
35
|
+
* A handle already used in the round needs its token (saved automatically on the machine you first submitted from, or `--token`).
|
|
36
|
+
* Your file is read, never run, while the round is open. It runs only after the round closes, in the sandbox, on seeds committed before it opened.
|
|
37
|
+
|
|
38
|
+
## 3. Follow it
|
|
39
|
+
|
|
40
|
+
svp.py status --round winter-1 # your submissions in that round (from your receipts)
|
|
41
|
+
svp.py status --round winter-1 --wait 3600 # poll until it is evaluated; prints only when something changes
|
|
42
|
+
|
|
43
|
+
## 4. Verify the result
|
|
44
|
+
|
|
45
|
+
After the operator evaluates the round and reveals the seeds, a certificate exists for each evaluated submission:
|
|
46
|
+
|
|
47
|
+
svp.py verify --round winter-1 --id <your id>
|
|
48
|
+
|
|
49
|
+
This downloads the certificate and checks, on your machine:
|
|
50
|
+
|
|
51
|
+
| check | what it shows |
|
|
52
|
+
|---|---|
|
|
53
|
+
| server: round revealed / same seed fingerprints | the certificate is for this round and names the fingerprints the round published |
|
|
54
|
+
| server: log matches | the certificate's log is **the server's own published log**, so the operator is not showing different logs to different people |
|
|
55
|
+
| your receipt | the file that was evaluated is the file you uploaded, and your logged entry is in the certificate's log |
|
|
56
|
+
| rules, sources, domain, log, seeds, ladders, coverage, credit | everything `certificate.py verify` checks: the questions are exactly the seeds', the fingerprints were public before any submission, the credit follows from the recorded timings |
|
|
57
|
+
|
|
58
|
+
The last line says whether the timings were measured in **the Docker sandbox or in bare local mode (then at most PROVISIONAL)**, and what the
|
|
59
|
+
check does not prove. Exit status: 0 verified, 1 a check failed, 2 could not do it (not ready, network, usage). `--json` gives the same as data.
|
|
60
|
+
|
|
61
|
+
svp.py verify cert.json # a certificate file you already have: no server, no network
|
|
62
|
+
svp.py verify --round winter-1 --id <id> --rerun 5 --execute # also re-measure 5 instances here (throwaway VM only!)
|
|
63
|
+
svp.py certificate --round winter-1 --id <id> --out mine.cert.json
|
|
64
|
+
svp.py certificate --round winter-1 --id <id> --full # YOUR full certificate, with your source (needs your token)
|
|
65
|
+
|
|
66
|
+
`--execute` runs code from the certificate (the declaration, and with `--rerun` the solvers) on your machine, **unsandboxed**. Use a throwaway
|
|
67
|
+
VM. `--rerun` picks its instances from a random draw of your own, so the operator cannot know which ones you will re-measure.
|
|
68
|
+
|
|
69
|
+
## Provable costs: step counting
|
|
70
|
+
|
|
71
|
+
Seconds on someone's machine cannot be proved: they depend on the hardware, the load and a sandbox you have to trust. A **count** can. In counted mode the
|
|
72
|
+
cost of a question is the number of Python bytecode instructions the solver executes (`count_runner.py`, using `sys.monitoring`, Python 3.12+). A deterministic
|
|
73
|
+
program on the same input gives the same number on any machine running the same Python version, so a verifier does not trust anyone's hardware or clock: it
|
|
74
|
+
re-executes and compares, and equality is the proof. (A solver that depends on memory addresses, the clock or randomness does not count the same twice;
|
|
75
|
+
`practice --count` checks for that before it spends any time and refuses to certify it.)
|
|
76
|
+
|
|
77
|
+
svp.py practice my_factorer.py --family factor --count --dims 38 40 42 --n 8 --cap 40 --yes # a counted run on three seeds of your own
|
|
78
|
+
svp.py verify my.dlog.practice.cert.json --rerun 5 --execute # re-execute 5 questions of BOTH solvers: counts must be IDENTICAL
|
|
79
|
+
python3 counted.py check my_factorer.py --family factor --dim 38 --cap 40 # is this solver deterministic here? (run it twice)
|
|
80
|
+
|
|
81
|
+
`factor` is the family to start with: its baseline (`solvers/factor_trial_py.py`, trial division) is plain Python, so its counts mean something; the smaller factor
|
|
82
|
+
has about half the bits of N, so at 38-42 bits it should cost roughly 2 to 17 counted seconds per question (an estimate from reading the loop, not yet measured),
|
|
83
|
+
above the estimator's 0.5 floor with room to spare, and under the cap of 40; a solver a few times faster still clears the floor. (At 36 bits it is marginal.) `solvers/factor_trial_fast_py.py` is a ready-made example (6k+/-1 trial division): `make practice-count SOLVER=solvers/factor_trial_fast_py.py`. The lattice
|
|
84
|
+
families (`gm`, `mlwe`) are refused in counted mode, because their baseline is fpylll (work inside C).
|
|
85
|
+
|
|
86
|
+
What a counted certificate proves: the arithmetic and the fairness as before, and, for every instance you re-run, that the recorded cost is **exactly**
|
|
87
|
+
what that program executes (no tolerance, no clock, no sandbox). The instances you do NOT re-run are covered only statistically: someone who falsified a
|
|
88
|
+
fraction f of the records escapes K random checks with probability (1-f)^K, and the verdict says how many of how many you re-ran. For certainty re-run all
|
|
89
|
+
of them: `--rerun all` (it costs about as much as the original run, and the verdict then has no "covered only statistically" remainder). The instances
|
|
90
|
+
checked are your own random draw by default (printed in the verdict), so the prover cannot know which ones to make honest. `practice --count` refuses a solver or interpreter whose count changes between two identical
|
|
91
|
+
runs before it spends any time. A different Python version is a SKIP with the reason, because instruction counts are only comparable on the same one.
|
|
92
|
+
|
|
93
|
+
What it cannot do, and the verdict says it every time:
|
|
94
|
+
* **It is not a time.** Bytecode instructions are not seconds. A "counted second" is only a unit (one million instructions), chosen so the estimator's
|
|
95
|
+
0.5-second floor is reachable: a size counts only if the solver's typical cost there is at least 0.5, so the baseline needs a few counted seconds
|
|
96
|
+
(the default cap is 20). Pick `--dims` accordingly, or every size is dropped and the credit is inconclusive.
|
|
97
|
+
* **It is blind to work inside C functions.** `pow(a, b, m)` on huge integers, `sorted`, `sum`, numpy and fpylll each cost ONE instruction however long they
|
|
98
|
+
run, so a solver can hide its work in a C call. A counted result means something only when the work is in Python code on both sides; do not use it to
|
|
99
|
+
compare an algorithm that leans on C builtins with one that does not.
|
|
100
|
+
* **The ladder is the prover's, unless a round declared it.** Counting is roughly 100x slower than running, so counted ladders use small sizes and a small cap. For
|
|
101
|
+
your own `practice --count` run they are chosen by you, so it is **not** an official round result. In a **counted round** (`svp.py round ID` shows
|
|
102
|
+
"cost model: STEP COUNTING") the operator committed the sizes, the questions per size, the cap, the Python version and the counting program in the round's first
|
|
103
|
+
log entry before any submission: everyone is counted on the same ladder, every source is public, and anyone can re-execute any count with `svp.py verify
|
|
104
|
+
--round ID --id X --rerun all --execute` on that Python (throwaway VM). Its status is `COUNTED`, not `OFFICIAL`: it is not a timing in a verified sandbox.
|
|
105
|
+
Test your solver first with `python3 counted.py check my_solver.py --family factor --dim 38`: a solver whose count changes between two runs, or that reads
|
|
106
|
+
anything outside its arguments, will not reproduce.
|
|
107
|
+
* **A counted solver is written in a restricted subset of Python**: pure computation (loops, arithmetic, lists/dicts/sets, classes, generators, `print`, the common
|
|
108
|
+
exceptions), with imports only from `math`, `itertools`, `heapq`, `bisect`, `functools`, `collections` and `fractions` (each exposing named functions only). No `sys`,
|
|
109
|
+
`os`, files, `getattr`/`type`/`eval`/`open`, dunder or underscore attributes, `str.format` (use f-strings or `%`), frame or traceback access. The counter enforces this
|
|
110
|
+
itself, and `practice --count` and `svp.py submit` tell you what is outside it before spending any time. Top-level code is counted too, so precomputing at import
|
|
111
|
+
time costs what it costs. This is a sandbox for the counter's own integrity; it is still wise to run other people's certificates in a throwaway VM.
|
|
112
|
+
|
|
113
|
+
## Private solvers
|
|
114
|
+
|
|
115
|
+
Submit without `--publish-source` and your algorithm stays out of public view. After the reveal, the public certificate for your submission is a
|
|
116
|
+
**private-solver certificate**: it has no source and no failure messages (a crash message is a traceback, and a traceback quotes your code), and keeps
|
|
117
|
+
everything else, including your solver's hash, which the round's log committed to before the seeds were revealed. Anyone can download it without a
|
|
118
|
+
token and `svp.py verify` it: the log, the fingerprints, the questions, the rules and the credit arithmetic all check out.
|
|
119
|
+
|
|
120
|
+
An operator can make publishing mandatory for a round (`ops.py round-new --require-source`): that is a public rule in the round's first log entry, shown by
|
|
121
|
+
`svp.py round ID`, and `svp.py submit` then refuses to upload without `--publish-source`.
|
|
122
|
+
|
|
123
|
+
What a private solver costs, and the verdict says it every time:
|
|
124
|
+
* **Nobody but the operator can inspect or re-run it.** The timings therefore rest on the operator's sandbox alone (whose tests have passed on real Linux machines, but not yet on a dedicated
|
|
125
|
+
evaluation machine separate from the web service), not on anyone re-measuring them. `--rerun` skips with that reason.
|
|
126
|
+
* **It is hidden from the public, not from the operator**, who ran your file. Hiding it from the operator too would need trusted hardware or a
|
|
127
|
+
zero-knowledge proof of execution; neither is feasible for solvers that run for minutes.
|
|
128
|
+
* **What still leaks.** Your solver's hash is public (it is in the log), so a very short or highly guessable file could be confirmed by someone guessing
|
|
129
|
+
candidates: put a long random comment in the file if that matters. And the certificate carries the raw timing of every instance, so anyone can see how
|
|
130
|
+
your solver's cost grows with problem size (that is what a speedup claim is), though not how it works.
|
|
131
|
+
* Attestations of a private-solver certificate are marked as weaker evidence.
|
|
132
|
+
* The static-check warnings (they name line numbers, modules and calls your file uses) are shown to you when you submit and are **not** published for a
|
|
133
|
+
private solver.
|
|
134
|
+
|
|
135
|
+
If you publish your file later (a gist, a repository, anywhere), anyone can upgrade the check:
|
|
136
|
+
|
|
137
|
+
svp.py verify --round winter-1 --id <id> --source my_solver.py # hash-check it against the committed value
|
|
138
|
+
svp.py verify --round winter-1 --id <id> --source my_solver.py --rerun 5 --execute # and re-measure it (throwaway VM)
|
|
139
|
+
|
|
140
|
+
`--source` must match the **exact bytes** you submitted: it hashes the file and compares it with the hash in the certificate and the log. A different
|
|
141
|
+
file, or the same file with different line endings, is refused. Once it matches, the certificate is as strong as one whose source was published from the
|
|
142
|
+
start. `svp.py practice ... --private` writes the same kind of certificate for your own local runs.
|
|
143
|
+
|
|
144
|
+
## What the client refuses to do
|
|
145
|
+
|
|
146
|
+
* send your token or source over plain `http` to a remote host (loopback is fine; `--allow-insecure-http` overrides);
|
|
147
|
+
* send your token anywhere except a resubmission under that handle and your own full certificate (`--full`): downloading the public certificate,
|
|
148
|
+
private-solver or not, never involves it;
|
|
149
|
+
* follow a redirect (it would forward your token); accept more than 16 MiB from the server (64 MiB for a certificate), or wait more than 2 minutes
|
|
150
|
+
(15 for a certificate) for one response; print server text unfiltered;
|
|
151
|
+
* upload anything if it cannot keep your receipt and token afterwards (an unwritable `--home` is refused BEFORE the upload, because the token is shown only
|
|
152
|
+
once); and if saving fails after an accepted upload anyway, the receipt and token are printed to the screen so you can write them down;
|
|
153
|
+
* save a receipt whose fields are not exactly the shape a real receipt has, or reset a damaged `receipts.json` (it says so and changes nothing, because
|
|
154
|
+
the file may hold the only copy of a token). Two `svp.py` processes at once do not overwrite each other: the store is locked;
|
|
155
|
+
* overwrite a certificate, or submit without `--accept-rules`.
|
|
156
|
+
|
|
157
|
+
## For operators
|
|
158
|
+
|
|
159
|
+
After `ops.py reveal`, run `ops.py certs --data D --id ROUND --seed-dir S` (DEPLOY.md, "Round lifecycle"). For a submission whose owner published their
|
|
160
|
+
source it builds one public certificate. For every other submission it builds two: a **public private-solver copy** (no source, no failure text) that
|
|
161
|
+
anyone may download, and the **full certificate**, served only to the handle's token at `/api/cert-full/`. Both are stored only if they verify, and
|
|
162
|
+
`ops.py export` publishes the public ones next to the round's log, never the full ones. Without a verified sandbox no round can be evaluated officially,
|
|
163
|
+
so every certificate a real round produces today would come from a sandbox that has never passed its self-test on a real host: say so to your users,
|
|
164
|
+
and be aware that for a private solver there is nothing else they can check the timings against.
|
|
165
|
+
|
|
166
|
+
## What this does and does not prove
|
|
167
|
+
|
|
168
|
+
Verification proves the arithmetic and the fairness. It does not by itself prove that the recorded timings are what a real run took: that rests on
|
|
169
|
+
the sandbox (never yet run on a real host) and on independent re-measurement (`--rerun`, attestations from people you trust: `attest.py`). The
|
|
170
|
+
certificate says which measured it.
|
guldo/_src/__init__.py
ADDED
|
File without changes
|
guldo/_src/attest.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"""Independent attestations of a speedup certificate: signed statements from people who checked it themselves.
|
|
2
|
+
|
|
3
|
+
python3 attest.py keygen --out my.key a new Ed25519 key (never overwritten); prints the public key to publish
|
|
4
|
+
python3 attest.py sign x.cert.json --key my.key --out x.my.att.json [--rerun 5 --execute] [--tolerance 1.0]
|
|
5
|
+
python3 attest.py check x.cert.json a1.json a2.json [--trusted keys.txt]
|
|
6
|
+
|
|
7
|
+
`sign` runs certificate.verify on YOUR machine (and, with --rerun --execute, re-measures K instances you pick at random) and signs the outcome,
|
|
8
|
+
the machine it ran on and a hash of the certificate. `check` reads attestation files, verifies each signature and that it is about THIS certificate,
|
|
9
|
+
and reports how many distinct keys agree.
|
|
10
|
+
|
|
11
|
+
What an attestation is worth is exactly what the verifier's identity is worth. A key proves "the same party signed these", never "this party is
|
|
12
|
+
independent of the operator": an operator can mint five keys. So `check` separates attestations by keys listed in --trusted (a file of public
|
|
13
|
+
keys, one hex per line, `# name` allowed, that YOU obtained out of band from people you chose) from all others, which are reported as unvouched
|
|
14
|
+
and never counted as independent. The machine description inside a statement is self-reported. A signed statement that the certificate does NOT
|
|
15
|
+
verify (a dissent) makes `check` fail whoever signed it.
|
|
16
|
+
"""
|
|
17
|
+
import argparse
|
|
18
|
+
import json
|
|
19
|
+
import math
|
|
20
|
+
import os
|
|
21
|
+
import platform
|
|
22
|
+
import re
|
|
23
|
+
import secrets
|
|
24
|
+
import sys
|
|
25
|
+
import time
|
|
26
|
+
|
|
27
|
+
import certificate as K
|
|
28
|
+
|
|
29
|
+
FORMAT = "svp-attestation-v1"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class NeedsCryptography(Exception):
|
|
33
|
+
"""The `cryptography` package is not installed. Signing cannot work; checking reports that signatures could not be verified."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _ed():
|
|
37
|
+
try:
|
|
38
|
+
from cryptography.hazmat.primitives.asymmetric import ed25519
|
|
39
|
+
from cryptography.hazmat.primitives import serialization
|
|
40
|
+
except ImportError:
|
|
41
|
+
raise NeedsCryptography("attest.py needs the `cryptography` package (pip install cryptography) for Ed25519 signatures")
|
|
42
|
+
return ed25519, serialization
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def have_crypto():
|
|
46
|
+
try:
|
|
47
|
+
_ed()
|
|
48
|
+
return True
|
|
49
|
+
except NeedsCryptography:
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def cert_digest(cert):
|
|
54
|
+
return K.sha256(K.canon(cert))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _pub_hex(priv, serialization):
|
|
58
|
+
return priv.public_key().public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw).hex()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def keygen(path):
|
|
62
|
+
ed25519, ser = _ed()
|
|
63
|
+
priv = ed25519.Ed25519PrivateKey.generate()
|
|
64
|
+
raw = priv.private_bytes(ser.Encoding.Raw, ser.PrivateFormat.Raw, ser.NoEncryption())
|
|
65
|
+
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600) # a key is never overwritten
|
|
66
|
+
with os.fdopen(fd, "w") as f:
|
|
67
|
+
f.write(raw.hex() + "\n")
|
|
68
|
+
return _pub_hex(priv, ser)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _load_key(path):
|
|
72
|
+
ed25519, ser = _ed()
|
|
73
|
+
with open(path) as f:
|
|
74
|
+
return ed25519.Ed25519PrivateKey.from_private_bytes(bytes.fromhex(f.read().strip())), ser
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def sign(cert, key_path, rerun=0, execute=False, tolerance=K.RERUN_TOLERANCE, sample_seed=None, note="", now=None):
|
|
78
|
+
priv, ser = _load_key(key_path)
|
|
79
|
+
if rerun and sample_seed is None:
|
|
80
|
+
sample_seed = secrets.randbelow(2 ** 31) # the verifier's own draw: the operator cannot know which instances will be re-measured
|
|
81
|
+
res = K.verify(cert, rerun=rerun, execute=execute, tolerance=tolerance, sample_seed=sample_seed or 0)
|
|
82
|
+
rr = next((c.get("data") for c in res["checks"] if c["check"] == "rerun" and c.get("data")), None)
|
|
83
|
+
stmt = {"format": FORMAT, "cert_sha256": cert_digest(cert), "claim": cert.get("claim"), "verified": res["ok"],
|
|
84
|
+
"checks": [{"check": c["check"], "status": c["status"]} for c in res["checks"]], "rerun": rr, "private_solver": bool(res.get("private")) and not res.get("source_revealed"), "rerun_requested": rerun, "sample_seed": sample_seed if rerun else None, "executed": bool(execute),
|
|
85
|
+
"machine": {"platform": platform.platform(), "machine": platform.machine(), "python": platform.python_version(), "self_reported": True},
|
|
86
|
+
"at": now or time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "note": note, "pubkey": _pub_hex(priv, ser)}
|
|
87
|
+
return {"statement": stmt, "signature": priv.sign(K.canon(stmt).encode()).hex()}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _valid_signature(att):
|
|
91
|
+
ed25519, _ = _ed()
|
|
92
|
+
try:
|
|
93
|
+
pub = ed25519.Ed25519PublicKey.from_public_bytes(bytes.fromhex(att["statement"]["pubkey"]))
|
|
94
|
+
pub.verify(bytes.fromhex(att["signature"]), K.canon(att["statement"]).encode())
|
|
95
|
+
return True
|
|
96
|
+
except Exception:
|
|
97
|
+
return False
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
_NAME_OK = re.compile(r"[A-Za-z0-9 _.:,()/+-]{1,60}") # used with fullmatch: `$` would also accept a trailing newline
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _wellformed(st):
|
|
104
|
+
"""A validly SIGNED statement is still attacker-controlled data (anyone can mint a key). Accept only the exact shape sign() writes and return a
|
|
105
|
+
cleaned copy: verified is a real bool, check names are short plain text (they are printed to terminals), the gap is a finite number or None.
|
|
106
|
+
Anything else raises ValueError and the attestation is ignored, so a hostile one can neither crash a caller nor count as an attestation."""
|
|
107
|
+
if st.get("verified") is not True and st.get("verified") is not False:
|
|
108
|
+
raise ValueError("verified is not a boolean")
|
|
109
|
+
checks = st.get("checks")
|
|
110
|
+
if not isinstance(checks, list) or len(checks) > 200:
|
|
111
|
+
raise ValueError("checks is not a short list")
|
|
112
|
+
cleaned = []
|
|
113
|
+
for c in checks:
|
|
114
|
+
if not isinstance(c, dict) or not isinstance(c.get("check"), str) or not _NAME_OK.fullmatch(c["check"]) or c.get("status") not in ("pass", "fail", "skip", "warn"):
|
|
115
|
+
raise ValueError("a check entry is malformed")
|
|
116
|
+
cleaned.append((c["check"], c["status"]))
|
|
117
|
+
gap, exact = None, None
|
|
118
|
+
rr = st.get("rerun")
|
|
119
|
+
if rr is not None:
|
|
120
|
+
if not isinstance(rr, dict):
|
|
121
|
+
raise ValueError("rerun is malformed")
|
|
122
|
+
if rr.get("exact") is True: # a re-run under STEP COUNTING (counted.py): identical counts, not a timing gap
|
|
123
|
+
nums = [rr.get("k"), rr.get("of"), rr.get("mismatches")]
|
|
124
|
+
if not all(isinstance(x, int) and not isinstance(x, bool) and 0 <= x <= 10 ** 9 for x in nums):
|
|
125
|
+
raise ValueError("rerun is malformed")
|
|
126
|
+
exact = {"k": nums[0], "of": nums[1], "mismatches": nums[2]}
|
|
127
|
+
elif isinstance(rr.get("median_gap_bits"), bool) or not isinstance(rr.get("median_gap_bits"), (int, float)) or not math.isfinite(rr["median_gap_bits"]):
|
|
128
|
+
raise ValueError("rerun is malformed")
|
|
129
|
+
else:
|
|
130
|
+
gap = round(float(rr["median_gap_bits"]), 3)
|
|
131
|
+
return {"verified": st["verified"], "checks": cleaned, "gap": gap, "exact": exact, "private": st.get("private_solver") is True}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def read_trusted(path):
|
|
135
|
+
"""Pinned public keys: one 64-hex Ed25519 key per line, `# name` allowed. A malformed line is refused, never skipped: a typo would silently
|
|
136
|
+
leave a reviewer unpinned and the count of independent attestations would read 0 with no explanation."""
|
|
137
|
+
keys = {}
|
|
138
|
+
with open(path) as f:
|
|
139
|
+
for n, line in enumerate(f, 1):
|
|
140
|
+
line = line.split("#")[0].strip()
|
|
141
|
+
if not line:
|
|
142
|
+
continue
|
|
143
|
+
if len(line) != 64 or any(c not in "0123456789abcdefABCDEF" for c in line):
|
|
144
|
+
raise SystemExit(f"REFUSED: {path} line {n} is not a 64-hex public key: {line[:40]!r}")
|
|
145
|
+
keys[line.lower()] = True
|
|
146
|
+
return keys
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def check(cert, attestations, trusted=None):
|
|
150
|
+
"""-> {"ok": bool, "checks": [...]}. `attestations` are parsed attestation dicts; `trusted` a set of public-key hex strings pinned by the reader."""
|
|
151
|
+
trusted = {k.lower() for k in (trusted or [])}
|
|
152
|
+
if attestations and not have_crypto():
|
|
153
|
+
# never treat an unverifiable signature as either valid or invalid, and never abort a caller (the site build) over it.
|
|
154
|
+
# ok is False: nothing was verified, so a caller (CI, the CLI exit status) must not read this as a pass
|
|
155
|
+
return {"ok": False, "pinned": 0, "unvouched": 0, "checks": [{"check": "attestations", "status": "warn",
|
|
156
|
+
"detail": f"{len(attestations)} attestation file(s) NOT checked: the `cryptography` package is not installed, so no signature could be verified (none is counted, and a dissent among them would not be seen)"}]}
|
|
157
|
+
digest, out = cert_digest(cert), []
|
|
158
|
+
good, dissent, ignored = {}, {}, []
|
|
159
|
+
for i, att in enumerate(attestations):
|
|
160
|
+
label = f"attestation {i + 1}"
|
|
161
|
+
try:
|
|
162
|
+
st = att["statement"]
|
|
163
|
+
if st.get("format") != FORMAT:
|
|
164
|
+
raise ValueError("not an " + FORMAT)
|
|
165
|
+
if not _valid_signature(att):
|
|
166
|
+
ignored.append(f"{label}: signature does not verify")
|
|
167
|
+
continue
|
|
168
|
+
if st["cert_sha256"] != digest:
|
|
169
|
+
ignored.append(f"{label}: signed for a different certificate")
|
|
170
|
+
continue
|
|
171
|
+
key = st["pubkey"].lower()
|
|
172
|
+
clean = _wellformed(st) # a valid signature only proves WHO signed: the contents are still untrusted input
|
|
173
|
+
except (KeyError, TypeError, ValueError, AttributeError) as e:
|
|
174
|
+
ignored.append(f"{label}: unreadable ({type(e).__name__})")
|
|
175
|
+
continue
|
|
176
|
+
(good if clean["verified"] else dissent).setdefault(key, clean) # one vote per key: a key attesting twice is still one party
|
|
177
|
+
for msg in ignored:
|
|
178
|
+
out.append({"check": "attestation ignored", "status": "warn", "detail": msg})
|
|
179
|
+
for key, cl in dissent.items():
|
|
180
|
+
fails = [name for name, status in cl["checks"] if status == "fail"]
|
|
181
|
+
out.append({"check": "dissent", "status": "fail", "detail": f"key {key[:12]}... signed that this certificate does NOT verify (failed: {', '.join(fails) or 'unspecified'})"
|
|
182
|
+
+ (" [pinned key]" if key in trusted else " [unvouched key: anyone can mint one, and the claim is checkable: run `certificate.py verify` yourself]")})
|
|
183
|
+
pinned = [k for k in good if k in trusted]
|
|
184
|
+
other = [k for k in good if k not in trusted]
|
|
185
|
+
gaps = [cl["gap"] for cl in good.values() if cl["gap"] is not None]
|
|
186
|
+
detail = (f"{len(good)} distinct key(s) attest that it verifies: {len(pinned)} from pinned keys (independent by YOUR choice), {len(other)} unvouched "
|
|
187
|
+
"(a key proves nothing about independence from the operator)")
|
|
188
|
+
if gaps:
|
|
189
|
+
detail += f"; {len(gaps)} re-measured the speedup on their own machine, median gaps {gaps} bits (self-reported)"
|
|
190
|
+
exacts = [cl["exact"] for cl in good.values() if cl["exact"] is not None and cl["exact"]["mismatches"] == 0]
|
|
191
|
+
if exacts:
|
|
192
|
+
detail += ("; " + str(len(exacts)) + " re-EXECUTED instances under step counting and got IDENTICAL counts ("
|
|
193
|
+
+ ", ".join(f"{e['k']} of {e['of']}" for e in exacts) + " instances re-run; self-reported by each signer, but anyone can repeat it)")
|
|
194
|
+
blind = sum(1 for cl in good.values() if cl["private"])
|
|
195
|
+
if blind:
|
|
196
|
+
detail += f"; {blind} verified a PRIVATE-SOLVER certificate: they could not inspect or re-run the solver, so that is weaker evidence about the timings"
|
|
197
|
+
status = "pass" if pinned else ("warn" if good else "skip")
|
|
198
|
+
out.append({"check": "attestations", "status": status, "detail": detail if good else "no valid attestation that it verifies"})
|
|
199
|
+
return {"ok": all(c["status"] != "fail" for c in out), "checks": out, "pinned": len(pinned), "unvouched": len(other)}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def main(argv=None):
|
|
203
|
+
try:
|
|
204
|
+
return _main(argv)
|
|
205
|
+
except NeedsCryptography as e:
|
|
206
|
+
raise SystemExit(f"REFUSED: {e}")
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _main(argv=None):
|
|
210
|
+
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
|
211
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
212
|
+
p = sub.add_parser("keygen")
|
|
213
|
+
p.add_argument("--out", required=True)
|
|
214
|
+
p = sub.add_parser("sign")
|
|
215
|
+
p.add_argument("cert")
|
|
216
|
+
p.add_argument("--key", required=True)
|
|
217
|
+
p.add_argument("--out", required=True)
|
|
218
|
+
p.add_argument("--rerun", type=K.rerun_count, default=0, metavar="K|all")
|
|
219
|
+
p.add_argument("--execute", action="store_true", help="runs the certificate's code on this machine, unsandboxed (see certificate.py)")
|
|
220
|
+
p.add_argument("--tolerance", type=float, default=K.RERUN_TOLERANCE)
|
|
221
|
+
p.add_argument("--note", default="")
|
|
222
|
+
p = sub.add_parser("check")
|
|
223
|
+
p.add_argument("cert")
|
|
224
|
+
p.add_argument("attestations", nargs="+")
|
|
225
|
+
p.add_argument("--trusted", help="file of public keys (hex, one per line) you obtained out of band")
|
|
226
|
+
a = ap.parse_args(argv)
|
|
227
|
+
if a.cmd == "keygen":
|
|
228
|
+
try:
|
|
229
|
+
pub = keygen(a.out)
|
|
230
|
+
except FileExistsError:
|
|
231
|
+
raise SystemExit(f"REFUSED: {a.out} exists; a key is never overwritten")
|
|
232
|
+
print(f"wrote {a.out} (keep it private). Publish this public key:\n{pub}")
|
|
233
|
+
return
|
|
234
|
+
with open(a.cert, encoding="utf-8") as f:
|
|
235
|
+
cert = json.load(f)
|
|
236
|
+
if a.cmd == "sign":
|
|
237
|
+
if os.path.exists(a.out):
|
|
238
|
+
raise SystemExit(f"REFUSED: {a.out} exists")
|
|
239
|
+
att = sign(cert, a.key, a.rerun, a.execute, a.tolerance, note=a.note)
|
|
240
|
+
fd = os.open(a.out, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644)
|
|
241
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
242
|
+
json.dump(att, f, indent=1, sort_keys=True)
|
|
243
|
+
s = att["statement"]
|
|
244
|
+
print(f"wrote {a.out}: certificate {'VERIFIES' if s['verified'] else 'does NOT verify'} on this machine" + (f"; re-measured gap {s['rerun']['median_gap_bits']} bits" if s["rerun"] else ""))
|
|
245
|
+
return
|
|
246
|
+
atts = []
|
|
247
|
+
for path in a.attestations:
|
|
248
|
+
with open(path, encoding="utf-8") as f:
|
|
249
|
+
atts.append(json.load(f))
|
|
250
|
+
res = check(cert, atts, list(read_trusted(a.trusted)) if a.trusted else None)
|
|
251
|
+
for c in res["checks"]:
|
|
252
|
+
print(f" {c['status'].upper():4s} {c['check']}: {c['detail']}")
|
|
253
|
+
sys.exit(0 if res["ok"] else 1)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
if __name__ == "__main__":
|
|
257
|
+
main()
|