Skip to content

Commit

Permalink
chore: Sanity checking of proving job IDs (#11134)
Browse files Browse the repository at this point in the history
This PR ensures we use a consistent method for generating proving jobs
Ids and then validates those ids.
  • Loading branch information
PhilWindle authored Jan 9, 2025
1 parent de99603 commit 61c3e95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion yarn-project/circuit-types/src/interfaces/proving-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ export const makeProvingJobId = (epochNumber: number, type: ProvingRequestType,

export const getEpochFromProvingJobId = (id: ProvingJobId) => {
const components = id.split(':');
return +components[0];
const epochNumber = components.length < 1 ? Number.NaN : parseInt(components[0], 10);
if (!Number.isSafeInteger(epochNumber) || epochNumber < 0) {
throw new Error(`Proving Job ID ${id} does not contain valid epoch`);
}
return epochNumber;
};

export type ProvingJob = z.infer<typeof ProvingJob>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ProvingRequestType,
type PublicInputsAndRecursiveProof,
type ServerCircuitProver,
makeProvingJobId,
} from '@aztec/circuit-types';
import {
type AVM_PROOF_LENGTH_IN_FIELDS,
Expand Down Expand Up @@ -560,6 +561,6 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {

private generateId(type: ProvingRequestType, inputs: { toBuffer(): Buffer }, epochNumber = 0) {
const inputsHash = sha256(inputs.toBuffer());
return `${epochNumber}:${ProvingRequestType[type]}:${inputsHash.toString('hex')}`;
return makeProvingJobId(epochNumber, type, inputsHash.toString('hex'));
}
}

0 comments on commit 61c3e95

Please sign in to comment.