Skip to content

Commit 9ad24dd

Browse files
authored
feat: new proving agent (#9999)
New proving agent for proving broker. Fix #9533 LE: PR 9999!!
1 parent 823c8e6 commit 9ad24dd

File tree

9 files changed

+647
-17
lines changed

9 files changed

+647
-17
lines changed

yarn-project/bb-prover/src/bb/execute.ts

+12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type BBSuccess = {
4343
export type BBFailure = {
4444
status: BB_RESULT.FAILURE;
4545
reason: string;
46+
retry?: boolean;
4647
};
4748

4849
export type BBResult = BBSuccess | BBFailure;
@@ -175,6 +176,7 @@ export async function generateKeyForNoirCircuit(
175176
return {
176177
status: BB_RESULT.FAILURE,
177178
reason: `Failed to generate key. Exit code: ${result.exitCode}. Signal ${result.signal}.`,
179+
retry: !!result.signal,
178180
};
179181
} catch (error) {
180182
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -245,6 +247,7 @@ export async function executeBbClientIvcProof(
245247
return {
246248
status: BB_RESULT.FAILURE,
247249
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
250+
retry: !!result.signal,
248251
};
249252
} catch (error) {
250253
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -324,6 +327,7 @@ export async function computeVerificationKey(
324327
return {
325328
status: BB_RESULT.FAILURE,
326329
reason: `Failed to write VK. Exit code ${result.exitCode}. Signal ${result.signal}.`,
330+
retry: !!result.signal,
327331
};
328332
} catch (error) {
329333
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -396,6 +400,7 @@ export async function generateProof(
396400
return {
397401
status: BB_RESULT.FAILURE,
398402
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
403+
retry: !!result.signal,
399404
};
400405
} catch (error) {
401406
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -470,6 +475,7 @@ export async function generateTubeProof(
470475
return {
471476
status: BB_RESULT.FAILURE,
472477
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
478+
retry: !!result.signal,
473479
};
474480
} catch (error) {
475481
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -573,6 +579,7 @@ export async function generateAvmProof(
573579
return {
574580
status: BB_RESULT.FAILURE,
575581
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
582+
retry: !!result.signal,
576583
};
577584
} catch (error) {
578585
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -648,6 +655,7 @@ export async function verifyClientIvcProof(
648655
return {
649656
status: BB_RESULT.FAILURE,
650657
reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
658+
retry: !!result.signal,
651659
};
652660
} catch (error) {
653661
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -690,6 +698,7 @@ async function verifyProofInternal(
690698
return {
691699
status: BB_RESULT.FAILURE,
692700
reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
701+
retry: !!result.signal,
693702
};
694703
} catch (error) {
695704
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -730,6 +739,7 @@ export async function writeVkAsFields(
730739
return {
731740
status: BB_RESULT.FAILURE,
732741
reason: `Failed to create vk as fields. Exit code ${result.exitCode}. Signal ${result.signal}.`,
742+
retry: !!result.signal,
733743
};
734744
} catch (error) {
735745
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -772,6 +782,7 @@ export async function writeProofAsFields(
772782
return {
773783
status: BB_RESULT.FAILURE,
774784
reason: `Failed to create proof as fields. Exit code ${result.exitCode}. Signal ${result.signal}.`,
785+
retry: !!result.signal,
775786
};
776787
} catch (error) {
777788
return { status: BB_RESULT.FAILURE, reason: `${error}` };
@@ -813,6 +824,7 @@ export async function generateContractForVerificationKey(
813824
return {
814825
status: BB_RESULT.FAILURE,
815826
reason: `Failed to write verifier contract. Exit code ${result.exitCode}. Signal ${result.signal}.`,
827+
retry: !!result.signal,
816828
};
817829
} catch (error) {
818830
return { status: BB_RESULT.FAILURE, reason: `${error}` };

yarn-project/bb-prover/src/prover/bb_prover.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable require-await */
22
import {
33
type ProofAndVerificationKey,
4+
ProvingError,
45
type PublicInputsAndRecursiveProof,
56
type ServerCircuitProver,
67
makeProofAndVerificationKey,
@@ -477,7 +478,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
477478

478479
if (provingResult.status === BB_RESULT.FAILURE) {
479480
logger.error(`Failed to generate proof for ${circuitType}: ${provingResult.reason}`);
480-
throw new Error(provingResult.reason);
481+
throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
481482
}
482483

483484
// Ensure our vk cache is up to date
@@ -538,7 +539,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
538539

539540
if (provingResult.status === BB_RESULT.FAILURE) {
540541
logger.error(`Failed to generate AVM proof for ${input.functionName}: ${provingResult.reason}`);
541-
throw new Error(provingResult.reason);
542+
throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
542543
}
543544

544545
return provingResult;
@@ -555,7 +556,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
555556

556557
if (provingResult.status === BB_RESULT.FAILURE) {
557558
logger.error(`Failed to generate proof for tube proof: ${provingResult.reason}`);
558-
throw new Error(provingResult.reason);
559+
throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
559560
}
560561
return provingResult;
561562
}
@@ -724,7 +725,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
724725

725726
if (result.status === BB_RESULT.FAILURE) {
726727
const errorMessage = `Failed to verify proof from key!`;
727-
throw new Error(errorMessage);
728+
throw new ProvingError(errorMessage, result, result.retry);
728729
}
729730

730731
logger.info(`Successfully verified proof from key in ${result.durationMs} ms`);
@@ -785,7 +786,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
785786

786787
if (result.status === BB_RESULT.FAILURE) {
787788
const errorMessage = `Failed to convert ${circuit} proof to fields, ${result.reason}`;
788-
throw new Error(errorMessage);
789+
throw new ProvingError(errorMessage, result, result.retry);
789790
}
790791

791792
const proofString = await fs.readFile(path.join(bbWorkingDirectory, PROOF_FIELDS_FILENAME), {
@@ -825,7 +826,11 @@ export class BBNativeRollupProver implements ServerCircuitProver {
825826
logger.debug,
826827
).then(result => {
827828
if (result.status === BB_RESULT.FAILURE) {
828-
throw new Error(`Failed to generate verification key for ${circuitType}, ${result.reason}`);
829+
throw new ProvingError(
830+
`Failed to generate verification key for ${circuitType}, ${result.reason}`,
831+
result,
832+
result.retry,
833+
);
829834
}
830835
return extractVkData(result.vkPath!);
831836
});

yarn-project/circuit-types/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export * from './simulation_error.js';
2222
export * from './tx/index.js';
2323
export * from './tx_effect.js';
2424
export * from './tx_execution_request.js';
25+
export * from './proving_error.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* An error thrown when generating a proof fails.
3+
*/
4+
export class ProvingError extends Error {
5+
public static readonly NAME = 'ProvingError';
6+
7+
/**
8+
* Creates a new instance
9+
* @param message - The error message.
10+
* @param cause - The cause of the error.
11+
* @param retry - Whether the proof should be retried.
12+
*/
13+
constructor(message: string, cause?: unknown, public readonly retry: boolean = false) {
14+
super(message);
15+
this.name = ProvingError.NAME;
16+
this.cause = cause;
17+
}
18+
}

0 commit comments

Comments
 (0)