@proto-kit/common 0.1.1-develop.2024 → 0.1.1-develop.2137
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/cache/CacheManifest.d.ts +11 -0
- package/dist/cache/CacheManifest.d.ts.map +1 -0
- package/dist/cache/CacheManifest.js +56 -0
- package/dist/cache/CacheManifest.js.map +1 -0
- package/dist/cache/ProxyCache.d.ts +13 -0
- package/dist/cache/ProxyCache.d.ts.map +1 -0
- package/dist/cache/ProxyCache.js +24 -0
- package/dist/cache/ProxyCache.js.map +1 -0
- package/dist/cache/RemoteCache.d.ts +8 -0
- package/dist/cache/RemoteCache.d.ts.map +1 -0
- package/dist/cache/RemoteCache.js +2 -0
- package/dist/cache/RemoteCache.js.map +1 -0
- package/dist/cache/RemoteCacheCompiler.d.ts +16 -0
- package/dist/cache/RemoteCacheCompiler.d.ts.map +1 -0
- package/dist/cache/RemoteCacheCompiler.js +104 -0
- package/dist/cache/RemoteCacheCompiler.js.map +1 -0
- package/dist/compiling/AtomicCompileHelper.d.ts +3 -1
- package/dist/compiling/AtomicCompileHelper.d.ts.map +1 -1
- package/dist/compiling/AtomicCompileHelper.js +25 -4
- package/dist/compiling/AtomicCompileHelper.js.map +1 -1
- package/dist/compiling/CompileRegistry.d.ts +4 -5
- package/dist/compiling/CompileRegistry.d.ts.map +1 -1
- package/dist/compiling/CompileRegistry.js +8 -13
- package/dist/compiling/CompileRegistry.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.d.ts +10 -3
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.js +2 -2
- package/dist/zkProgrammable/ZkProgrammable.js.map +1 -1
- package/package.json +3 -2
- package/src/cache/CacheManifest.ts +57 -0
- package/src/cache/ProxyCache.ts +30 -0
- package/src/cache/RemoteCache.ts +9 -0
- package/src/cache/RemoteCacheCompiler.ts +131 -0
- package/src/compiling/AtomicCompileHelper.ts +11 -2
- package/src/compiling/CompileRegistry.ts +7 -17
- package/src/index.ts +4 -0
- package/src/zkProgrammable/ZkProgrammable.ts +19 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class CacheManifest {
|
|
2
|
+
manifestFile(): string;
|
|
3
|
+
manifestRead: boolean;
|
|
4
|
+
manifest: string[];
|
|
5
|
+
private readManifest;
|
|
6
|
+
private ensureManifestRead;
|
|
7
|
+
getManifest(): string[];
|
|
8
|
+
writeToManifest(program: string): void;
|
|
9
|
+
includes(program: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=CacheManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheManifest.d.ts","sourceRoot":"","sources":["../../src/cache/CacheManifest.ts"],"names":[],"mappings":"AAMA,qBAEa,aAAa;IACjB,YAAY,IAAI,MAAM;IAQ7B,YAAY,UAAS;IAErB,QAAQ,EAAE,MAAM,EAAE,CAAM;IAExB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,kBAAkB;IAOnB,WAAW;IAMX,eAAe,CAAC,OAAO,EAAE,MAAM;IAS/B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAK1C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import { injectable, singleton } from "tsyringe";
|
|
10
|
+
import cachedir from "cachedir";
|
|
11
|
+
export let CacheManifest = class CacheManifest {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.manifestRead = false;
|
|
14
|
+
this.manifest = [];
|
|
15
|
+
}
|
|
16
|
+
manifestFile() {
|
|
17
|
+
return path.format({
|
|
18
|
+
dir: cachedir("o1js"),
|
|
19
|
+
name: "protokit-cache-manifest",
|
|
20
|
+
ext: "json",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
readManifest() {
|
|
24
|
+
const file = this.manifestFile();
|
|
25
|
+
if (fs.existsSync(file)) {
|
|
26
|
+
return JSON.parse(fs.readFileSync(file).toString());
|
|
27
|
+
}
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
ensureManifestRead() {
|
|
31
|
+
if (!this.manifestRead) {
|
|
32
|
+
this.manifest = this.readManifest();
|
|
33
|
+
this.manifestRead = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getManifest() {
|
|
37
|
+
this.ensureManifestRead();
|
|
38
|
+
return this.manifest;
|
|
39
|
+
}
|
|
40
|
+
writeToManifest(program) {
|
|
41
|
+
this.ensureManifestRead();
|
|
42
|
+
if (!this.manifest.includes(program)) {
|
|
43
|
+
this.manifest.push(program);
|
|
44
|
+
fs.writeFileSync(this.manifestFile(), JSON.stringify(this.manifest));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
includes(program) {
|
|
48
|
+
this.ensureManifestRead();
|
|
49
|
+
return this.manifest.includes(program);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
CacheManifest = __decorate([
|
|
53
|
+
injectable(),
|
|
54
|
+
singleton()
|
|
55
|
+
], CacheManifest);
|
|
56
|
+
//# sourceMappingURL=CacheManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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ACpC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;SACtE;IACH,CAAC;IAEM,QAAQ,CAAC,OAAe;QAC7B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAE1B,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF,CAAA;AAhDY,aAAa;IAFzB,UAAU,EAAE;IACZ,SAAS,EAAE;GACC,aAAa,CAgDzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CacheHeader, Cache as O1Cache } from "o1js";
|
|
2
|
+
export declare class ProxyCache implements O1Cache {
|
|
3
|
+
private realCache;
|
|
4
|
+
private log;
|
|
5
|
+
canWrite: boolean;
|
|
6
|
+
debug: boolean;
|
|
7
|
+
cacheDirectory: string | undefined;
|
|
8
|
+
read(header: CacheHeader): Uint8Array | undefined;
|
|
9
|
+
write(header: CacheHeader, value: Uint8Array): void;
|
|
10
|
+
getLog(): string[];
|
|
11
|
+
startLog(): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ProxyCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyCache.d.ts","sourceRoot":"","sources":["../../src/cache/ProxyCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,MAAM,CAAC;AAErD,qBAAa,UAAW,YAAW,OAAO;IACxC,OAAO,CAAC,SAAS,CAA6B;IAE9C,OAAO,CAAC,GAAG,CAAgB;IAE3B,QAAQ,UAAQ;IAEhB,KAAK,UAAS;IAEd,cAAc,qBAAiC;IAExC,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,SAAS;IAIjD,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAKnD,MAAM;IAIN,QAAQ;CAGhB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Cache as O1Cache } from "o1js";
|
|
2
|
+
export class ProxyCache {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.realCache = O1Cache.FileSystemDefault;
|
|
5
|
+
this.log = [];
|
|
6
|
+
this.canWrite = true;
|
|
7
|
+
this.debug = false;
|
|
8
|
+
this.cacheDirectory = this.realCache.cacheDirectory;
|
|
9
|
+
}
|
|
10
|
+
read(header) {
|
|
11
|
+
return this.realCache.read(header);
|
|
12
|
+
}
|
|
13
|
+
write(header, value) {
|
|
14
|
+
this.log.push(header.persistentId);
|
|
15
|
+
return this.realCache.write(header, value);
|
|
16
|
+
}
|
|
17
|
+
getLog() {
|
|
18
|
+
return this.log;
|
|
19
|
+
}
|
|
20
|
+
startLog() {
|
|
21
|
+
this.log = [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ProxyCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyCache.js","sourceRoot":"","sources":["../../src/cache/ProxyCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,IAAI,OAAO,EAAE,MAAM,MAAM,CAAC;AAErD,MAAM,OAAO,UAAU;IAAvB;QACU,cAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAEtC,QAAG,GAAa,EAAE,CAAC;QAE3B,aAAQ,GAAG,IAAI,CAAC;QAEhB,UAAK,GAAG,KAAK,CAAC;QAEd,mBAAc,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;IAkBjD,CAAC;IAhBQ,IAAI,CAAC,MAAmB;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,MAAmB,EAAE,KAAiB;QACjD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,QAAQ;QACb,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
export interface RemoteCache {
|
|
4
|
+
storeObject(program: string, object: string, file: Readable): Promise<void>;
|
|
5
|
+
getObjects(program: string): Promise<string[]>;
|
|
6
|
+
readObject(program: string, object: string): Promise<Readable>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=RemoteCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCache.d.ts","sourceRoot":"","sources":["../../src/cache/RemoteCache.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5E,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE/C,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCache.js","sourceRoot":"","sources":["../../src/cache/RemoteCache.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CompileArtifact, PlainZkProgram } from "../zkProgrammable/ZkProgrammable";
|
|
2
|
+
import { RemoteCache } from "./RemoteCache";
|
|
3
|
+
import { CacheManifest } from "./CacheManifest";
|
|
4
|
+
export declare class RemoteCacheCompiler {
|
|
5
|
+
private readonly remoteCache;
|
|
6
|
+
private readonly manifest;
|
|
7
|
+
constructor(remoteCache: RemoteCache | undefined, manifest: CacheManifest);
|
|
8
|
+
private getFileFromObjectName;
|
|
9
|
+
private download;
|
|
10
|
+
private uploadFile;
|
|
11
|
+
private upload;
|
|
12
|
+
private isSRSFile;
|
|
13
|
+
private compileWithRemoteCache;
|
|
14
|
+
compileWithCache(program: Pick<PlainZkProgram, "name" | "compile">): Promise<CompileArtifact>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=RemoteCacheCompiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCacheCompiler.d.ts","sourceRoot":"","sources":["../../src/cache/RemoteCacheCompiler.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,eAAe,EACf,cAAc,EACf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAEa,mBAAmB;IAG5B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,WAAW,EAAE,WAAW,GAAG,SAAS,EACpC,QAAQ,EAAE,aAAa;IAW1C,OAAO,CAAC,qBAAqB;YASf,QAAQ;YAkBR,UAAU;YAUV,MAAM;IAWpB,OAAO,CAAC,SAAS;YAIH,sBAAsB;IAmCvB,gBAAgB,CAC3B,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC,GAChD,OAAO,CAAC,eAAe,CAAC;CAO5B"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { inject, injectable, Lifecycle, scoped } from "tsyringe";
|
|
16
|
+
import cachedir from "cachedir";
|
|
17
|
+
import { log } from "../log";
|
|
18
|
+
import { mapSequential } from "../utils";
|
|
19
|
+
import { ProxyCache } from "./ProxyCache";
|
|
20
|
+
import { CacheManifest } from "./CacheManifest";
|
|
21
|
+
export let RemoteCacheCompiler = class RemoteCacheCompiler {
|
|
22
|
+
constructor(remoteCache, manifest) {
|
|
23
|
+
this.remoteCache = remoteCache;
|
|
24
|
+
this.manifest = manifest;
|
|
25
|
+
if (remoteCache === undefined) {
|
|
26
|
+
log.debug("No remote cache configured, only using local file system cache for circuits");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
log.debug("Using remote cache for circuit caching");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
getFileFromObjectName(object) {
|
|
33
|
+
const dir = cachedir("o1js");
|
|
34
|
+
return path.format({
|
|
35
|
+
dir,
|
|
36
|
+
base: object,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async download(remoteCache, name) {
|
|
40
|
+
const objects = await remoteCache.getObjects(name);
|
|
41
|
+
log.debug(`Downloading ${objects.length} cached objects for ${name}`);
|
|
42
|
+
await mapSequential(objects, async (object) => {
|
|
43
|
+
const readable = await remoteCache.readObject(name, object);
|
|
44
|
+
const file = this.getFileFromObjectName(object);
|
|
45
|
+
const writeStream = fs.createWriteStream(file);
|
|
46
|
+
readable.pipe(writeStream);
|
|
47
|
+
await new Promise((res) => {
|
|
48
|
+
writeStream.on("close", res);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async uploadFile(remoteCache, program, fileName) {
|
|
53
|
+
const file = path.resolve(cachedir("o1js"), fileName);
|
|
54
|
+
const readStream = fs.createReadStream(file);
|
|
55
|
+
await remoteCache.storeObject(program, fileName, readStream);
|
|
56
|
+
}
|
|
57
|
+
async upload(remoteCache, name, identifiers) {
|
|
58
|
+
await mapSequential(identifiers, async (identifier) => {
|
|
59
|
+
await this.uploadFile(remoteCache, name, identifier);
|
|
60
|
+
await this.uploadFile(remoteCache, name, `${identifier}.header`);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
isSRSFile(file) {
|
|
64
|
+
return file.includes("srs-") || file.includes("lagrange-");
|
|
65
|
+
}
|
|
66
|
+
async compileWithRemoteCache(remoteCache, program) {
|
|
67
|
+
const { name } = program;
|
|
68
|
+
if (!this.manifest.includes("srs")) {
|
|
69
|
+
await this.download(remoteCache, "srs");
|
|
70
|
+
}
|
|
71
|
+
if (!this.manifest.includes(name)) {
|
|
72
|
+
await this.download(remoteCache, name);
|
|
73
|
+
}
|
|
74
|
+
const cache = new ProxyCache();
|
|
75
|
+
cache.startLog();
|
|
76
|
+
const result = await program.compile({
|
|
77
|
+
cache,
|
|
78
|
+
});
|
|
79
|
+
const files = cache.getLog();
|
|
80
|
+
log.debug("Uploading files", files);
|
|
81
|
+
const srsFiles = files.filter((file) => this.isSRSFile(file));
|
|
82
|
+
await this.upload(remoteCache, "srs", srsFiles);
|
|
83
|
+
this.manifest.writeToManifest("srs");
|
|
84
|
+
const circuitFiles = files.filter((file) => !this.isSRSFile(file));
|
|
85
|
+
await this.upload(remoteCache, name, circuitFiles);
|
|
86
|
+
this.manifest.writeToManifest(name);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
async compileWithCache(program) {
|
|
90
|
+
if (this.remoteCache !== undefined) {
|
|
91
|
+
return await this.compileWithRemoteCache(this.remoteCache, program);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return await program.compile();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
RemoteCacheCompiler = __decorate([
|
|
99
|
+
injectable(),
|
|
100
|
+
scoped(Lifecycle.ContainerScoped),
|
|
101
|
+
__param(0, inject("RemoteCache", { isOptional: true })),
|
|
102
|
+
__metadata("design:paramtypes", [Object, CacheManifest])
|
|
103
|
+
], RemoteCacheCompiler);
|
|
104
|
+
//# sourceMappingURL=RemoteCacheCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCacheCompiler.js","sourceRoot":"","sources":["../../src/cache/RemoteCacheCompiler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAOzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIzC,WAAM,mBAAm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;GAJ/B,mBAAmB,CA+G/B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AreProofsEnabled, CompileArtifact } from "../zkProgrammable/ZkProgrammable";
|
|
2
|
+
import { RemoteCacheCompiler } from "../cache/RemoteCacheCompiler";
|
|
2
3
|
export type ArtifactRecord = Record<string, CompileArtifact>;
|
|
3
4
|
export type CompileTarget = {
|
|
4
5
|
name: string;
|
|
@@ -6,7 +7,8 @@ export type CompileTarget = {
|
|
|
6
7
|
};
|
|
7
8
|
export declare class AtomicCompileHelper {
|
|
8
9
|
private readonly areProofsEnabled;
|
|
9
|
-
|
|
10
|
+
private readonly remoteCacheCompiler;
|
|
11
|
+
constructor(areProofsEnabled: AreProofsEnabled, remoteCacheCompiler: RemoteCacheCompiler);
|
|
10
12
|
private compilationPromises;
|
|
11
13
|
compileContract(contract: CompileTarget, overrideProofsEnabled?: boolean): Promise<CompileArtifact>;
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomicCompileHelper.d.ts","sourceRoot":"","sources":["../../src/compiling/AtomicCompileHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AtomicCompileHelper.d.ts","sourceRoot":"","sources":["../../src/compiling/AtomicCompileHelper.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,eAAe,EAEhB,MAAM,kCAAkC,CAAC;AAI1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CACzC,CAAC;AAEF,qBACa,mBAAmB;IAG5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;gBADnB,gBAAgB,EAAE,gBAAgB,EAClC,mBAAmB,EAAE,mBAAmB;IAG3D,OAAO,CAAC,mBAAmB,CAEpB;IAEM,eAAe,CAC1B,QAAQ,EAAE,aAAa,EACvB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,eAAe,CAAC;CAoC5B"}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { inject, injectable } from "tsyringe";
|
|
1
14
|
import { MOCK_VERIFICATION_KEY, } from "../zkProgrammable/ZkProgrammable";
|
|
2
15
|
import { isSubtypeOfName } from "../utils";
|
|
3
16
|
import { log } from "../log";
|
|
4
|
-
|
|
5
|
-
|
|
17
|
+
import { RemoteCacheCompiler } from "../cache/RemoteCacheCompiler";
|
|
18
|
+
export let AtomicCompileHelper = class AtomicCompileHelper {
|
|
19
|
+
constructor(areProofsEnabled, remoteCacheCompiler) {
|
|
6
20
|
this.areProofsEnabled = areProofsEnabled;
|
|
21
|
+
this.remoteCacheCompiler = remoteCacheCompiler;
|
|
7
22
|
this.compilationPromises = {};
|
|
8
23
|
}
|
|
9
24
|
async compileContract(contract, overrideProofsEnabled) {
|
|
@@ -20,7 +35,8 @@ export class AtomicCompileHelper {
|
|
|
20
35
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
21
36
|
contract, "SmartContract")) {
|
|
22
37
|
log.time(`Compiling ${name}`);
|
|
23
|
-
this.compilationPromises[name] =
|
|
38
|
+
this.compilationPromises[name] =
|
|
39
|
+
this.remoteCacheCompiler.compileWithCache(contract);
|
|
24
40
|
newPromise = true;
|
|
25
41
|
}
|
|
26
42
|
else {
|
|
@@ -36,5 +52,10 @@ export class AtomicCompileHelper {
|
|
|
36
52
|
}
|
|
37
53
|
return result;
|
|
38
54
|
}
|
|
39
|
-
}
|
|
55
|
+
};
|
|
56
|
+
AtomicCompileHelper = __decorate([
|
|
57
|
+
injectable(),
|
|
58
|
+
__param(0, inject("AreProofsEnabled")),
|
|
59
|
+
__metadata("design:paramtypes", [Object, RemoteCacheCompiler])
|
|
60
|
+
], AtomicCompileHelper);
|
|
40
61
|
//# sourceMappingURL=AtomicCompileHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomicCompileHelper.js","sourceRoot":"","sources":["../../src/compiling/AtomicCompileHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,qBAAqB,GACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"AtomicCompileHelper.js","sourceRoot":"","sources":["../../src/compiling/AtomicCompileHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAGL,qBAAqB,GACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;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pD,IAAI,UAAU,EAAE;YACd,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;SACvC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAlDY,mBAAmB;IAD/B,UAAU,EAAE;IAGR,WAAA,MAAM,CAAC,kBAAkB,CAAC,CAAA;6CAEW,mBAAmB;GAJhD,mBAAmB,CAkD/B"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ArtifactRecord, CompileTarget } from "./AtomicCompileHelper";
|
|
1
|
+
import { CompileArtifact } from "../zkProgrammable/ZkProgrammable";
|
|
2
|
+
import { ArtifactRecord, AtomicCompileHelper, CompileTarget } from "./AtomicCompileHelper";
|
|
3
3
|
/**
|
|
4
4
|
* The CompileRegistry compiles "compilable modules"
|
|
5
5
|
* (i.e. zkprograms, contracts or contractmodules)
|
|
6
6
|
* while making sure they don't get compiled twice in the same process in parallel.
|
|
7
7
|
*/
|
|
8
8
|
export declare class CompileRegistry {
|
|
9
|
-
private readonly
|
|
10
|
-
constructor(
|
|
11
|
-
private compiler;
|
|
9
|
+
private readonly compiler;
|
|
10
|
+
constructor(compiler: AtomicCompileHelper);
|
|
12
11
|
private artifacts;
|
|
13
12
|
private inForceProverBlock;
|
|
14
13
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompileRegistry.d.ts","sourceRoot":"","sources":["../../src/compiling/CompileRegistry.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"CompileRegistry.d.ts","sourceRoot":"","sources":["../../src/compiling/CompileRegistry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAEa,eAAe;IACP,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,mBAAmB;IAEjE,OAAO,CAAC,SAAS,CAAsB;IAEvC,OAAO,CAAC,kBAAkB,CAAK;IAE/B;;;;;OAKG;IACU,iBAAiB,CAAC,CAAC,EAC9B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3C,OAAO,CAAC,CAAC,CAAC;IAOA,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,CAAC,EAAE,MAAM;IAU1D,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAItD,eAAe,CAAC,SAAS,EAAE,cAAc;IAOzC,eAAe;CAGvB"}
|
|
@@ -7,10 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { inject, injectable, singleton } from "tsyringe";
|
|
10
|
+
import { injectable, singleton } from "tsyringe";
|
|
14
11
|
import { AtomicCompileHelper, } from "./AtomicCompileHelper";
|
|
15
12
|
/**
|
|
16
13
|
* The CompileRegistry compiles "compilable modules"
|
|
@@ -18,11 +15,10 @@ import { AtomicCompileHelper, } from "./AtomicCompileHelper";
|
|
|
18
15
|
* while making sure they don't get compiled twice in the same process in parallel.
|
|
19
16
|
*/
|
|
20
17
|
export let CompileRegistry = class CompileRegistry {
|
|
21
|
-
constructor(
|
|
22
|
-
this.
|
|
18
|
+
constructor(compiler) {
|
|
19
|
+
this.compiler = compiler;
|
|
23
20
|
this.artifacts = {};
|
|
24
|
-
this.inForceProverBlock =
|
|
25
|
-
this.compiler = new AtomicCompileHelper(this.areProofsEnabled);
|
|
21
|
+
this.inForceProverBlock = 0;
|
|
26
22
|
}
|
|
27
23
|
/**
|
|
28
24
|
* This function forces compilation even if the artifact itself is in the registry.
|
|
@@ -31,14 +27,14 @@ export let CompileRegistry = class CompileRegistry {
|
|
|
31
27
|
* This is true for non-sideloaded circuit dependencies.
|
|
32
28
|
*/
|
|
33
29
|
async forceProverExists(f) {
|
|
34
|
-
this.inForceProverBlock
|
|
30
|
+
this.inForceProverBlock += 1;
|
|
35
31
|
const result = await f(this);
|
|
36
|
-
this.inForceProverBlock
|
|
32
|
+
this.inForceProverBlock -= 1;
|
|
37
33
|
return result;
|
|
38
34
|
}
|
|
39
35
|
async compile(target, nameOverride) {
|
|
40
36
|
const name = nameOverride ?? target.name;
|
|
41
|
-
if (this.artifacts[name] === undefined || this.inForceProverBlock) {
|
|
37
|
+
if (this.artifacts[name] === undefined || this.inForceProverBlock > 0) {
|
|
42
38
|
const artifact = await this.compiler.compileContract(target);
|
|
43
39
|
this.artifacts[name] = artifact;
|
|
44
40
|
return artifact;
|
|
@@ -61,7 +57,6 @@ export let CompileRegistry = class CompileRegistry {
|
|
|
61
57
|
CompileRegistry = __decorate([
|
|
62
58
|
injectable(),
|
|
63
59
|
singleton(),
|
|
64
|
-
|
|
65
|
-
__metadata("design:paramtypes", [Object])
|
|
60
|
+
__metadata("design:paramtypes", [AtomicCompileHelper])
|
|
66
61
|
], CompileRegistry);
|
|
67
62
|
//# sourceMappingURL=CompileRegistry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompileRegistry.js","sourceRoot":"","sources":["../../src/compiling/CompileRegistry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CompileRegistry.js","sourceRoot":"","sources":["../../src/compiling/CompileRegistry.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIjD,OAAO,EAEL,mBAAmB,GAEpB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AAGI,WAAM,e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,eAAe,CA8C3B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -29,4 +29,8 @@ export * from "./compiling/AtomicCompileHelper";
|
|
|
29
29
|
export * from "./compiling/CompileRegistry";
|
|
30
30
|
export * from "./compiling/CompilableModule";
|
|
31
31
|
export * from "./compiling/services/ChildVerificationKeyService";
|
|
32
|
+
export * from "./cache/RemoteCache";
|
|
33
|
+
export * from "./cache/RemoteCacheCompiler";
|
|
34
|
+
export * from "./cache/CacheManifest";
|
|
35
|
+
export * from "./cache/ProxyCache";
|
|
32
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kDAAkD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kDAAkD,CAAC;AACjE,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -29,4 +29,8 @@ export * from "./compiling/AtomicCompileHelper";
|
|
|
29
29
|
export * from "./compiling/CompileRegistry";
|
|
30
30
|
export * from "./compiling/CompilableModule";
|
|
31
31
|
export * from "./compiling/services/ChildVerificationKeyService";
|
|
32
|
+
export * from "./cache/RemoteCache";
|
|
33
|
+
export * from "./cache/RemoteCacheCompiler";
|
|
34
|
+
export * from "./cache/CacheManifest";
|
|
35
|
+
export * from "./cache/ProxyCache";
|
|
32
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kDAAkD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kDAAkD,CAAC;AACjE,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ZkProgram, FlexibleProvablePure, Proof, Field, Provable } from "o1js";
|
|
1
|
+
import { ZkProgram, FlexibleProvablePure, Proof, Field, Provable, Cache as O1Cache } from "o1js";
|
|
2
2
|
import type { CompileRegistry } from "../compiling/CompileRegistry";
|
|
3
3
|
export interface CompileArtifact {
|
|
4
4
|
verificationKey: {
|
|
@@ -14,7 +14,14 @@ export interface Verify<PublicInput, PublicOutput> {
|
|
|
14
14
|
(proof: Proof<PublicInput, PublicOutput>): Promise<boolean>;
|
|
15
15
|
}
|
|
16
16
|
export interface Compile {
|
|
17
|
-
(
|
|
17
|
+
(options?: {
|
|
18
|
+
cache?: O1Cache;
|
|
19
|
+
forceRecompile?: boolean;
|
|
20
|
+
proofsEnabled?: boolean;
|
|
21
|
+
withRuntimeTables?: boolean;
|
|
22
|
+
numChunks?: number;
|
|
23
|
+
lazyMode?: boolean;
|
|
24
|
+
}): Promise<CompileArtifact>;
|
|
18
25
|
}
|
|
19
26
|
export interface PlainZkProgram<PublicInput = undefined, PublicOutput = undefined> {
|
|
20
27
|
name: string;
|
|
@@ -32,7 +39,7 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = undefine
|
|
|
32
39
|
}
|
|
33
40
|
export declare function verifyToMockable<PublicInput, PublicOutput>(verify: Verify<PublicInput, PublicOutput>, { areProofsEnabled }: AreProofsEnabled): (proof: Proof<PublicInput, PublicOutput>) => Promise<boolean>;
|
|
34
41
|
export declare const MOCK_VERIFICATION_KEY: import("o1js/dist/node/lib/proof-system/verification-key").VerificationKey;
|
|
35
|
-
export declare function compileToMockable(compile: Compile, { areProofsEnabled }: AreProofsEnabled):
|
|
42
|
+
export declare function compileToMockable(compile: Compile, { areProofsEnabled }: AreProofsEnabled): Compile;
|
|
36
43
|
export declare abstract class ZkProgrammable<PublicInput = undefined, PublicOutput = void> {
|
|
37
44
|
abstract get areProofsEnabled(): AreProofsEnabled | undefined;
|
|
38
45
|
abstract zkProgramFactory(): PlainZkProgram<PublicInput, PublicOutput>[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,KAAK,EACL,KAAK,EACL,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AAc,EAAE,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;CAC3D"}
|
|
@@ -34,9 +34,9 @@ export function verifyToMockable(verify, { areProofsEnabled }) {
|
|
|
34
34
|
}
|
|
35
35
|
export const MOCK_VERIFICATION_KEY = dummyVerificationKey();
|
|
36
36
|
export function compileToMockable(compile, { areProofsEnabled }) {
|
|
37
|
-
return async () => {
|
|
37
|
+
return async (...args) => {
|
|
38
38
|
if (areProofsEnabled) {
|
|
39
|
-
return await compile();
|
|
39
|
+
return await compile(...args);
|
|
40
40
|
}
|
|
41
41
|
return {
|
|
42
42
|
verificationKey: MOCK_VERIFICATION_KEY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZkProgrammable.js","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ZkProgrammable.js","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":";;;;;;;;;AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,GAAG;IACb,sBAAsB,EAAE,CAAC,IAAY,EAAE,EAAE,CACvC,IAAI,KAAK,CAAC,0CAA0C,IAAI,EAAE,CAAC;CAC9D,CAAC;AA6DF,MAAM,UAAU,gBAAgB,CAC9B,MAAyC,EACzC,EAAE,gBAAgB,EAAoB;IAEtC,OAAO,KAAK,EAAE,KAAuC,EAAE,EAAE;QACvD,IAAI,gBAAgB,EAAE;YACpB,IAAI,QAAQ,GAAG,KAAK,CAAC;YAErB,IAAI;gBACF,QA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AAC;IACL,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,QAAyB;QAC5C,OAAO,MAAM,gBAAgB,CAC3B,IAAI,CAAC,SAAS,EACd,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;YACrB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC/C,OAAO;gBACL,GAAG,GAAG;gBACN,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM;aACvB,CAAC;QACJ,CAAC;QACD,yEAAyE;QACzE,EAAqC,CACtC,CAAC;IACJ,CAAC;CACF;AAhCC;IAAC,OAAO,EAAE;;;+CAgBT"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.1.1-develop.
|
|
6
|
+
"version": "0.1.1-develop.2137+8a7eca31",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"dev": "tsc -p tsconfig.json --watch",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"cachedir": "^2.4.0",
|
|
20
21
|
"lodash": "^4.17.21",
|
|
21
22
|
"loglevel": "^1.8.1",
|
|
22
23
|
"reflect-metadata": "^0.1.13",
|
|
@@ -31,5 +32,5 @@
|
|
|
31
32
|
"@jest/globals": "^29.5.0",
|
|
32
33
|
"@types/lodash": "^4.14.194"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8a7eca319272a15162dc4ad04bdc134b1017716d"
|
|
35
36
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
import { injectable, singleton } from "tsyringe";
|
|
5
|
+
import cachedir from "cachedir";
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
@singleton()
|
|
9
|
+
export class CacheManifest {
|
|
10
|
+
public manifestFile(): string {
|
|
11
|
+
return path.format({
|
|
12
|
+
dir: cachedir("o1js"),
|
|
13
|
+
name: "protokit-cache-manifest",
|
|
14
|
+
ext: "json",
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
manifestRead = false;
|
|
19
|
+
|
|
20
|
+
manifest: string[] = [];
|
|
21
|
+
|
|
22
|
+
private readManifest(): string[] {
|
|
23
|
+
const file = this.manifestFile();
|
|
24
|
+
if (fs.existsSync(file)) {
|
|
25
|
+
return JSON.parse(fs.readFileSync(file).toString());
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private ensureManifestRead() {
|
|
31
|
+
if (!this.manifestRead) {
|
|
32
|
+
this.manifest = this.readManifest();
|
|
33
|
+
this.manifestRead = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public getManifest() {
|
|
38
|
+
this.ensureManifestRead();
|
|
39
|
+
|
|
40
|
+
return this.manifest;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public writeToManifest(program: string) {
|
|
44
|
+
this.ensureManifestRead();
|
|
45
|
+
|
|
46
|
+
if (!this.manifest.includes(program)) {
|
|
47
|
+
this.manifest.push(program);
|
|
48
|
+
fs.writeFileSync(this.manifestFile(), JSON.stringify(this.manifest));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public includes(program: string): boolean {
|
|
53
|
+
this.ensureManifestRead();
|
|
54
|
+
|
|
55
|
+
return this.manifest.includes(program);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CacheHeader, Cache as O1Cache } from "o1js";
|
|
2
|
+
|
|
3
|
+
export class ProxyCache implements O1Cache {
|
|
4
|
+
private realCache = O1Cache.FileSystemDefault;
|
|
5
|
+
|
|
6
|
+
private log: string[] = [];
|
|
7
|
+
|
|
8
|
+
canWrite = true;
|
|
9
|
+
|
|
10
|
+
debug = false;
|
|
11
|
+
|
|
12
|
+
cacheDirectory = this.realCache.cacheDirectory;
|
|
13
|
+
|
|
14
|
+
public read(header: CacheHeader): Uint8Array | undefined {
|
|
15
|
+
return this.realCache.read(header);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public write(header: CacheHeader, value: Uint8Array): void {
|
|
19
|
+
this.log.push(header.persistentId);
|
|
20
|
+
return this.realCache.write(header, value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public getLog() {
|
|
24
|
+
return this.log;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public startLog() {
|
|
28
|
+
this.log = [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
|
|
3
|
+
export interface RemoteCache {
|
|
4
|
+
storeObject(program: string, object: string, file: Readable): Promise<void>;
|
|
5
|
+
|
|
6
|
+
getObjects(program: string): Promise<string[]>;
|
|
7
|
+
|
|
8
|
+
readObject(program: string, object: string): Promise<Readable>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { inject, injectable, Lifecycle, scoped } from "tsyringe";
|
|
5
|
+
import cachedir from "cachedir";
|
|
6
|
+
|
|
7
|
+
import { log } from "../log";
|
|
8
|
+
import { mapSequential } from "../utils";
|
|
9
|
+
import {
|
|
10
|
+
CompileArtifact,
|
|
11
|
+
PlainZkProgram,
|
|
12
|
+
} from "../zkProgrammable/ZkProgrammable";
|
|
13
|
+
|
|
14
|
+
import { RemoteCache } from "./RemoteCache";
|
|
15
|
+
import { ProxyCache } from "./ProxyCache";
|
|
16
|
+
import { CacheManifest } from "./CacheManifest";
|
|
17
|
+
|
|
18
|
+
@injectable()
|
|
19
|
+
@scoped(Lifecycle.ContainerScoped)
|
|
20
|
+
export class RemoteCacheCompiler {
|
|
21
|
+
public constructor(
|
|
22
|
+
@inject("RemoteCache", { isOptional: true })
|
|
23
|
+
private readonly remoteCache: RemoteCache | undefined,
|
|
24
|
+
private readonly manifest: CacheManifest
|
|
25
|
+
) {
|
|
26
|
+
if (remoteCache === undefined) {
|
|
27
|
+
log.debug(
|
|
28
|
+
"No remote cache configured, only using local file system cache for circuits"
|
|
29
|
+
);
|
|
30
|
+
} else {
|
|
31
|
+
log.debug("Using remote cache for circuit caching");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private getFileFromObjectName(object: string): string {
|
|
36
|
+
const dir = cachedir("o1js");
|
|
37
|
+
|
|
38
|
+
return path.format({
|
|
39
|
+
dir,
|
|
40
|
+
base: object,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private async download(remoteCache: RemoteCache, name: string) {
|
|
45
|
+
const objects = await remoteCache.getObjects(name);
|
|
46
|
+
|
|
47
|
+
log.debug(`Downloading ${objects.length} cached objects for ${name}`);
|
|
48
|
+
|
|
49
|
+
await mapSequential(objects, async (object) => {
|
|
50
|
+
const readable = await remoteCache.readObject(name, object);
|
|
51
|
+
const file = this.getFileFromObjectName(object);
|
|
52
|
+
|
|
53
|
+
const writeStream = fs.createWriteStream(file);
|
|
54
|
+
readable.pipe(writeStream);
|
|
55
|
+
|
|
56
|
+
await new Promise<void>((res) => {
|
|
57
|
+
writeStream.on("close", res);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private async uploadFile(
|
|
63
|
+
remoteCache: RemoteCache,
|
|
64
|
+
program: string,
|
|
65
|
+
fileName: string
|
|
66
|
+
) {
|
|
67
|
+
const file = path.resolve(cachedir("o1js"), fileName);
|
|
68
|
+
const readStream = fs.createReadStream(file);
|
|
69
|
+
await remoteCache.storeObject(program, fileName, readStream);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private async upload(
|
|
73
|
+
remoteCache: RemoteCache,
|
|
74
|
+
name: string,
|
|
75
|
+
identifiers: string[]
|
|
76
|
+
) {
|
|
77
|
+
await mapSequential(identifiers, async (identifier) => {
|
|
78
|
+
await this.uploadFile(remoteCache, name, identifier);
|
|
79
|
+
await this.uploadFile(remoteCache, name, `${identifier}.header`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private isSRSFile(file: string): boolean {
|
|
84
|
+
return file.includes("srs-") || file.includes("lagrange-");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async compileWithRemoteCache(
|
|
88
|
+
remoteCache: RemoteCache,
|
|
89
|
+
program: Pick<PlainZkProgram, "name" | "compile">
|
|
90
|
+
) {
|
|
91
|
+
const { name } = program;
|
|
92
|
+
|
|
93
|
+
if (!this.manifest.includes("srs")) {
|
|
94
|
+
await this.download(remoteCache, "srs");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!this.manifest.includes(name)) {
|
|
98
|
+
await this.download(remoteCache, name);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const cache = new ProxyCache();
|
|
102
|
+
cache.startLog();
|
|
103
|
+
|
|
104
|
+
const result = await program.compile({
|
|
105
|
+
cache,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const files = cache.getLog();
|
|
109
|
+
log.debug("Uploading files", files);
|
|
110
|
+
|
|
111
|
+
const srsFiles = files.filter((file) => this.isSRSFile(file));
|
|
112
|
+
await this.upload(remoteCache, "srs", srsFiles);
|
|
113
|
+
this.manifest.writeToManifest("srs");
|
|
114
|
+
|
|
115
|
+
const circuitFiles = files.filter((file) => !this.isSRSFile(file));
|
|
116
|
+
await this.upload(remoteCache, name, circuitFiles);
|
|
117
|
+
this.manifest.writeToManifest(name);
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public async compileWithCache(
|
|
123
|
+
program: Pick<PlainZkProgram, "name" | "compile">
|
|
124
|
+
): Promise<CompileArtifact> {
|
|
125
|
+
if (this.remoteCache !== undefined) {
|
|
126
|
+
return await this.compileWithRemoteCache(this.remoteCache, program);
|
|
127
|
+
} else {
|
|
128
|
+
return await program.compile();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { inject, injectable } from "tsyringe";
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
AreProofsEnabled,
|
|
3
5
|
CompileArtifact,
|
|
@@ -6,6 +8,7 @@ import {
|
|
|
6
8
|
import { isSubtypeOfName } from "../utils";
|
|
7
9
|
import { TypedClass } from "../types";
|
|
8
10
|
import { log } from "../log";
|
|
11
|
+
import { RemoteCacheCompiler } from "../cache/RemoteCacheCompiler";
|
|
9
12
|
|
|
10
13
|
export type ArtifactRecord = Record<string, CompileArtifact>;
|
|
11
14
|
|
|
@@ -14,8 +17,13 @@ export type CompileTarget = {
|
|
|
14
17
|
compile: () => Promise<CompileArtifact>;
|
|
15
18
|
};
|
|
16
19
|
|
|
20
|
+
@injectable()
|
|
17
21
|
export class AtomicCompileHelper {
|
|
18
|
-
public constructor(
|
|
22
|
+
public constructor(
|
|
23
|
+
@inject("AreProofsEnabled")
|
|
24
|
+
private readonly areProofsEnabled: AreProofsEnabled,
|
|
25
|
+
private readonly remoteCacheCompiler: RemoteCacheCompiler
|
|
26
|
+
) {}
|
|
19
27
|
|
|
20
28
|
private compilationPromises: {
|
|
21
29
|
[key: string]: Promise<CompileArtifact>;
|
|
@@ -44,7 +52,8 @@ export class AtomicCompileHelper {
|
|
|
44
52
|
)
|
|
45
53
|
) {
|
|
46
54
|
log.time(`Compiling ${name}`);
|
|
47
|
-
this.compilationPromises[name] =
|
|
55
|
+
this.compilationPromises[name] =
|
|
56
|
+
this.remoteCacheCompiler.compileWithCache(contract);
|
|
48
57
|
newPromise = true;
|
|
49
58
|
} else {
|
|
50
59
|
log.debug(`Compiling ${name} - mock`);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { injectable, singleton } from "tsyringe";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
AreProofsEnabled,
|
|
5
|
-
CompileArtifact,
|
|
6
|
-
} from "../zkProgrammable/ZkProgrammable";
|
|
3
|
+
import { CompileArtifact } from "../zkProgrammable/ZkProgrammable";
|
|
7
4
|
|
|
8
5
|
import {
|
|
9
6
|
ArtifactRecord,
|
|
@@ -19,18 +16,11 @@ import {
|
|
|
19
16
|
@injectable()
|
|
20
17
|
@singleton()
|
|
21
18
|
export class CompileRegistry {
|
|
22
|
-
public constructor(
|
|
23
|
-
@inject("AreProofsEnabled")
|
|
24
|
-
private readonly areProofsEnabled: AreProofsEnabled
|
|
25
|
-
) {
|
|
26
|
-
this.compiler = new AtomicCompileHelper(this.areProofsEnabled);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private compiler: AtomicCompileHelper;
|
|
19
|
+
public constructor(private readonly compiler: AtomicCompileHelper) {}
|
|
30
20
|
|
|
31
21
|
private artifacts: ArtifactRecord = {};
|
|
32
22
|
|
|
33
|
-
private inForceProverBlock =
|
|
23
|
+
private inForceProverBlock = 0;
|
|
34
24
|
|
|
35
25
|
/**
|
|
36
26
|
* This function forces compilation even if the artifact itself is in the registry.
|
|
@@ -41,15 +31,15 @@ export class CompileRegistry {
|
|
|
41
31
|
public async forceProverExists<R>(
|
|
42
32
|
f: (registry: CompileRegistry) => Promise<R>
|
|
43
33
|
): Promise<R> {
|
|
44
|
-
this.inForceProverBlock
|
|
34
|
+
this.inForceProverBlock += 1;
|
|
45
35
|
const result = await f(this);
|
|
46
|
-
this.inForceProverBlock
|
|
36
|
+
this.inForceProverBlock -= 1;
|
|
47
37
|
return result;
|
|
48
38
|
}
|
|
49
39
|
|
|
50
40
|
public async compile(target: CompileTarget, nameOverride?: string) {
|
|
51
41
|
const name = nameOverride ?? target.name;
|
|
52
|
-
if (this.artifacts[name] === undefined || this.inForceProverBlock) {
|
|
42
|
+
if (this.artifacts[name] === undefined || this.inForceProverBlock > 0) {
|
|
53
43
|
const artifact = await this.compiler.compileContract(target);
|
|
54
44
|
this.artifacts[name] = artifact;
|
|
55
45
|
return artifact;
|
package/src/index.ts
CHANGED
|
@@ -29,3 +29,7 @@ export * from "./compiling/AtomicCompileHelper";
|
|
|
29
29
|
export * from "./compiling/CompileRegistry";
|
|
30
30
|
export * from "./compiling/CompilableModule";
|
|
31
31
|
export * from "./compiling/services/ChildVerificationKeyService";
|
|
32
|
+
export * from "./cache/RemoteCache";
|
|
33
|
+
export * from "./cache/RemoteCacheCompiler";
|
|
34
|
+
export * from "./cache/CacheManifest";
|
|
35
|
+
export * from "./cache/ProxyCache";
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ZkProgram,
|
|
3
|
+
FlexibleProvablePure,
|
|
4
|
+
Proof,
|
|
5
|
+
Field,
|
|
6
|
+
Provable,
|
|
7
|
+
Cache as O1Cache,
|
|
8
|
+
} from "o1js";
|
|
2
9
|
import { Memoize } from "typescript-memoize";
|
|
3
10
|
|
|
4
11
|
import { log } from "../log";
|
|
@@ -30,7 +37,14 @@ export interface Verify<PublicInput, PublicOutput> {
|
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
export interface Compile {
|
|
33
|
-
(
|
|
40
|
+
(options?: {
|
|
41
|
+
cache?: O1Cache;
|
|
42
|
+
forceRecompile?: boolean;
|
|
43
|
+
proofsEnabled?: boolean;
|
|
44
|
+
withRuntimeTables?: boolean;
|
|
45
|
+
numChunks?: number;
|
|
46
|
+
lazyMode?: boolean;
|
|
47
|
+
}): Promise<CompileArtifact>;
|
|
34
48
|
}
|
|
35
49
|
|
|
36
50
|
export interface PlainZkProgram<
|
|
@@ -93,10 +107,10 @@ export const MOCK_VERIFICATION_KEY = dummyVerificationKey();
|
|
|
93
107
|
export function compileToMockable(
|
|
94
108
|
compile: Compile,
|
|
95
109
|
{ areProofsEnabled }: AreProofsEnabled
|
|
96
|
-
):
|
|
97
|
-
return async () => {
|
|
110
|
+
): Compile {
|
|
111
|
+
return async (...args) => {
|
|
98
112
|
if (areProofsEnabled) {
|
|
99
|
-
return await compile();
|
|
113
|
+
return await compile(...args);
|
|
100
114
|
}
|
|
101
115
|
|
|
102
116
|
return {
|