@nite-framework/nite-zk-profiler 0.2.4 → 0.2.6

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.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # nite-zk-profiler
2
2
 
3
+ This project extends the Midnight Network with additional developer tooling.
4
+
3
5
  See what a Compact circuit costs to prove, while you are still writing it.
4
6
 
5
7
  No proving keys. No real proof. A small contract reports in under a second, and a thirteen circuit production contract in about thirty, nearly all of which is the Compact compiler itself. Measuring the same contract by generating proving keys takes far longer.
package/dist/budget.js CHANGED
@@ -115,12 +115,10 @@ export function check(measured, budget, strict) {
115
115
  const rows = [];
116
116
  let failed = false;
117
117
  for (const { source, costs } of measured) {
118
- const declared = budget.contracts[source]?.circuits ??
119
- // A legacy budget stores its single contract under "", so fall back to it
120
- // when only one contract is declared and the path does not match.
121
- (Object.keys(budget.contracts).length === 1
122
- ? Object.values(budget.contracts)[0].circuits
123
- : {});
118
+ // A legacy budget stores its single contract under the empty key, so fall
119
+ // back to it only in that case. Matching any single contract budget would
120
+ // silently check a second contract against the first one's ceilings.
121
+ const declared = budget.contracts[source]?.circuits ?? budget.contracts[""]?.circuits ?? {};
124
122
  for (const cost of costs) {
125
123
  const entry = declared[cost.circuit];
126
124
  if (!entry) {
package/dist/cache.d.ts CHANGED
@@ -10,7 +10,14 @@ import type { Toolchain } from "./toolchain.ts";
10
10
  * timestamp or a partial import scan could.
11
11
  */
12
12
  export declare function cacheDir(): string;
13
- /** Hash every emitted IR file, plus the toolchain that produced and reads it. */
14
- export declare function cacheKey(zkirDir: string, toolchain: Toolchain): string;
13
+ /**
14
+ * Hash every emitted IR file, plus the toolchain that produced and reads it.
15
+ *
16
+ * Returns undefined when the IR directory cannot be read, which happens for a
17
+ * contract with no provable circuits. Caching is an optimisation, so it must
18
+ * never be the thing that reports that: it would preempt the guard in
19
+ * `measure` and surface a raw ENOENT instead of the explanation.
20
+ */
21
+ export declare function cacheKey(zkirDir: string, toolchain: Toolchain): string | undefined;
15
22
  export declare function readCache(key: string): Measurement[] | undefined;
16
23
  export declare function writeCache(key: string, measurements: Measurement[]): void;
package/dist/cache.js CHANGED
@@ -15,8 +15,22 @@ import { toolVersion } from "./version.js";
15
15
  export function cacheDir() {
16
16
  return process.env.NITE_ZK_CACHE || join(tmpdir(), "nite-zk-profiler-cache");
17
17
  }
18
- /** Hash every emitted IR file, plus the toolchain that produced and reads it. */
18
+ /**
19
+ * Hash every emitted IR file, plus the toolchain that produced and reads it.
20
+ *
21
+ * Returns undefined when the IR directory cannot be read, which happens for a
22
+ * contract with no provable circuits. Caching is an optimisation, so it must
23
+ * never be the thing that reports that: it would preempt the guard in
24
+ * `measure` and surface a raw ENOENT instead of the explanation.
25
+ */
19
26
  export function cacheKey(zkirDir, toolchain) {
27
+ let files;
28
+ try {
29
+ files = readdirSync(zkirDir).filter((f) => f.endsWith(".zkir")).sort();
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
20
34
  const hash = createHash("sha256");
21
35
  // The profiler's own version is part of the key. Without it, upgrading the
22
36
  // tool would keep serving results produced by the previous measurement code,
@@ -24,7 +38,7 @@ export function cacheKey(zkirDir, toolchain) {
24
38
  hash.update(toolVersion());
25
39
  hash.update(toolchain.version);
26
40
  hash.update(toolchain.zkirVersion);
27
- for (const file of readdirSync(zkirDir).filter((f) => f.endsWith(".zkir")).sort()) {
41
+ for (const file of files) {
28
42
  hash.update(file);
29
43
  hash.update(readFileSync(join(zkirDir, file)));
30
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nite-framework/nite-zk-profiler",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "See what a Compact circuit costs to prove, without generating proving keys",
5
5
  "type": "module",
6
6
  "bin": {