@nite-framework/nite-zk-profiler 0.2.3 → 0.2.5
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/dist/budget.js +4 -6
- package/dist/cache.d.ts +9 -2
- package/dist/cache.js +16 -2
- package/package.json +1 -1
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
/**
|
|
14
|
-
|
|
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
|
-
/**
|
|
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
|
|
41
|
+
for (const file of files) {
|
|
28
42
|
hash.update(file);
|
|
29
43
|
hash.update(readFileSync(join(zkirDir, file)));
|
|
30
44
|
}
|