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.
Files changed (134) hide show
  1. guldo/__init__.py +0 -0
  2. guldo/_src/COMPILER.md +329 -0
  3. guldo/_src/DEPLOY.md +200 -0
  4. guldo/_src/LAUNCH.md +85 -0
  5. guldo/_src/PROTOCOL.md +294 -0
  6. guldo/_src/RULES.md +25 -0
  7. guldo/_src/SUBMIT.md +170 -0
  8. guldo/_src/__init__.py +0 -0
  9. guldo/_src/attest.py +257 -0
  10. guldo/_src/build_site.py +958 -0
  11. guldo/_src/bundle_templates/check.py +1382 -0
  12. guldo/_src/bundle_templates/qcheck.py +253 -0
  13. guldo/_src/bundle_templates/qscore.py +402 -0
  14. guldo/_src/bundle_templates/score.py +649 -0
  15. guldo/_src/certificate.py +828 -0
  16. guldo/_src/certs_site.py +108 -0
  17. guldo/_src/claims.py +343 -0
  18. guldo/_src/compile_domain.py +1312 -0
  19. guldo/_src/compile_quality.py +286 -0
  20. guldo/_src/count_runner.py +248 -0
  21. guldo/_src/counted.py +274 -0
  22. guldo/_src/declared.py +215 -0
  23. guldo/_src/deploy/Caddyfile +48 -0
  24. guldo/_src/deploy/ledger-backup.service +9 -0
  25. guldo/_src/deploy/ledger-backup.sh +73 -0
  26. guldo/_src/deploy/ledger-backup.timer +10 -0
  27. guldo/_src/deploy/ledger-export.service +12 -0
  28. guldo/_src/deploy/ledger-export.timer +9 -0
  29. guldo/_src/deploy/ledger-web.service +38 -0
  30. guldo/_src/deploy/pin_cpu.sh +34 -0
  31. guldo/_src/deploy/provision_eval.sh +128 -0
  32. guldo/_src/deploy_smoke.py +148 -0
  33. guldo/_src/dlog_experiment.py +165 -0
  34. guldo/_src/domains/aidecode/compiled.json +586 -0
  35. guldo/_src/domains/aidecode/decl.py +134 -0
  36. guldo/_src/domains/aidecode/reference.py +73 -0
  37. guldo/_src/domains/aiinfer/compiled.json +722 -0
  38. guldo/_src/domains/aiinfer/decl.py +91 -0
  39. guldo/_src/domains/aiinfer/reference.py +42 -0
  40. guldo/_src/domains/dlog/compiled.json +248 -0
  41. guldo/_src/domains/dlog/decl.py +41 -0
  42. guldo/_src/domains/dlog/reference.py +10 -0
  43. guldo/_src/domains/maxcut/compiled.json +291 -0
  44. guldo/_src/domains/maxcut/decl.py +46 -0
  45. guldo/_src/domains/maxcut/reference.py +16 -0
  46. guldo/_src/drift_check.py +89 -0
  47. guldo/_src/export_bundle.py +750 -0
  48. guldo/_src/extrapolate.py +326 -0
  49. guldo/_src/families.py +53 -0
  50. guldo/_src/gen_cheat_table.py +36 -0
  51. guldo/_src/gpu_meter.py +634 -0
  52. guldo/_src/gpu_runner.py +63 -0
  53. guldo/_src/harness.py +273 -0
  54. guldo/_src/instances.py +86 -0
  55. guldo/_src/instances_factor.py +40 -0
  56. guldo/_src/instances_mlwe.py +69 -0
  57. guldo/_src/judge.py +278 -0
  58. guldo/_src/limits_plan.py +158 -0
  59. guldo/_src/official.py +189 -0
  60. guldo/_src/ops.py +281 -0
  61. guldo/_src/portal.py +313 -0
  62. guldo/_src/portal_core.py +57 -0
  63. guldo/_src/power.py +174 -0
  64. guldo/_src/prereg.py +173 -0
  65. guldo/_src/public_portal.py +500 -0
  66. guldo/_src/quality_core.py +126 -0
  67. guldo/_src/recheck.py +236 -0
  68. guldo/_src/remeasure.py +88 -0
  69. guldo/_src/report_html.py +493 -0
  70. guldo/_src/results/.keep +0 -0
  71. guldo/_src/rounds.py +846 -0
  72. guldo/_src/runner.py +52 -0
  73. guldo/_src/sandbox/Dockerfile +11 -0
  74. guldo/_src/sandbox/Dockerfile.v2 +19 -0
  75. guldo/_src/sandbox/README.md +40 -0
  76. guldo/_src/sandbox/linux_selftest.py +117 -0
  77. guldo/_src/sandbox/meter.py +89 -0
  78. guldo/_src/sandbox/meter_core.py +28 -0
  79. guldo/_src/site_assets.py +176 -0
  80. guldo/_src/site_live_check.py +79 -0
  81. guldo/_src/solvers/aidecode_flops_kv.py +73 -0
  82. guldo/_src/solvers/aidecode_flops_lossy.py +73 -0
  83. guldo/_src/solvers/aidecode_flops_ref.py +64 -0
  84. guldo/_src/solvers/aidecode_kv.py +76 -0
  85. guldo/_src/solvers/aidecode_kv_f32.py +77 -0
  86. guldo/_src/solvers/aidecode_lossy.py +76 -0
  87. guldo/_src/solvers/aidecode_repeat.py +5 -0
  88. guldo/_src/solvers/aiinfer_batched.py +40 -0
  89. guldo/_src/solvers/aiinfer_f32.py +41 -0
  90. guldo/_src/solvers/aiinfer_gpu_batched.py +42 -0
  91. guldo/_src/solvers/aiinfer_gpu_ref.py +45 -0
  92. guldo/_src/solvers/aiinfer_lossy.py +42 -0
  93. guldo/_src/solvers/baseline_bkz.py +14 -0
  94. guldo/_src/solvers/cheat_lookup.py +24 -0
  95. guldo/_src/solvers/cheat_table.json +1 -0
  96. guldo/_src/solvers/cheat_table_v1_stale.json +1 -0
  97. guldo/_src/solvers/daemon_cpu_hider.py +17 -0
  98. guldo/_src/solvers/dlog_bsgs.py +19 -0
  99. guldo/_src/solvers/dlog_stride4.py +18 -0
  100. guldo/_src/solvers/egg_base.py +11 -0
  101. guldo/_src/solvers/egg_eightaxis.py +68 -0
  102. guldo/_src/solvers/egg_template.py +11 -0
  103. guldo/_src/solvers/factor_brent.py +34 -0
  104. guldo/_src/solvers/factor_floyd.py +19 -0
  105. guldo/_src/solvers/factor_trial_fast_py.py +21 -0
  106. guldo/_src/solvers/factor_trial_np.py +21 -0
  107. guldo/_src/solvers/factor_trial_py.py +12 -0
  108. guldo/_src/solvers/fixed_overhead_ref.py +21 -0
  109. guldo/_src/solvers/fork_bomb.py +18 -0
  110. guldo/_src/solvers/gpu_noop.py +6 -0
  111. guldo/_src/solvers/hostile_probe.py +36 -0
  112. guldo/_src/solvers/kill_meter.py +27 -0
  113. guldo/_src/solvers/memory_bomb.py +10 -0
  114. guldo/_src/solvers/noop.py +5 -0
  115. guldo/_src/solvers/orphan_cpu_hider.py +16 -0
  116. guldo/_src/solvers/planted_peek.py +23 -0
  117. guldo/_src/solvers/sleeping_daemon_hang.py +12 -0
  118. guldo/_src/solvers/small_n_trick.py +22 -0
  119. guldo/_src/solvers/starter_template.py +21 -0
  120. guldo/_src/solvers/stdout_flood.py +9 -0
  121. guldo/_src/solvers/tmp_fill.py +10 -0
  122. guldo/_src/solvers/tuned_bkz.py +25 -0
  123. guldo/_src/static_check.py +214 -0
  124. guldo/_src/submit_check.py +166 -0
  125. guldo/_src/svp.py +889 -0
  126. guldo/_src/tensorops.py +304 -0
  127. guldo/_src/tflops.py +453 -0
  128. guldo/_src/tflops_runner.py +134 -0
  129. guldo/cli.py +60 -0
  130. guldo_cli-0.1.0.dist-info/METADATA +30 -0
  131. guldo_cli-0.1.0.dist-info/RECORD +134 -0
  132. guldo_cli-0.1.0.dist-info/WHEEL +5 -0
  133. guldo_cli-0.1.0.dist-info/entry_points.txt +2 -0
  134. guldo_cli-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,91 @@
1
+ """Declaration of an AI-inference domain: classify a committed batch with a committed 3-layer ReLU MLP, as fast as you can, at equivalent accuracy.
2
+
3
+ size = d, the hidden width; the batch holds `size` inputs of dimension d. The model (W1 d x d, W2 d x d, W3 10 x d, no biases) and the batch are NOT
4
+ shipped as data: they are a pure function of one 63-bit seed through a pinned integer hash stream (SplitMix64, below), so a solver regenerates the
5
+ exact same floats with numpy alone and the instance stays a few bytes. Regenerating the model stands in for loading it from disk; that cost is
6
+ shared by the reference and every submission.
7
+
8
+ The answer is the list of `size` class labels. Judge-side, the verifier recomputes the float64 logits and accepts an answer in which at least
9
+ 99% of the labels are within TOL_SIGMA * (standard deviation of the instance's logits) of the best logit of their sample. That is the "equivalent
10
+ accuracy" the speedup is conditional on: a float32 or well-quantised model passes, a pruned or truncated one fails (solvers/aiinfer_lossy.py).
11
+
12
+ The reference is the unoptimised way to run it: float64, one sample at a time. Batching (a BLAS matmul), float32 and fused kernels are the
13
+ speedups this domain exists to certify. CPU only, one thread (the harness and the sandbox both set OMP_NUM_THREADS=1): see PROTOCOL.md for why a
14
+ GPU speedup is not certifiable by this protocol yet.
15
+ """
16
+ import functools
17
+ import hashlib
18
+ import hmac
19
+ import math
20
+
21
+ import numpy as np
22
+
23
+ NAME = "aiinfer"
24
+ VERSION = "aiinfer-v1" # bump whenever derive() or the model definition changes
25
+ SIZE_RANGE = (1024, 6144) # d=6144 peaks near 2.5 GB (weights + batch + hash-stream temporaries); the sandbox allows 4 GB
26
+ SIZE_STEP = 64
27
+ REFERENCE_SOLVER = "reference.py"
28
+ CLASSES = 10
29
+ TOL_SIGMA = 0.1 # a label is acceptable if its logit >= max logit - TOL_SIGMA * std(all logits of the instance)
30
+ MAX_BAD_FRACTION = 0.01 # at most floor(0.01 * batch) labels may be unacceptable
31
+ DOC = ("solve(seed, d, batch): regenerate the model and inputs from `seed` with the SplitMix64 stream documented in domains/aiinfer/reference.py "
32
+ "(W1, W2: d x d, W3: 10 x d, scaled by sqrt(3/d); batch inputs of dimension d), run h=relu(W1 x), h=relu(W2 h), logits=W3 h, and return the list of "
33
+ "`batch` class labels (ints 0-9). A label counts if its logit is within 0.1 standard deviations of the sample's best logit; "
34
+ "at most 1% of labels may miss. Return None for no answer.")
35
+ REFERENCE_NOTE = ("Float64, one sample at a time (a numpy matrix-vector product per input). Known to be beaten by batching the whole input "
36
+ "matrix into one BLAS matmul and by float32; the speedup grows with d because the model regeneration is O(d^2) and the inference O(d^3).")
37
+
38
+ _GOLD = 0x9E3779B97F4A7C15
39
+ _C1 = 0xBF58476D1CE4E5B9
40
+ _C2 = 0x94D049BB133111EB
41
+
42
+
43
+ def _uniform(seed, start, n):
44
+ """n floats in [-1, 1): SplitMix64 of the counter start..start+n-1 under `seed`. Integer arithmetic wraps mod 2^64, so it is exact on every machine."""
45
+ u = np.uint64
46
+ with np.errstate(over="ignore"):
47
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
48
+ z = (z ^ (z >> u(30))) * u(_C1)
49
+ z = (z ^ (z >> u(27))) * u(_C2)
50
+ z = z ^ (z >> u(31))
51
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
52
+
53
+
54
+ def _model(seed, d, batch):
55
+ s = math.sqrt(3.0 / d)
56
+ o = 0
57
+ W1 = (_uniform(seed, o, d * d) * s).reshape(d, d)
58
+ o += d * d
59
+ W2 = (_uniform(seed, o, d * d) * s).reshape(d, d)
60
+ o += d * d
61
+ W3 = (_uniform(seed, o, CLASSES * d) * s).reshape(CLASSES, d)
62
+ o += CLASSES * d
63
+ X = _uniform(seed, o, batch * d).reshape(batch, d)
64
+ return W1, W2, W3, X
65
+
66
+
67
+ @functools.lru_cache(maxsize=4)
68
+ def _logits(seed, d, batch):
69
+ W1, W2, W3, X = _model(seed, d, batch)
70
+ h = np.maximum(X @ W1.T, 0.0)
71
+ h = np.maximum(h @ W2.T, 0.0)
72
+ return h @ W3.T
73
+
74
+
75
+ def derive(master: bytes, size: int, idx: int) -> dict:
76
+ seed = int.from_bytes(hmac.new(master, f"aiinfer-v1:{size}:{idx}".encode(), hashlib.sha256).digest()[:8], "big") >> 1
77
+ L = _logits(seed, size, size)
78
+ return {"args": [seed, size, size], "planted": [int(c) for c in L.argmax(axis=1)]}
79
+
80
+
81
+ def verify(inst: dict, ans) -> bool:
82
+ seed, d, batch = inst["args"]
83
+ if not isinstance(ans, list) or len(ans) != batch:
84
+ return False
85
+ if any(isinstance(c, bool) or not isinstance(c, int) or not 0 <= c < CLASSES for c in ans):
86
+ return False
87
+ L = _logits(seed, d, batch)
88
+ tol = TOL_SIGMA * float(L.std())
89
+ got = L[np.arange(batch), np.asarray(ans)]
90
+ bad = int(np.count_nonzero(got < L.max(axis=1) - tol))
91
+ return bad <= int(MAX_BAD_FRACTION * batch)
@@ -0,0 +1,42 @@
1
+ """Reference for aiinfer: float64, one sample at a time.
2
+
3
+ The model definition (the contract a submission must reproduce): SplitMix64 counter stream under `seed`, element k = finalise((k+1)*GOLD + seed),
4
+ mapped to [-1, 1) as (z >> 11) * 2^-52 - 1. Stream layout: W1 (d*d), W2 (d*d), W3 (10*d), then the batch X (batch*d); weights are scaled by
5
+ sqrt(3/d). Network: relu(W1 x) -> relu(W2 h) -> W3 h; the label is the argmax.
6
+ """
7
+ import math
8
+
9
+ import numpy as np
10
+
11
+ _GOLD = 0x9E3779B97F4A7C15
12
+ _C1 = 0xBF58476D1CE4E5B9
13
+ _C2 = 0x94D049BB133111EB
14
+ _CLASSES = 10
15
+
16
+
17
+ def _uniform(seed, start, n):
18
+ u = np.uint64
19
+ with np.errstate(over="ignore"):
20
+ z = (np.arange(start, start + n, dtype=u) + u(1)) * u(_GOLD) + u(seed)
21
+ z = (z ^ (z >> u(30))) * u(_C1)
22
+ z = (z ^ (z >> u(27))) * u(_C2)
23
+ z = z ^ (z >> u(31))
24
+ return (z >> u(11)).astype(np.float64) * 2.0 ** -52 - 1.0
25
+
26
+
27
+ def solve(seed, d, batch):
28
+ s = math.sqrt(3.0 / d)
29
+ o = 0
30
+ W1 = (_uniform(seed, o, d * d) * s).reshape(d, d)
31
+ o += d * d
32
+ W2 = (_uniform(seed, o, d * d) * s).reshape(d, d)
33
+ o += d * d
34
+ W3 = (_uniform(seed, o, _CLASSES * d) * s).reshape(_CLASSES, d)
35
+ o += _CLASSES * d
36
+ X = _uniform(seed, o, batch * d).reshape(batch, d)
37
+ out = []
38
+ for i in range(batch):
39
+ h = np.maximum(W1 @ X[i], 0.0)
40
+ h = np.maximum(W2 @ h, 0.0)
41
+ out.append(int(np.argmax(W3 @ h)))
42
+ return out
@@ -0,0 +1,248 @@
1
+ {
2
+ "compiled_at": "2026-11-20T12:15:01Z",
3
+ "compiler_sha256": "f9434d3cc474fddee199665cb7bdf6f59f5b90ac079ac273cd4efa6e1dc0e5f2",
4
+ "cpu_hours": {
5
+ "expected": 3.07,
6
+ "worst_case": 14.4
7
+ },
8
+ "decl_sha256": "4b6669a7acc63fca54b0ebd1f95d4fb39cb254db44d50f231f9266389fd590b5",
9
+ "dims": [
10
+ 28,
11
+ 29,
12
+ 30
13
+ ],
14
+ "format": "svp-compiled-v1",
15
+ "name": "dlog",
16
+ "official": {
17
+ "budget": 120,
18
+ "n": 24
19
+ },
20
+ "plan": {
21
+ "cap": 120,
22
+ "confirmed": false,
23
+ "median_log2": {
24
+ "28": 1.3844,
25
+ "29": 2.6811,
26
+ "30": 3.9778
27
+ },
28
+ "notes": [
29
+ "narrow ladder: 3 size(s) spanning 2.59 octaves of cost (3+ is needed for the estimator's three difficulty bins to be well populated): widen SIZE_RANGE or let the reference's cost grow faster",
30
+ "the first plan's cost predictions missed by more than an octave, so the ladder was re-planned from the confirming data: it is the best available but NOT independently confirmed",
31
+ "the cost model was still off by more than one octave at size(s) [30] after 2 refinements",
32
+ "the measured median at one size is 1.3 octaves from the smoothed trend (sampling noise at 16 instances per size): the power analysis uses the smoothed trend; raise --n-prof for a steadier profile"
33
+ ],
34
+ "predicted_median": [
35
+ 2.611,
36
+ 6.413,
37
+ 15.756
38
+ ],
39
+ "sigma": 2.17,
40
+ "sigma_measured": true,
41
+ "sizes": [
42
+ 28,
43
+ 29,
44
+ 30
45
+ ],
46
+ "span_octaves": 2.59
47
+ },
48
+ "power": {
49
+ "boot": 60,
50
+ "curve": {
51
+ "0": {
52
+ "all_three": 0.0,
53
+ "inconclusive": 0.0,
54
+ "single": 0.0
55
+ },
56
+ "0.5": {
57
+ "all_three": 0.0,
58
+ "inconclusive": 0.0,
59
+ "single": 0.0
60
+ },
61
+ "1": {
62
+ "all_three": 0.0,
63
+ "inconclusive": 0.0,
64
+ "single": 0.044
65
+ },
66
+ "1.5": {
67
+ "all_three": 0.967,
68
+ "inconclusive": 0.0,
69
+ "single": 0.989
70
+ },
71
+ "2": {
72
+ "all_three": 1.0,
73
+ "inconclusive": 0.0,
74
+ "single": 1.0
75
+ },
76
+ "3": {
77
+ "all_three": 1.0,
78
+ "inconclusive": 0.0,
79
+ "single": 1.0
80
+ },
81
+ "4": {
82
+ "all_three": 0.6,
83
+ "inconclusive": 0.022,
84
+ "single": 0.789
85
+ },
86
+ "5": {
87
+ "all_three": 0.0,
88
+ "inconclusive": 0.222,
89
+ "single": 0.078
90
+ },
91
+ "6": {
92
+ "all_three": 0.0,
93
+ "inconclusive": 0.822,
94
+ "single": 0.0
95
+ }
96
+ },
97
+ "max_certifiable_effect": 3,
98
+ "min_certifiable_effect": 1.5,
99
+ "n": 24,
100
+ "notes": [],
101
+ "pair_noise": 0.6,
102
+ "target_effect": 2.0,
103
+ "target_power": 0.8,
104
+ "threshold": 1.0,
105
+ "tried": {
106
+ "12": 0.1,
107
+ "24": 1.0
108
+ },
109
+ "triples": 30
110
+ },
111
+ "practice_dims": [
112
+ 16,
113
+ 24
114
+ ],
115
+ "profile": {
116
+ "overhead": 0.0302,
117
+ "seed": "svp-compiler-profile-seed-v1",
118
+ "sizes": {
119
+ "16": {
120
+ "median_cost": 0.001,
121
+ "n": 5,
122
+ "sd_log2": 0.0,
123
+ "solved": 5,
124
+ "timeouts": 0
125
+ },
126
+ "24": {
127
+ "median_cost": 0.06,
128
+ "n": 5,
129
+ "sd_log2": 1.215,
130
+ "solved": 5,
131
+ "timeouts": 0
132
+ },
133
+ "28": {
134
+ "median_cost": 3.3794,
135
+ "n": 16,
136
+ "sd_log2": 0.793,
137
+ "solved": 16,
138
+ "timeouts": 0
139
+ },
140
+ "29": {
141
+ "median_cost": 3.7456,
142
+ "n": 16,
143
+ "sd_log2": 2.861,
144
+ "solved": 16,
145
+ "timeouts": 0
146
+ },
147
+ "30": {
148
+ "median_cost": 39.2031,
149
+ "n": 16,
150
+ "sd_log2": 1.616,
151
+ "solved": 16,
152
+ "timeouts": 0
153
+ }
154
+ }
155
+ },
156
+ "reference_sha256": "cc576160b83253cc09c55120fda2bd59fb62f35494436542ff5e0cdfa451cf8d",
157
+ "selftest": {
158
+ "at": "2026-11-20T13:03:08Z",
159
+ "controls": [
160
+ {
161
+ "check": "zero-effect control",
162
+ "detail": "reference vs reference earned 0.00 bits",
163
+ "status": "pass"
164
+ },
165
+ {
166
+ "check": "failure control",
167
+ "detail": "a solver that never answers earned 0",
168
+ "status": "pass"
169
+ },
170
+ {
171
+ "check": "known-effect control",
172
+ "detail": "a known 1-bit speedup earned 0.99 bits",
173
+ "status": "pass"
174
+ }
175
+ ],
176
+ "credits": {
177
+ "known_effect": 0.9858744980441347,
178
+ "none": 0.0,
179
+ "zero": 0.0
180
+ },
181
+ "effect": 1.0,
182
+ "ladders": {
183
+ "baseline": "results/judged_dlog_9421ea52_baseline_reference.py.jsonl",
184
+ "control_none": "results/judged_dlog_9421ea52_submission_control_none.py.jsonl",
185
+ "control_zero": "results/judged_dlog_9421ea52_submission_control_zero.py.jsonl"
186
+ },
187
+ "n": 24,
188
+ "status": "pass"
189
+ },
190
+ "size_range": [
191
+ 16,
192
+ 40
193
+ ],
194
+ "size_step": 1,
195
+ "validation": [
196
+ {
197
+ "check": "declaration",
198
+ "detail": "dlog dlog-v1, sizes 16..40 step 1",
199
+ "status": "pass"
200
+ },
201
+ {
202
+ "check": "reference",
203
+ "detail": "reference.py",
204
+ "status": "pass"
205
+ },
206
+ {
207
+ "check": "shape",
208
+ "detail": "args are JSON-serializable lists at sizes [16, 28, 40]",
209
+ "status": "pass"
210
+ },
211
+ {
212
+ "check": "determinism",
213
+ "detail": "pure in (master, size, index); 8/8 distinct indices; seed-dependent",
214
+ "status": "pass"
215
+ },
216
+ {
217
+ "check": "process purity",
218
+ "detail": "identical instances in fresh interpreters with two hash seeds",
219
+ "status": "pass"
220
+ },
221
+ {
222
+ "check": "witness",
223
+ "detail": "verify() accepts the planted witness on 12 instances; it is not in the arguments",
224
+ "status": "pass"
225
+ },
226
+ {
227
+ "check": "junk rejected",
228
+ "detail": "verify() rejected all 19 junk answers on 6 instances",
229
+ "status": "pass"
230
+ },
231
+ {
232
+ "check": "no trivial answer",
233
+ "detail": "no argument, its neighbour or the argument list verifies",
234
+ "status": "pass"
235
+ },
236
+ {
237
+ "check": "witness reuse",
238
+ "detail": "0 of 30 cross-instance witnesses accepted",
239
+ "status": "pass"
240
+ },
241
+ {
242
+ "check": "reference solves",
243
+ "detail": "solved 3 instances at each of sizes [16, 17, 18]; median cost 16: 0.001s, 17: 0.001s, 18: 0.001s",
244
+ "status": "pass"
245
+ }
246
+ ],
247
+ "version": "dlog-v1"
248
+ }
@@ -0,0 +1,41 @@
1
+ """Declaration of a domain the compiler was NOT written for: discrete logarithms in Z_p^*, by exhaustive search.
2
+
3
+ A solver receives (p, g, h) and returns any exponent x with g^x = h (mod p). size = the bit length of the planted exponent, so the
4
+ reference's linear scan costs ~2^size steps and every extra bit doubles it; a baby-step/giant-step solver is the speedup this
5
+ domain exists to certify (about size/2 bits at large sizes). Judge-side, the verifier is one modular exponentiation.
6
+ """
7
+ import hashlib
8
+ import hmac
9
+ import random
10
+
11
+ import instances # the project's Miller-Rabin test
12
+
13
+ NAME = "dlog"
14
+ VERSION = "dlog-v1" # bump whenever derive() changes
15
+ SIZE_RANGE = (16, 40) # sizes (exponent bits) the compiler may use
16
+ SIZE_STEP = 1
17
+ REFERENCE_SOLVER = "reference.py"
18
+ DOC = "solve(p, g, h): return an integer x with pow(g, x, p) == h, 0 <= x < p - 1. Any valid x counts; return None for no answer."
19
+
20
+
21
+ def _prime(rng, bits):
22
+ while True:
23
+ c = rng.getrandbits(bits) | (1 << (bits - 1)) | 1
24
+ if instances._is_prime(c):
25
+ return c
26
+
27
+
28
+ def derive(master: bytes, size: int, idx: int) -> dict:
29
+ rng = random.Random(hmac.new(master, f"dlog-v1:{size}:{idx}".encode(), hashlib.sha256).digest())
30
+ p = _prime(rng, size + 2)
31
+ while True:
32
+ g = rng.randrange(2, p - 1)
33
+ x = rng.randrange(1, 1 << size)
34
+ if x < p - 1:
35
+ break
36
+ return {"args": [p, g, pow(g, x, p)], "planted": x}
37
+
38
+
39
+ def verify(inst: dict, ans) -> bool:
40
+ p, g, h = inst["args"]
41
+ return isinstance(ans, int) and not isinstance(ans, bool) and 0 <= ans < p - 1 and pow(g, ans, p) == h
@@ -0,0 +1,10 @@
1
+ """Reference for dlog: exhaustive search, one multiplication per candidate exponent."""
2
+
3
+
4
+ def solve(p, g, h):
5
+ cur = 1
6
+ for x in range(p - 1):
7
+ if cur == h:
8
+ return x
9
+ cur = cur * g % p
10
+ return None