Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new proving agent #9999

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions yarn-project/bb-prover/src/bb/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type BBSuccess = {
export type BBFailure = {
status: BB_RESULT.FAILURE;
reason: string;
retry?: boolean;
};

export type BBResult = BBSuccess | BBFailure;
Expand Down Expand Up @@ -175,6 +176,7 @@ export async function generateKeyForNoirCircuit(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to generate key. Exit code: ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -245,6 +247,7 @@ export async function executeBbClientIvcProof(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -324,6 +327,7 @@ export async function computeVerificationKey(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to write VK. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -396,6 +400,7 @@ export async function generateProof(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -470,6 +475,7 @@ export async function generateTubeProof(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -573,6 +579,7 @@ export async function generateAvmProof(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -648,6 +655,7 @@ export async function verifyClientIvcProof(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -690,6 +698,7 @@ async function verifyProofInternal(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -730,6 +739,7 @@ export async function writeVkAsFields(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to create vk as fields. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -772,6 +782,7 @@ export async function writeProofAsFields(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to create proof as fields. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down Expand Up @@ -813,6 +824,7 @@ export async function generateContractForVerificationKey(
return {
status: BB_RESULT.FAILURE,
reason: `Failed to write verifier contract. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
Expand Down
17 changes: 11 additions & 6 deletions yarn-project/bb-prover/src/prover/bb_prover.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable require-await */
import {
type ProofAndVerificationKey,
ProvingError,
type PublicInputsAndRecursiveProof,
type ServerCircuitProver,
makeProofAndVerificationKey,
Expand Down Expand Up @@ -477,7 +478,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {

if (provingResult.status === BB_RESULT.FAILURE) {
logger.error(`Failed to generate proof for ${circuitType}: ${provingResult.reason}`);
throw new Error(provingResult.reason);
throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
}

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

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

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

if (provingResult.status === BB_RESULT.FAILURE) {
logger.error(`Failed to generate proof for tube proof: ${provingResult.reason}`);
throw new Error(provingResult.reason);
throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
}
return provingResult;
}
Expand Down Expand Up @@ -724,7 +725,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {

if (result.status === BB_RESULT.FAILURE) {
const errorMessage = `Failed to verify proof from key!`;
throw new Error(errorMessage);
throw new ProvingError(errorMessage, result, result.retry);
}

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

if (result.status === BB_RESULT.FAILURE) {
const errorMessage = `Failed to convert ${circuit} proof to fields, ${result.reason}`;
throw new Error(errorMessage);
throw new ProvingError(errorMessage, result, result.retry);
}

const proofString = await fs.readFile(path.join(bbWorkingDirectory, PROOF_FIELDS_FILENAME), {
Expand Down Expand Up @@ -825,7 +826,11 @@ export class BBNativeRollupProver implements ServerCircuitProver {
logger.debug,
).then(result => {
if (result.status === BB_RESULT.FAILURE) {
throw new Error(`Failed to generate verification key for ${circuitType}, ${result.reason}`);
throw new ProvingError(
`Failed to generate verification key for ${circuitType}, ${result.reason}`,
result,
result.retry,
);
}
return extractVkData(result.vkPath!);
});
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './simulation_error.js';
export * from './tx/index.js';
export * from './tx_effect.js';
export * from './tx_execution_request.js';
export * from './proving_error.js';
18 changes: 18 additions & 0 deletions yarn-project/circuit-types/src/proving_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* An error thrown when generating a proof fails.
*/
export class ProvingError extends Error {
public static readonly NAME = 'ProvingError';

/**
* Creates a new instance
* @param message - The error message.
* @param cause - The cause of the error.
* @param retry - Whether the proof should be retried.
*/
constructor(message: string, cause?: unknown, public readonly retry: boolean = false) {
super(message);
this.name = ProvingError.NAME;
this.cause = cause;
}
}
Loading