@aztec/prover-client 0.69.1 → 0.71.0

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.
Files changed (130) hide show
  1. package/dest/bin/get-proof-inputs.d.ts +2 -0
  2. package/dest/bin/get-proof-inputs.d.ts.map +1 -0
  3. package/dest/bin/get-proof-inputs.js +50 -0
  4. package/dest/block_builder/light.d.ts +3 -5
  5. package/dest/block_builder/light.d.ts.map +1 -1
  6. package/dest/block_builder/light.js +9 -22
  7. package/dest/config.d.ts +2 -1
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +3 -2
  10. package/dest/mocks/fixtures.d.ts +1 -1
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +2 -2
  13. package/dest/mocks/test_context.d.ts +1 -1
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +11 -12
  16. package/dest/orchestrator/block-building-helpers.d.ts +15 -29
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +51 -58
  19. package/dest/orchestrator/block-proving-state.d.ts +40 -44
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +149 -85
  22. package/dest/orchestrator/epoch-proving-state.d.ts +23 -30
  23. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/epoch-proving-state.js +92 -65
  25. package/dest/orchestrator/orchestrator.d.ts +17 -48
  26. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  27. package/dest/orchestrator/orchestrator.js +208 -351
  28. package/dest/orchestrator/tx-proving-state.d.ts +10 -6
  29. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  30. package/dest/orchestrator/tx-proving-state.js +57 -46
  31. package/dest/prover-agent/memory-proving-queue.d.ts +4 -4
  32. package/dest/prover-agent/memory-proving-queue.d.ts.map +1 -1
  33. package/dest/prover-agent/memory-proving-queue.js +5 -5
  34. package/dest/prover-agent/prover-agent.d.ts +0 -2
  35. package/dest/prover-agent/prover-agent.d.ts.map +1 -1
  36. package/dest/prover-agent/prover-agent.js +7 -9
  37. package/dest/prover-client/factory.d.ts.map +1 -1
  38. package/dest/prover-client/factory.js +3 -3
  39. package/dest/prover-client/prover-client.d.ts +4 -2
  40. package/dest/prover-client/prover-client.d.ts.map +1 -1
  41. package/dest/prover-client/prover-client.js +16 -15
  42. package/dest/prover-client/server-epoch-prover.d.ts +25 -0
  43. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -0
  44. package/dest/prover-client/server-epoch-prover.js +40 -0
  45. package/dest/proving_broker/broker_prover_facade.d.ts +19 -7
  46. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  47. package/dest/proving_broker/broker_prover_facade.js +271 -49
  48. package/dest/proving_broker/config.d.ts +61 -0
  49. package/dest/proving_broker/config.d.ts.map +1 -0
  50. package/dest/proving_broker/config.js +83 -0
  51. package/dest/proving_broker/factory.d.ts +1 -1
  52. package/dest/proving_broker/factory.d.ts.map +1 -1
  53. package/dest/proving_broker/factory.js +4 -7
  54. package/dest/proving_broker/fixtures.d.ts +5 -0
  55. package/dest/proving_broker/fixtures.d.ts.map +1 -0
  56. package/dest/proving_broker/fixtures.js +12 -0
  57. package/dest/proving_broker/index.d.ts +2 -1
  58. package/dest/proving_broker/index.d.ts.map +1 -1
  59. package/dest/proving_broker/index.js +3 -2
  60. package/dest/proving_broker/proof_store/factory.d.ts +6 -0
  61. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -0
  62. package/dest/proving_broker/proof_store/factory.js +39 -0
  63. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +13 -0
  64. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -0
  65. package/dest/proving_broker/proof_store/gcs_proof_store.js +46 -0
  66. package/dest/proving_broker/proof_store/index.d.ts +4 -0
  67. package/dest/proving_broker/proof_store/index.d.ts.map +1 -0
  68. package/dest/proving_broker/proof_store/index.js +4 -0
  69. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +14 -0
  70. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -0
  71. package/dest/proving_broker/proof_store/inline_proof_store.js +37 -0
  72. package/dest/proving_broker/{proof_store.d.ts → proof_store/proof_store.d.ts} +1 -12
  73. package/dest/proving_broker/proof_store/proof_store.d.ts.map +1 -0
  74. package/dest/proving_broker/proof_store/proof_store.js +2 -0
  75. package/dest/proving_broker/proving_agent.d.ts +4 -4
  76. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  77. package/dest/proving_broker/proving_agent.js +5 -5
  78. package/dest/proving_broker/proving_broker.d.ts +16 -12
  79. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  80. package/dest/proving_broker/proving_broker.js +307 -274
  81. package/dest/proving_broker/proving_broker_database/memory.d.ts +4 -2
  82. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  83. package/dest/proving_broker/proving_broker_database/memory.js +17 -4
  84. package/dest/proving_broker/proving_broker_database/persisted.d.ts +10 -6
  85. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  86. package/dest/proving_broker/proving_broker_database/persisted.js +106 -14
  87. package/dest/proving_broker/proving_broker_database.d.ts +7 -3
  88. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  89. package/dest/proving_broker/proving_job_controller.js +4 -4
  90. package/dest/proving_broker/rpc.d.ts.map +1 -1
  91. package/dest/proving_broker/rpc.js +4 -4
  92. package/dest/test/mock_prover.d.ts +8 -8
  93. package/dest/test/mock_prover.d.ts.map +1 -1
  94. package/dest/test/mock_prover.js +9 -10
  95. package/package.json +14 -12
  96. package/src/bin/get-proof-inputs.ts +60 -0
  97. package/src/block_builder/light.ts +7 -31
  98. package/src/config.ts +4 -4
  99. package/src/mocks/fixtures.ts +1 -1
  100. package/src/mocks/test_context.ts +9 -11
  101. package/src/orchestrator/block-building-helpers.ts +360 -402
  102. package/src/orchestrator/block-proving-state.ts +251 -121
  103. package/src/orchestrator/epoch-proving-state.ts +159 -88
  104. package/src/orchestrator/orchestrator.ts +262 -542
  105. package/src/orchestrator/tx-proving-state.ts +30 -18
  106. package/src/prover-agent/memory-proving-queue.ts +12 -16
  107. package/src/prover-agent/prover-agent.ts +14 -8
  108. package/src/prover-client/factory.ts +2 -3
  109. package/src/prover-client/prover-client.ts +17 -20
  110. package/src/prover-client/server-epoch-prover.ts +44 -0
  111. package/src/proving_broker/broker_prover_facade.ts +347 -67
  112. package/src/proving_broker/config.ts +93 -0
  113. package/src/proving_broker/factory.ts +11 -10
  114. package/src/proving_broker/fixtures.ts +14 -0
  115. package/src/proving_broker/index.ts +2 -1
  116. package/src/proving_broker/proof_store/factory.ts +42 -0
  117. package/src/proving_broker/proof_store/gcs_proof_store.ts +72 -0
  118. package/src/proving_broker/proof_store/index.ts +3 -0
  119. package/src/proving_broker/{proof_store.ts → proof_store/inline_proof_store.ts} +1 -44
  120. package/src/proving_broker/proof_store/proof_store.ts +54 -0
  121. package/src/proving_broker/proving_agent.ts +11 -5
  122. package/src/proving_broker/proving_broker.ts +122 -73
  123. package/src/proving_broker/proving_broker_database/memory.ts +24 -4
  124. package/src/proving_broker/proving_broker_database/persisted.ts +142 -20
  125. package/src/proving_broker/proving_broker_database.ts +8 -3
  126. package/src/proving_broker/proving_job_controller.ts +5 -5
  127. package/src/proving_broker/rpc.ts +2 -3
  128. package/src/test/mock_prover.ts +12 -18
  129. package/dest/proving_broker/proof_store.d.ts.map +0 -1
  130. package/dest/proving_broker/proof_store.js +0 -37
@@ -1,7 +1,6 @@
1
- import { type ProverBrokerConfig } from '@aztec/circuit-types';
2
- import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
3
1
  import { type TelemetryClient } from '@aztec/telemetry-client';
4
2
 
3
+ import { type ProverBrokerConfig } from './config.js';
5
4
  import { ProvingBroker } from './proving_broker.js';
6
5
  import { InMemoryBrokerDatabase } from './proving_broker_database/memory.js';
7
6
  import { KVBrokerDatabase } from './proving_broker_database/persisted.js';
@@ -10,15 +9,17 @@ export async function createAndStartProvingBroker(
10
9
  config: ProverBrokerConfig,
11
10
  client: TelemetryClient,
12
11
  ): Promise<ProvingBroker> {
13
- const database = config.proverBrokerDataDirectory
14
- ? new KVBrokerDatabase(AztecLmdbStore.open(config.proverBrokerDataDirectory), client)
15
- : new InMemoryBrokerDatabase();
12
+ const database = config.dataDirectory ? await KVBrokerDatabase.new(config, client) : new InMemoryBrokerDatabase();
16
13
 
17
- const broker = new ProvingBroker(database, client, {
18
- jobTimeoutMs: config.proverBrokerJobTimeoutMs,
19
- maxRetries: config.proverBrokerJobMaxRetries,
20
- timeoutIntervalMs: config.proverBrokerPollIntervalMs,
21
- });
14
+ const broker = new ProvingBroker(
15
+ database,
16
+ {
17
+ jobTimeoutMs: config.proverBrokerJobTimeoutMs,
18
+ maxRetries: config.proverBrokerJobMaxRetries,
19
+ timeoutIntervalMs: config.proverBrokerPollIntervalMs,
20
+ },
21
+ client,
22
+ );
22
23
 
23
24
  await broker.start();
24
25
  return broker;
@@ -0,0 +1,14 @@
1
+ import { type ProofUri, type ProvingJobId, ProvingRequestType, makeProvingJobId } from '@aztec/circuit-types';
2
+ import { randomBytes } from '@aztec/foundation/crypto';
3
+
4
+ export function makeRandomProvingJobId(epochNumber?: number): ProvingJobId {
5
+ return makeProvingJobId(epochNumber ?? 1, ProvingRequestType.BASE_PARITY, randomBytes(8).toString('hex'));
6
+ }
7
+
8
+ export function makeInputsUri(): ProofUri {
9
+ return randomBytes(8).toString('hex') as ProofUri;
10
+ }
11
+
12
+ export function makeOutputsUri(): ProofUri {
13
+ return randomBytes(8).toString('hex') as ProofUri;
14
+ }
@@ -4,5 +4,6 @@ export * from './rpc.js';
4
4
  export * from './proving_broker_database.js';
5
5
  export * from './proving_broker_database/memory.js';
6
6
  export * from './proving_broker_database/persisted.js';
7
- export * from './proof_store.js';
7
+ export * from './proof_store/index.js';
8
8
  export * from './factory.js';
9
+ export * from './config.js';
@@ -0,0 +1,42 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+
3
+ import { GoogleCloudStorageProofStore } from './gcs_proof_store.js';
4
+ import { InlineProofStore } from './inline_proof_store.js';
5
+ import { type ProofStore } from './proof_store.js';
6
+
7
+ export function createProofStore(config: string | undefined, logger = createLogger('prover-client:proof-store')) {
8
+ if (config === undefined) {
9
+ logger.info('Creating inline proof store');
10
+ return new InlineProofStore();
11
+ } else if (config.startsWith('gs://')) {
12
+ try {
13
+ const url = new URL(config);
14
+ const bucket = url.host;
15
+ const path = url.pathname.replace(/^\/+/, '');
16
+ logger.info(`Creating google cloud proof store at ${bucket}`, { bucket, path });
17
+ return new GoogleCloudStorageProofStore(bucket, path);
18
+ } catch (err) {
19
+ throw new Error(
20
+ `Invalid google cloud proof store definition: '${config}'. Supported values are 'gs://bucket-name/path/to/store'.`,
21
+ );
22
+ }
23
+ } else {
24
+ throw new Error(`Unknown proof store config: '${config}'. Supported values are 'gs://bucket-name/path/to/store'.`);
25
+ }
26
+ }
27
+
28
+ export function createProofStoreForUri(
29
+ uri: string,
30
+ logger = createLogger('prover-client:proof-store'),
31
+ ): Pick<ProofStore, 'getProofInput' | 'getProofOutput'> {
32
+ if (uri.startsWith('data://')) {
33
+ return createProofStore(undefined, logger);
34
+ } else if (uri.startsWith('gs://')) {
35
+ const url = new URL(uri);
36
+ const basePath = url.pathname.replace(/^\/+/, '').split('/').slice(0, -3);
37
+ url.pathname = basePath.join('/');
38
+ return createProofStore(uri, logger);
39
+ } else {
40
+ throw new Error(`Unknown proof store config: '${uri}'. Supported protocols are 'data://' and 'gs://'.`);
41
+ }
42
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ type ProofUri,
3
+ type ProvingJobId,
4
+ type ProvingJobInputs,
5
+ type ProvingJobInputsMap,
6
+ type ProvingJobResult,
7
+ type ProvingJobResultsMap,
8
+ ProvingRequestType,
9
+ getProvingJobInputClassFor,
10
+ } from '@aztec/circuit-types';
11
+
12
+ import { Storage } from '@google-cloud/storage';
13
+ import { join } from 'path';
14
+
15
+ import { type ProofStore } from './proof_store.js';
16
+
17
+ const INPUTS_PATH = 'inputs';
18
+
19
+ export class GoogleCloudStorageProofStore implements ProofStore {
20
+ private readonly storage: Storage;
21
+
22
+ constructor(private readonly bucketName: string, private readonly path: string) {
23
+ this.storage = new Storage();
24
+ }
25
+
26
+ public async saveProofInput<T extends ProvingRequestType>(
27
+ id: ProvingJobId,
28
+ type: T,
29
+ inputs: ProvingJobInputsMap[T],
30
+ ): Promise<ProofUri> {
31
+ const path = join(this.path, INPUTS_PATH, ProvingRequestType[type], id);
32
+ const file = this.storage.bucket(this.bucketName).file(path);
33
+ await file.save(inputs.toBuffer());
34
+ return file.cloudStorageURI.toString() as ProofUri;
35
+ }
36
+
37
+ saveProofOutput<T extends ProvingRequestType>(
38
+ _id: ProvingJobId,
39
+ _type: T,
40
+ _result: ProvingJobResultsMap[T],
41
+ ): Promise<ProofUri> {
42
+ throw new Error('Not implemented');
43
+ }
44
+
45
+ public async getProofInput(uri: ProofUri): Promise<ProvingJobInputs> {
46
+ try {
47
+ const url = new URL(uri);
48
+ const bucket = this.storage.bucket(url.host);
49
+ const path = url.pathname.replace(/^\/+/, '');
50
+ const file = bucket.file(path);
51
+ if (!(await file.exists())) {
52
+ throw new Error(`File at ${uri} does not exist`);
53
+ }
54
+
55
+ const typeString = path.split('/').at(-2);
56
+ const type = typeString ? ProvingRequestType[typeString as keyof typeof ProvingRequestType] : undefined;
57
+ if (type === undefined) {
58
+ throw new Error(`Unrecognized proof type ${type} in path ${path}`);
59
+ }
60
+
61
+ const contents = await file.download();
62
+ const inputs = getProvingJobInputClassFor(type).fromBuffer(contents[0]);
63
+ return { inputs, type } as ProvingJobInputs;
64
+ } catch (err) {
65
+ throw new Error(`Error getting proof input at ${uri}: ${err}`);
66
+ }
67
+ }
68
+
69
+ getProofOutput(_uri: ProofUri): Promise<ProvingJobResult> {
70
+ throw new Error('Not implemented');
71
+ }
72
+ }
@@ -0,0 +1,3 @@
1
+ export * from './proof_store.js';
2
+ export * from './inline_proof_store.js';
3
+ export * from './factory.js';
@@ -10,50 +10,7 @@ import {
10
10
  import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
11
11
  import { type ZodFor } from '@aztec/foundation/schemas';
12
12
 
13
- /**
14
- * A database for storing proof inputs and outputs.
15
- */
16
- export interface ProofStore {
17
- /**
18
- * Save a proof input to the database.
19
- * @param jobId - The ID of the job the proof input is associated with.
20
- * @param type - The type of the proving request.
21
- * @param inputs - The proof input to save.
22
- * @returns The URI of the saved proof input.
23
- */
24
- saveProofInput<T extends ProvingRequestType>(
25
- jobId: ProvingJobId,
26
- type: T,
27
- inputs: ProvingJobInputsMap[T],
28
- ): Promise<ProofUri>;
29
-
30
- /**
31
- * Save a proof output to the database.
32
- * @param jobId - The ID of the job the proof input is associated with.
33
- * @param type - The type of the proving request.
34
- * @param result - The proof output to save.
35
- * @returns The URI of the saved proof output.
36
- */
37
- saveProofOutput<T extends ProvingRequestType>(
38
- id: ProvingJobId,
39
- type: T,
40
- result: ProvingJobResultsMap[T],
41
- ): Promise<ProofUri>;
42
-
43
- /**
44
- * Retrieve a proof input from the database.
45
- * @param uri - The URI of the proof input to retrieve.
46
- * @returns The proof input.
47
- */
48
- getProofInput(uri: ProofUri): Promise<ProvingJobInputs>;
49
-
50
- /**
51
- * Retrieve a proof output from the database.
52
- * @param uri - The URI of the proof output to retrieve.
53
- * @returns The proof output.
54
- */
55
- getProofOutput(uri: ProofUri): Promise<ProvingJobResult>;
56
- }
13
+ import { type ProofStore } from './proof_store.js';
57
14
 
58
15
  // use an ASCII encoded data uri https://datatracker.ietf.org/doc/html/rfc2397#section-2
59
16
  // we do this to avoid double encoding to base64 (since the inputs already serialize to a base64 string)
@@ -0,0 +1,54 @@
1
+ import {
2
+ type ProofUri,
3
+ type ProvingJobId,
4
+ type ProvingJobInputs,
5
+ type ProvingJobInputsMap,
6
+ type ProvingJobResult,
7
+ type ProvingJobResultsMap,
8
+ type ProvingRequestType,
9
+ } from '@aztec/circuit-types';
10
+
11
+ /**
12
+ * A database for storing proof inputs and outputs.
13
+ */
14
+ export interface ProofStore {
15
+ /**
16
+ * Save a proof input to the database.
17
+ * @param jobId - The ID of the job the proof input is associated with.
18
+ * @param type - The type of the proving request.
19
+ * @param inputs - The proof input to save.
20
+ * @returns The URI of the saved proof input.
21
+ */
22
+ saveProofInput<T extends ProvingRequestType>(
23
+ jobId: ProvingJobId,
24
+ type: T,
25
+ inputs: ProvingJobInputsMap[T],
26
+ ): Promise<ProofUri>;
27
+
28
+ /**
29
+ * Save a proof output to the database.
30
+ * @param jobId - The ID of the job the proof input is associated with.
31
+ * @param type - The type of the proving request.
32
+ * @param result - The proof output to save.
33
+ * @returns The URI of the saved proof output.
34
+ */
35
+ saveProofOutput<T extends ProvingRequestType>(
36
+ id: ProvingJobId,
37
+ type: T,
38
+ result: ProvingJobResultsMap[T],
39
+ ): Promise<ProofUri>;
40
+
41
+ /**
42
+ * Retrieve a proof input from the database.
43
+ * @param uri - The URI of the proof input to retrieve.
44
+ * @returns The proof input.
45
+ */
46
+ getProofInput(uri: ProofUri): Promise<ProvingJobInputs>;
47
+
48
+ /**
49
+ * Retrieve a proof output from the database.
50
+ * @param uri - The URI of the proof output to retrieve.
51
+ * @returns The proof output.
52
+ */
53
+ getProofOutput(uri: ProofUri): Promise<ProvingJobResult>;
54
+ }
@@ -12,9 +12,15 @@ import { createLogger } from '@aztec/foundation/log';
12
12
  import { RunningPromise } from '@aztec/foundation/running-promise';
13
13
  import { truncate } from '@aztec/foundation/string';
14
14
  import { Timer } from '@aztec/foundation/timer';
15
- import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
16
-
17
- import { type ProofStore } from './proof_store.js';
15
+ import {
16
+ type TelemetryClient,
17
+ type Traceable,
18
+ type Tracer,
19
+ getTelemetryClient,
20
+ trackSpan,
21
+ } from '@aztec/telemetry-client';
22
+
23
+ import { type ProofStore } from './proof_store/index.js';
18
24
  import { ProvingAgentInstrumentation } from './proving_agent_instrumentation.js';
19
25
  import { ProvingJobController, ProvingJobControllerStatus } from './proving_job_controller.js';
20
26
 
@@ -36,12 +42,12 @@ export class ProvingAgent implements Traceable {
36
42
  private proofStore: ProofStore,
37
43
  /** The prover implementation to defer jobs to */
38
44
  private circuitProver: ServerCircuitProver,
39
- /** A telemetry client through which to emit metrics */
40
- client: TelemetryClient,
41
45
  /** Optional list of allowed proof types to build */
42
46
  private proofAllowList: Array<ProvingRequestType> = [],
43
47
  /** How long to wait between jobs */
44
48
  private pollIntervalMs = 1000,
49
+ /** A telemetry client through which to emit metrics */
50
+ client: TelemetryClient = getTelemetryClient(),
45
51
  private log = createLogger('prover-client:proving-agent'),
46
52
  ) {
47
53
  this.tracer = client.getTracer('ProvingAgent');