Repository navigation
Expand file tree
/
Copy pathlibraryUsage.ts
More file actions
101 lines (99 loc) · 4.19 KB
/
Copy pathlibraryUsage.ts
File metadata and controls
101 lines (99 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import type { MathematicsVerifierBatchResult } from '../../src/math/verifier';
import { readLibraryCatalog } from '../../src/solver/libraryCatalog';
import type { LibraryAccess } from '../../src/solver/libraryAccess';
import { proofReceiptsMatch } from '../../src/solver/modules/evidence';
import type { SolverProblem } from '../../src/solver/problem';
const object = (value: unknown): Record<string, unknown> | undefined =>
value !== null && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : undefined;
const maxReferences = 64;
/** Summarize only references from S3's independently accepted, exact original-proof receipts. */
export function summarizeWebLibraryUsage(
problem: SolverProblem,
access: LibraryAccess,
result: Record<string, unknown>,
installationRounds: number,
) {
const catalog = readLibraryCatalog(access.file, access.digest);
const evaluator = object(result.evaluator),
check = object(evaluator?.verification),
batch = object(check?.verification);
const targets = problem.targets,
references = new Map<string, { name: string; file: string; sourceDigest: string }>();
let coveredTargets = 0;
const accepted =
result.status === 'evaluated_passed' &&
evaluator?.status === 'passed' &&
evaluator.method === 'host-lean-kernel-all-targets' &&
check?.passed === true &&
typeof check.commit === 'string' &&
check.commit === result.solution_commit &&
typeof check.sourceDigest === 'string' &&
/^[a-f0-9]{64}$/u.test(check.sourceDigest) &&
batch?.schema === 'deepscientist.mathematics.verification-batch/v1' &&
Array.isArray(batch.results) &&
batch.results.every(row => object(row)) &&
targets.length > 0 &&
proofReceiptsMatch(
batch as MathematicsVerifierBatchResult,
check.commit,
targets.map(target => ({
proofPath: target.proofPath,
theoremName: target.theoremName,
expectedSourceDeclarationHash: target.declarationHash,
statementHash: problem.contract.statementHash,
leanStatementHash: problem.contract.leanStatementHash,
claim: 'statement',
})),
);
if (accepted)
for (const row of batch!.results as MathematicsVerifierBatchResult['results']) {
const proof: unknown = object(row.declarationReferences)?.proof;
if (
!Array.isArray(proof) ||
!proof.every(value => {
const item = object(value);
return item && typeof item.name === 'string' && typeof item.file === 'string';
})
)
continue;
coveredTargets++;
for (const value of proof) {
const item = value as { name: string; file: string };
if (!problem.frozenFiles?.[item.file]) continue;
// Private declarations and other installed sources are outside this pinned release's public interface.
let declaration: ReturnType<typeof catalog.declaration>;
try {
declaration = catalog.declaration(item.name);
} catch {
continue;
}
if (declaration.file !== item.file || declaration.sourceDigest !== problem.frozenFiles[item.file]) continue;
references.set(declaration.name, {
name: declaration.name,
file: declaration.file,
sourceDigest: declaration.sourceDigest,
});
}
}
const items = [...references.values()].sort((left, right) => left.name.localeCompare(right.name));
return {
schema: 'theorem-os.web-library-usage.v1' as const,
library: catalog.identity,
installedModules: Object.keys(problem.frozenFiles ?? {}).length,
installationRounds,
proof: {
scope: 'independently-accepted-original-proofs' as const,
coverage: !coveredTargets
? ('unknown' as const)
: coveredTargets === targets.length
? ('available' as const)
: ('partial' as const),
targetCount: targets.length,
coveredTargets,
referenceCount: coveredTargets && coveredTargets === targets.length ? items.length : null,
references: items.slice(0, maxReferences),
omittedReferences: Math.max(0, items.length - maxReferences),
...(accepted ? { commit: check!.commit as string, sourceDigest: check!.sourceDigest as string } : {}),
},
};
}