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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Red-team (MLWE and GM): finds the judge's seed file and code on disk, re-derives the instance and returns the
|
|
2
|
+
planted answer. Works against bare local mode; must crash inside the sandbox (nothing of the judge is mounted)."""
|
|
3
|
+
import glob
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def solve(basis, bound2):
|
|
9
|
+
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
10
|
+
sys.path.insert(0, root)
|
|
11
|
+
import families
|
|
12
|
+
d = len(basis)
|
|
13
|
+
for fam in ("mlwe", "gm"):
|
|
14
|
+
for seed_file in glob.glob(root + "/results/*.seed"):
|
|
15
|
+
master = open(seed_file, "rb").read().strip()
|
|
16
|
+
for idx in range(64):
|
|
17
|
+
try:
|
|
18
|
+
inst = families.derive(fam, master, d, idx)
|
|
19
|
+
except Exception:
|
|
20
|
+
break
|
|
21
|
+
if inst["basis"] == basis:
|
|
22
|
+
return inst["planted"]
|
|
23
|
+
return None
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Red-team: a detached daemon that keeps the stdout pipe open and sleeps forever, trying to hang the judge.
|
|
2
|
+
The meter must kill it at the wall deadline and report an overrun (timeout); it must never block."""
|
|
3
|
+
import os
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def solve(basis, bound2):
|
|
8
|
+
if os.fork() == 0:
|
|
9
|
+
os.setsid()
|
|
10
|
+
while True:
|
|
11
|
+
time.sleep(1)
|
|
12
|
+
os._exit(0)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""SUPERSEDED (kept for the record): intended as a small-dimension-only win but pruning is slower than the baseline
|
|
2
|
+
at n<=60, so it never showed an early advantage. See fixed_overhead_ref.py for the working version of this red-team case."""
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from fpylll import BKZ, LLL, IntegerMatrix
|
|
6
|
+
|
|
7
|
+
_S = "/opt/homebrew/share/fplll/strategies/default.json"
|
|
8
|
+
STRATEGIES = _S if os.path.exists(_S) else "/opt/homebrew/Cellar/fplll/5.5.0/share/fplll/strategies/default.json"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def solve(basis, bound2):
|
|
12
|
+
n = len(basis)
|
|
13
|
+
A = IntegerMatrix.from_matrix(basis)
|
|
14
|
+
LLL.reduction(A)
|
|
15
|
+
pruned = n <= 60
|
|
16
|
+
for beta in list(range(10, n + 1, 4)):
|
|
17
|
+
if sum(x * x for x in A[0]) <= bound2:
|
|
18
|
+
break
|
|
19
|
+
kw = {"strategies": STRATEGIES} if pruned else {}
|
|
20
|
+
BKZ.reduction(A, BKZ.Param(block_size=beta, flags=BKZ.AUTO_ABORT | BKZ.MAX_LOOPS, max_loops=8, **kw))
|
|
21
|
+
v = [int(x) for x in A[0]]
|
|
22
|
+
return v if sum(x * x for x in v) <= bound2 else None
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Starter submission. Copy this file, change `solve`, run: python3 submit_check.py solvers/my_solver.py
|
|
2
|
+
|
|
3
|
+
Contract (details in COMPETITORS.md):
|
|
4
|
+
solve(basis, bound2) -> list[int] | None
|
|
5
|
+
* basis: list of integer row vectors (a lattice basis); bound2: accept any NONZERO lattice vector with squared norm <= bound2
|
|
6
|
+
* return the vector as plain ints, or None if you did not find one (a failure costs the full CPU cap)
|
|
7
|
+
* deterministic, single-process, no files, no network; only fpylll and numpy are available in the judge's sandbox
|
|
8
|
+
"""
|
|
9
|
+
from fpylll import BKZ, LLL, IntegerMatrix
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def solve(basis, bound2):
|
|
13
|
+
n = len(basis)
|
|
14
|
+
A = IntegerMatrix.from_matrix(basis)
|
|
15
|
+
LLL.reduction(A)
|
|
16
|
+
for beta in range(10, n + 1, 4): # progressive BKZ: replace this with your algorithm
|
|
17
|
+
if sum(x * x for x in A[0]) <= bound2:
|
|
18
|
+
break
|
|
19
|
+
BKZ.reduction(A, BKZ.Param(block_size=beta, flags=BKZ.AUTO_ABORT | BKZ.MAX_LOOPS, max_loops=8))
|
|
20
|
+
v = [int(x) for x in A[0]]
|
|
21
|
+
return v if sum(c * c for c in v) <= bound2 else None
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Red-team: floods the answer channel (stdout) without end, trying to exhaust the meter's memory or bury the real answer. The CPU limit and the
|
|
2
|
+
memory limit must stop it: a timeout or crash in bounded time, never a solve."""
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def solve(basis, bound2):
|
|
7
|
+
chunk = (b"x" * 1023 + b"\n") * 1024
|
|
8
|
+
while True:
|
|
9
|
+
sys.stdout.buffer.write(chunk)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Red-team: fills the only writable place (/tmp, a memory-backed filesystem) without end. The memory limit or a full-disk error must stop it:
|
|
2
|
+
a crash or timeout in bounded time, never a solve."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def solve(basis, bound2):
|
|
6
|
+
i = 0
|
|
7
|
+
while True:
|
|
8
|
+
with open(f"/tmp/fill{i}", "wb") as f:
|
|
9
|
+
f.write(b"\x01" * (64 * 1024 * 1024))
|
|
10
|
+
i += 1
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Honest speedup: same progressive BKZ, but with extreme-pruned enumeration (fplll default strategies)."""
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from fpylll import BKZ, LLL, IntegerMatrix
|
|
5
|
+
from fpylll.fplll.bkz_param import load_strategies_json
|
|
6
|
+
|
|
7
|
+
STRATEGIES = next(p for p in (BKZ.DEFAULT_STRATEGY.decode() if isinstance(BKZ.DEFAULT_STRATEGY, bytes) else BKZ.DEFAULT_STRATEGY,
|
|
8
|
+
"/opt/fplll/strategies/default.json",
|
|
9
|
+
"/opt/homebrew/share/fplll/strategies/default.json",
|
|
10
|
+
"/opt/homebrew/Cellar/fplll/5.5.0/share/fplll/strategies/default.json")
|
|
11
|
+
if os.path.exists(p))
|
|
12
|
+
_LOADED = load_strategies_json(STRATEGIES.encode()) # parse the 8.6 MB file once, not once per block size
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def solve(basis, bound2):
|
|
16
|
+
n = len(basis)
|
|
17
|
+
A = IntegerMatrix.from_matrix(basis)
|
|
18
|
+
LLL.reduction(A)
|
|
19
|
+
for beta in list(range(10, n + 1, 4)):
|
|
20
|
+
if sum(x * x for x in A[0]) <= bound2:
|
|
21
|
+
break
|
|
22
|
+
BKZ.reduction(A, BKZ.Param(block_size=beta, strategies=_LOADED,
|
|
23
|
+
flags=BKZ.AUTO_ABORT | BKZ.MAX_LOOPS, max_loops=8))
|
|
24
|
+
v = [int(x) for x in A[0]]
|
|
25
|
+
return v if sum(x * x for x in v) <= bound2 else None
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"""Static sanity check that EXECUTES NONE of the project's code: it reads source files as text and parses them.
|
|
2
|
+
|
|
3
|
+
python3 static_check.py the AI / counted-ops / GPU files added in November 2026
|
|
4
|
+
python3 static_check.py FILE [FILE ...] any files
|
|
5
|
+
|
|
6
|
+
Reports: syntax errors; names used but defined nowhere in scope; `module.attr` references to a project module that does not define `attr` at top level; calls to a project
|
|
7
|
+
function (`module.f(...)` or a local `f(...)`) whose arguments cannot match its signature (too many positional, an unknown keyword, a missing required argument).
|
|
8
|
+
|
|
9
|
+
What it does NOT find: anything about values (wrong dict keys, wrong types, wrong logic), method calls on objects, or whether a test would pass. It exists for the cases where
|
|
10
|
+
nothing may be run (it caught nothing in the files above, and it does catch deliberately planted errors of each kind); it is a complement to `make test`, never a substitute.
|
|
11
|
+
"""
|
|
12
|
+
import ast
|
|
13
|
+
import builtins
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
18
|
+
BUILTINS = set(dir(builtins)) | {"__file__", "__name__", "__doc__"}
|
|
19
|
+
DEFAULT_FILES = ["tensorops.py", "tflops_runner.py", "tflops.py", "test_tflops.py", "gpu_meter.py", "gpu_runner.py", "test_gpu_meter.py", "test_aidecode.py", "test_aiinfer.py",
|
|
20
|
+
"build_site.py", "test_site_ai.py",
|
|
21
|
+
"domains/aidecode/decl.py", "domains/aidecode/reference.py", "domains/aiinfer/decl.py", "domains/aiinfer/reference.py",
|
|
22
|
+
"solvers/aidecode_kv.py", "solvers/aidecode_kv_f32.py", "solvers/aidecode_lossy.py", "solvers/aidecode_repeat.py", "solvers/aidecode_flops_ref.py",
|
|
23
|
+
"solvers/aidecode_flops_kv.py", "solvers/aidecode_flops_lossy.py", "solvers/aiinfer_batched.py", "solvers/aiinfer_f32.py", "solvers/aiinfer_lossy.py",
|
|
24
|
+
"solvers/aiinfer_gpu_ref.py", "solvers/aiinfer_gpu_batched.py", "solvers/gpu_noop.py"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load(path):
|
|
28
|
+
with open(path, "rb") as f:
|
|
29
|
+
return ast.parse(f.read(), filename=path)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def bound_names(node):
|
|
33
|
+
"""Names bound directly by the statements of `node`'s body (nested function/class bodies are separate scopes; their own names are bound here)."""
|
|
34
|
+
out = set()
|
|
35
|
+
|
|
36
|
+
def targets(t):
|
|
37
|
+
if isinstance(t, ast.Name):
|
|
38
|
+
out.add(t.id)
|
|
39
|
+
elif isinstance(t, (ast.Tuple, ast.List)):
|
|
40
|
+
for e in t.elts:
|
|
41
|
+
targets(e)
|
|
42
|
+
elif isinstance(t, ast.Starred):
|
|
43
|
+
targets(t.value)
|
|
44
|
+
|
|
45
|
+
def visit(n):
|
|
46
|
+
if isinstance(n, ast.Import):
|
|
47
|
+
for a in n.names:
|
|
48
|
+
out.add((a.asname or a.name).split(".")[0])
|
|
49
|
+
elif isinstance(n, ast.ImportFrom):
|
|
50
|
+
for a in n.names:
|
|
51
|
+
out.add(a.asname or a.name)
|
|
52
|
+
elif isinstance(n, ast.Assign):
|
|
53
|
+
for t in n.targets:
|
|
54
|
+
targets(t)
|
|
55
|
+
elif isinstance(n, (ast.AugAssign, ast.AnnAssign)):
|
|
56
|
+
targets(n.target)
|
|
57
|
+
elif isinstance(n, (ast.For, ast.AsyncFor)):
|
|
58
|
+
targets(n.target)
|
|
59
|
+
elif isinstance(n, (ast.With, ast.AsyncWith)):
|
|
60
|
+
for it in n.items:
|
|
61
|
+
if it.optional_vars is not None:
|
|
62
|
+
targets(it.optional_vars)
|
|
63
|
+
elif isinstance(n, ast.ExceptHandler) and n.name:
|
|
64
|
+
out.add(n.name)
|
|
65
|
+
elif isinstance(n, ast.NamedExpr):
|
|
66
|
+
targets(n.target)
|
|
67
|
+
elif isinstance(n, (ast.Global, ast.Nonlocal)):
|
|
68
|
+
out.update(n.names)
|
|
69
|
+
for c in ast.iter_child_nodes(n):
|
|
70
|
+
if isinstance(c, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
71
|
+
out.add(c.name)
|
|
72
|
+
elif not isinstance(c, (ast.Lambda, ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):
|
|
73
|
+
visit(c)
|
|
74
|
+
for stmt in getattr(node, "body", []):
|
|
75
|
+
if isinstance(stmt, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
76
|
+
out.add(stmt.name)
|
|
77
|
+
else:
|
|
78
|
+
visit(stmt)
|
|
79
|
+
return out
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def args_of(fn):
|
|
83
|
+
a = fn.args
|
|
84
|
+
names = [x.arg for x in a.posonlyargs + a.args + a.kwonlyargs]
|
|
85
|
+
if a.vararg:
|
|
86
|
+
names.append(a.vararg.arg)
|
|
87
|
+
if a.kwarg:
|
|
88
|
+
names.append(a.kwarg.arg)
|
|
89
|
+
return set(names)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def signatures(tree):
|
|
93
|
+
out = {}
|
|
94
|
+
for n in tree.body:
|
|
95
|
+
if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
96
|
+
a = n.args
|
|
97
|
+
pos = a.posonlyargs + a.args
|
|
98
|
+
names = [x.arg for x in pos] + [x.arg for x in a.kwonlyargs]
|
|
99
|
+
required = [x.arg for x in pos[:len(pos) - len(a.defaults)]] + [x.arg for x, d in zip(a.kwonlyargs, a.kw_defaults) if d is None]
|
|
100
|
+
out[n.name] = (len(pos), names, required, a.vararg is not None, a.kwarg is not None)
|
|
101
|
+
return out
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Checker:
|
|
105
|
+
def __init__(self, path, tree, modtops, modsigs):
|
|
106
|
+
self.path, self.tree, self.modtops, self.modsigs = path, tree, modtops, modsigs
|
|
107
|
+
self.problems = []
|
|
108
|
+
self.module_names = bound_names(tree)
|
|
109
|
+
self.aliases = {}
|
|
110
|
+
for n in ast.walk(tree):
|
|
111
|
+
if isinstance(n, ast.Import):
|
|
112
|
+
for a in n.names:
|
|
113
|
+
if a.name in modtops:
|
|
114
|
+
self.aliases[a.asname or a.name] = a.name
|
|
115
|
+
self.local_sigs = modsigs.get(os.path.splitext(os.path.basename(path))[0], {})
|
|
116
|
+
|
|
117
|
+
def report(self, node, msg):
|
|
118
|
+
self.problems.append(f"{os.path.relpath(self.path, ROOT)}:{getattr(node, 'lineno', '?')}: {msg}")
|
|
119
|
+
|
|
120
|
+
def run(self):
|
|
121
|
+
for child in ast.iter_child_nodes(self.tree):
|
|
122
|
+
self.walk(child, [self.module_names])
|
|
123
|
+
return self.problems
|
|
124
|
+
|
|
125
|
+
def walk(self, n, chain):
|
|
126
|
+
if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
127
|
+
for d in n.decorator_list + n.args.defaults + [d for d in n.args.kw_defaults if d]:
|
|
128
|
+
self.walk(d, chain)
|
|
129
|
+
inner = args_of(n) | bound_names(n)
|
|
130
|
+
for c in n.body:
|
|
131
|
+
self.walk(c, chain + [inner])
|
|
132
|
+
return
|
|
133
|
+
if isinstance(n, ast.Lambda):
|
|
134
|
+
self.walk(n.body, chain + [args_of(n)])
|
|
135
|
+
return
|
|
136
|
+
if isinstance(n, ast.ClassDef):
|
|
137
|
+
for d in n.decorator_list + n.bases:
|
|
138
|
+
self.walk(d, chain)
|
|
139
|
+
inner = bound_names(n)
|
|
140
|
+
for c in n.body:
|
|
141
|
+
self.walk(c, chain + [inner])
|
|
142
|
+
return
|
|
143
|
+
if isinstance(n, (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):
|
|
144
|
+
comp = {t.id for g in n.generators for t in ast.walk(g.target) if isinstance(t, ast.Name)}
|
|
145
|
+
chain2 = chain + [comp]
|
|
146
|
+
for g in n.generators:
|
|
147
|
+
self.walk(g.iter, chain2)
|
|
148
|
+
for i in g.ifs:
|
|
149
|
+
self.walk(i, chain2)
|
|
150
|
+
for part in ([n.key, n.value] if isinstance(n, ast.DictComp) else [n.elt]):
|
|
151
|
+
self.walk(part, chain2)
|
|
152
|
+
return
|
|
153
|
+
if isinstance(n, ast.Name) and isinstance(n.ctx, ast.Load) and n.id not in BUILTINS and not any(n.id in s for s in chain):
|
|
154
|
+
self.report(n, f"undefined name {n.id!r}")
|
|
155
|
+
if isinstance(n, ast.Attribute) and isinstance(n.value, ast.Name) and n.value.id in self.aliases and not any(n.value.id in s for s in chain[1:]):
|
|
156
|
+
mod = self.aliases[n.value.id]
|
|
157
|
+
if n.attr not in self.modtops[mod]:
|
|
158
|
+
self.report(n, f"{mod} has no top-level name {n.attr!r}")
|
|
159
|
+
if isinstance(n, ast.Call):
|
|
160
|
+
self.check_call(n, chain)
|
|
161
|
+
for c in ast.iter_child_nodes(n):
|
|
162
|
+
self.walk(c, chain)
|
|
163
|
+
|
|
164
|
+
def check_call(self, call, chain):
|
|
165
|
+
sig, label, f = None, None, call.func
|
|
166
|
+
if isinstance(f, ast.Attribute) and isinstance(f.value, ast.Name) and f.value.id in self.aliases and not any(f.value.id in s for s in chain[1:]):
|
|
167
|
+
mod = self.aliases[f.value.id]
|
|
168
|
+
sig, label = self.modsigs.get(mod, {}).get(f.attr), f"{mod}.{f.attr}"
|
|
169
|
+
elif isinstance(f, ast.Name) and f.id in self.local_sigs and not any(f.id in s for s in chain[1:]):
|
|
170
|
+
sig, label = self.local_sigs[f.id], f.id
|
|
171
|
+
if sig is None or any(isinstance(a, ast.Starred) for a in call.args) or any(k.arg is None for k in call.keywords):
|
|
172
|
+
return
|
|
173
|
+
_, names, required, has_var, has_kw = sig
|
|
174
|
+
if len(call.args) > len(names) and not has_var:
|
|
175
|
+
self.report(call, f"{label}() takes at most {len(names)} positional arguments, {len(call.args)} given")
|
|
176
|
+
kw = {k.arg for k in call.keywords}
|
|
177
|
+
for k in kw:
|
|
178
|
+
if k not in names and not has_kw:
|
|
179
|
+
self.report(call, f"{label}() has no parameter {k!r}")
|
|
180
|
+
supplied = set(names[:len(call.args)]) | kw
|
|
181
|
+
missing = [r for r in required if r not in supplied]
|
|
182
|
+
if missing:
|
|
183
|
+
self.report(call, f"{label}() missing required argument(s) {missing}")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def main(argv):
|
|
187
|
+
files = [os.path.abspath(a) for a in argv] or [os.path.join(ROOT, f) for f in DEFAULT_FILES]
|
|
188
|
+
trees, modtops, modsigs, syntax = {}, {}, {}, 0
|
|
189
|
+
for name in os.listdir(ROOT): # every top-level project module, so cross-module references can be resolved
|
|
190
|
+
if name.endswith(".py"):
|
|
191
|
+
files_extra = os.path.join(ROOT, name)
|
|
192
|
+
try:
|
|
193
|
+
tree = load(files_extra)
|
|
194
|
+
except SyntaxError:
|
|
195
|
+
continue
|
|
196
|
+
mod = name[:-3]
|
|
197
|
+
modtops[mod], modsigs[mod], trees[files_extra] = bound_names(tree), signatures(tree), tree
|
|
198
|
+
total = 0
|
|
199
|
+
for p in files:
|
|
200
|
+
try:
|
|
201
|
+
tree = trees.get(p) or load(p)
|
|
202
|
+
except (SyntaxError, OSError) as e:
|
|
203
|
+
print(f"{os.path.relpath(p, ROOT)}: {'SYNTAX ERROR line ' + str(e.lineno) + ': ' + e.msg if isinstance(e, SyntaxError) else e}")
|
|
204
|
+
syntax += 1
|
|
205
|
+
continue
|
|
206
|
+
for line in Checker(p, tree, modtops, modsigs).run():
|
|
207
|
+
print(line)
|
|
208
|
+
total += 1
|
|
209
|
+
print(f"checked {len(files)} file(s): {total} problem(s), {syntax} unreadable or syntax error(s)")
|
|
210
|
+
return 1 if total or syntax else 0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if __name__ == "__main__":
|
|
214
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""Pre-flight check for a submission. Run this before sending a solver in.
|
|
2
|
+
|
|
3
|
+
python3 submit_check.py solvers/my_solver.py [--family gm|mlwe] [--n 3]
|
|
4
|
+
|
|
5
|
+
It (1) lints the source for things the judge's sandbox will block or treat as an attempt to evade metering, (2) runs the
|
|
6
|
+
solver in a bare local process on small PUBLIC practice instances, checks every answer with the real verifier, checks
|
|
7
|
+
the solver is deterministic, and reports CPU cost. A pass here means "well-formed", not "fast enough to certify".
|
|
8
|
+
Exit code: 0 = ok (warnings allowed), 1 = a fatal problem.
|
|
9
|
+
"""
|
|
10
|
+
import argparse
|
|
11
|
+
import ast
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
import families
|
|
16
|
+
import harness
|
|
17
|
+
import instances
|
|
18
|
+
|
|
19
|
+
# (name or dotted prefix, why it matters). These are warnings: the sandbox enforces; the point is to avoid surprises.
|
|
20
|
+
SUSPECT_CALLS = {
|
|
21
|
+
"os.fork": "forking: all descendants are billed and orphans are killed at the deadline; detached daemons are an evasion attempt",
|
|
22
|
+
"os.setsid": "detaching from the process group looks like an attempt to hide CPU from the meter",
|
|
23
|
+
"os.system": "spawns a shell; descendants are billed, and there is no shell or network in the sandbox",
|
|
24
|
+
"subprocess": "spawning processes: descendants are billed; most tools will not exist in the sandbox image",
|
|
25
|
+
"multiprocessing": "extra processes are billed in total CPU, and the sandbox is limited to one CPU and 64 pids",
|
|
26
|
+
"threading": "threads are billed in total CPU; the sandbox is limited to one CPU",
|
|
27
|
+
"socket": "there is no network in the sandbox",
|
|
28
|
+
"urllib": "there is no network in the sandbox",
|
|
29
|
+
"requests": "there is no network in the sandbox",
|
|
30
|
+
"glob": "the sandbox filesystem is read-only and contains nothing of the judge's; reading seeds or judge code is disqualifying",
|
|
31
|
+
"open": "files: only /work/submission.py and the Python stdlib/site-packages are readable; do not read judge files or seeds",
|
|
32
|
+
"importlib": "dynamic imports: everything you need must be importable in the sandbox image (fpylll, numpy only)",
|
|
33
|
+
"__import__": "dynamic imports: everything you need must be importable in the sandbox image (fpylll, numpy only)",
|
|
34
|
+
"sys.path": "path tricks: the judge's modules are not importable in the sandbox, and trying to import them is disqualifying",
|
|
35
|
+
"os.environ": "the sandbox passes only PATH, OMP_NUM_THREADS and PYTHONHASHSEED",
|
|
36
|
+
"time.sleep": "sleeping costs no CPU but counts toward the wall-clock deadline",
|
|
37
|
+
}
|
|
38
|
+
ALLOWED_THIRD_PARTY = {"fpylll", "numpy", "cysignals"}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def stdlib_names():
|
|
42
|
+
"""Top-level standard-library module names. sys.stdlib_module_names exists from Python 3.10; on 3.9 build the same set from the
|
|
43
|
+
interpreter's own library directory (a missing name would only mis-label a stdlib import in a WARNING, never reject a file)."""
|
|
44
|
+
names = getattr(sys, "stdlib_module_names", None)
|
|
45
|
+
if names is not None:
|
|
46
|
+
return names
|
|
47
|
+
import sysconfig
|
|
48
|
+
found = set(sys.builtin_module_names)
|
|
49
|
+
root = sysconfig.get_paths()["stdlib"]
|
|
50
|
+
for d in (root, os.path.join(root, "lib-dynload")):
|
|
51
|
+
try:
|
|
52
|
+
for n in os.listdir(d):
|
|
53
|
+
found.add(n[:-3] if n.endswith(".py") else n.split(".")[0])
|
|
54
|
+
except OSError:
|
|
55
|
+
pass
|
|
56
|
+
return found
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def dotted(node):
|
|
60
|
+
parts = []
|
|
61
|
+
while isinstance(node, ast.Attribute):
|
|
62
|
+
parts.append(node.attr)
|
|
63
|
+
node = node.value
|
|
64
|
+
if isinstance(node, ast.Name):
|
|
65
|
+
parts.append(node.id)
|
|
66
|
+
return ".".join(reversed(parts))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def lint(path):
|
|
70
|
+
try:
|
|
71
|
+
with open(path, "rb") as f:
|
|
72
|
+
tree = ast.parse(f.read()) # BYTES, so a PEP 263 coding cookie is honoured exactly as the interpreter will: lint sees what runs
|
|
73
|
+
except SyntaxError as e: # includes NUL bytes, unknown encodings, invalid UTF-8 and over-deep nesting: a clean FATAL, never a traceback
|
|
74
|
+
return [], [f"syntax error: {e.msg} (line {e.lineno})"]
|
|
75
|
+
except (ValueError, RecursionError, MemoryError) as e:
|
|
76
|
+
return [], [f"could not parse the file ({type(e).__name__})"]
|
|
77
|
+
warnings, fatal = [], []
|
|
78
|
+
def defines_solve(n):
|
|
79
|
+
if isinstance(n, ast.AsyncFunctionDef) and n.name == "solve":
|
|
80
|
+
fatal.append("`async def solve` is not supported: the runner calls solve() synchronously, so an async solver "
|
|
81
|
+
"would return an un-awaited coroutine and crash")
|
|
82
|
+
return True # defined, but already reported as fatal
|
|
83
|
+
if isinstance(n, ast.FunctionDef):
|
|
84
|
+
return n.name == "solve"
|
|
85
|
+
if isinstance(n, ast.Assign): # solve = some_function / solve = lambda ...
|
|
86
|
+
return any(isinstance(t, ast.Name) and t.id == "solve" for t in n.targets)
|
|
87
|
+
if isinstance(n, ast.ImportFrom): # from helper import solve
|
|
88
|
+
return any((a.asname or a.name) == "solve" for a in n.names)
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
if not any(defines_solve(n) for n in tree.body):
|
|
92
|
+
fatal.append("no top-level `solve` (a function, an assignment, or an import named solve)")
|
|
93
|
+
seen = set()
|
|
94
|
+
for node in ast.walk(tree):
|
|
95
|
+
names = []
|
|
96
|
+
if isinstance(node, ast.Call):
|
|
97
|
+
names.append(dotted(node.func))
|
|
98
|
+
elif isinstance(node, (ast.Attribute, ast.Name)):
|
|
99
|
+
names.append(dotted(node))
|
|
100
|
+
elif isinstance(node, ast.Import):
|
|
101
|
+
names += [a.name for a in node.names]
|
|
102
|
+
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
103
|
+
names.append(node.module)
|
|
104
|
+
for nm in names:
|
|
105
|
+
for key, why in SUSPECT_CALLS.items():
|
|
106
|
+
if (nm == key or nm.startswith(key + ".")) and key not in seen:
|
|
107
|
+
seen.add(key)
|
|
108
|
+
warnings.append(f"line {getattr(node, 'lineno', '?')}: `{key}` - {why}")
|
|
109
|
+
stdlib = stdlib_names()
|
|
110
|
+
for node in ast.walk(tree):
|
|
111
|
+
mods = [a.name for a in node.names] if isinstance(node, ast.Import) else \
|
|
112
|
+
[node.module] if isinstance(node, ast.ImportFrom) and node.module and node.level == 0 else []
|
|
113
|
+
for m in mods:
|
|
114
|
+
top = m.split(".")[0]
|
|
115
|
+
if top not in stdlib and top not in ALLOWED_THIRD_PARTY:
|
|
116
|
+
warnings.append(f"line {node.lineno}: imports `{top}`, which is not in the sandbox image "
|
|
117
|
+
f"(only fpylll, numpy, cysignals); it will crash there")
|
|
118
|
+
return warnings, fatal
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def check(path, family="gm", n=3, dims=None, budget=30):
|
|
122
|
+
"""Returns (ok, report_lines)."""
|
|
123
|
+
lines = []
|
|
124
|
+
warnings, fatal = lint(path)
|
|
125
|
+
for w in warnings:
|
|
126
|
+
lines.append(f"WARN {w}")
|
|
127
|
+
for f in fatal:
|
|
128
|
+
lines.append(f"FATAL {f}")
|
|
129
|
+
if fatal:
|
|
130
|
+
lines.append("RESULT: FIX THE FATAL ITEMS ABOVE") # the same closing line every other outcome ends with
|
|
131
|
+
return False, lines
|
|
132
|
+
dims = dims or families.PRACTICE_DIMS[family]
|
|
133
|
+
path = os.path.abspath(path)
|
|
134
|
+
bad = 0
|
|
135
|
+
for d in dims:
|
|
136
|
+
for i in range(n):
|
|
137
|
+
inst = families.derive(family, instances.PRACTICE_SEED, d, i)
|
|
138
|
+
r1 = harness.run_one(path, inst, budget)
|
|
139
|
+
r2 = harness.run_one(path, inst, budget)
|
|
140
|
+
tag = f"{family} dim {d} #{i}: {r1['status']:8s} cpu {r1['cpu']:6.2f}s"
|
|
141
|
+
if r1["status"] in ("wrong", "crash"):
|
|
142
|
+
bad += 1
|
|
143
|
+
tag += " <-- " + (r1.get("err", "")[-160:].replace("\n", " ") or "invalid vector")
|
|
144
|
+
lines.append(f"FATAL {tag}")
|
|
145
|
+
continue
|
|
146
|
+
lines.append(f"ok {tag}")
|
|
147
|
+
if r1["status"] != r2["status"]:
|
|
148
|
+
lines.append(f"WARN not deterministic: status {r1['status']} then {r2['status']} on the same instance")
|
|
149
|
+
ok = bad == 0
|
|
150
|
+
lines.append("RESULT: " + ("well-formed (this says nothing about speed)" if ok else "FIX THE FATAL ITEMS ABOVE"))
|
|
151
|
+
return ok, lines
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def main():
|
|
155
|
+
ap = argparse.ArgumentParser()
|
|
156
|
+
ap.add_argument("solver")
|
|
157
|
+
ap.add_argument("--family", default="gm", choices=sorted(families.FAMILIES))
|
|
158
|
+
ap.add_argument("--n", type=int, default=3)
|
|
159
|
+
a = ap.parse_args()
|
|
160
|
+
ok, lines = check(a.solver, a.family, a.n)
|
|
161
|
+
print("\n".join(lines))
|
|
162
|
+
sys.exit(0 if ok else 1)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
if __name__ == "__main__":
|
|
166
|
+
main()
|