Skip to content
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
144 changes: 144 additions & 0 deletions yarn-project/circuit-types/src/interfaces/proving-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,147 @@ export const ProvingRequestResultSchema = z.discriminatedUnion('type', [
result: schemaForRecursiveProofAndVerificationKey(TUBE_PROOF_LENGTH),
}),
]) satisfies ZodFor<ProvingRequestResult>;

export const V2ProvingJobId = z.string().brand('ProvingJobId');
export type V2ProvingJobId = z.infer<typeof V2ProvingJobId>;

export const V2ProvingJob = z.discriminatedUnion('type', [
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.PUBLIC_VM),
inputs: AvmCircuitInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.BASE_PARITY),
inputs: BaseParityInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.ROOT_PARITY),
inputs: RootParityInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.PRIVATE_BASE_ROLLUP),
inputs: PrivateBaseRollupInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.PUBLIC_BASE_ROLLUP),
inputs: PublicBaseRollupInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.MERGE_ROLLUP),
inputs: MergeRollupInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.BLOCK_ROOT_ROLLUP),
inputs: BlockRootRollupInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.EMPTY_BLOCK_ROOT_ROLLUP),
inputs: EmptyBlockRootRollupInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.BLOCK_MERGE_ROLLUP),
inputs: BlockMergeRollupInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.ROOT_ROLLUP),
inputs: RootRollupInputs.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.PRIVATE_KERNEL_EMPTY),
inputs: PrivateKernelEmptyInputData.schema,
}),
z.object({
id: V2ProvingJobId,
blockNumber: z.number(),
type: z.literal(ProvingRequestType.TUBE_PROOF),
inputs: TubeInputs.schema,
}),
]);
export type V2ProvingJob = z.infer<typeof V2ProvingJob>;

export const V2ProofOutput = z.discriminatedUnion('type', [
z.object({
type: z.literal(ProvingRequestType.PRIVATE_KERNEL_EMPTY),
value: schemaForPublicInputsAndRecursiveProof(KernelCircuitPublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.PUBLIC_VM),
value: schemaForRecursiveProofAndVerificationKey(AVM_PROOF_LENGTH_IN_FIELDS),
}),
z.object({
type: z.literal(ProvingRequestType.PRIVATE_BASE_ROLLUP),
value: schemaForPublicInputsAndRecursiveProof(BaseOrMergeRollupPublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.PUBLIC_BASE_ROLLUP),
value: schemaForPublicInputsAndRecursiveProof(BaseOrMergeRollupPublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.MERGE_ROLLUP),
value: schemaForPublicInputsAndRecursiveProof(BaseOrMergeRollupPublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.EMPTY_BLOCK_ROOT_ROLLUP),
value: schemaForPublicInputsAndRecursiveProof(BlockRootOrBlockMergePublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.BLOCK_ROOT_ROLLUP),
value: schemaForPublicInputsAndRecursiveProof(BlockRootOrBlockMergePublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.BLOCK_MERGE_ROLLUP),
value: schemaForPublicInputsAndRecursiveProof(BlockRootOrBlockMergePublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.ROOT_ROLLUP),
value: schemaForPublicInputsAndRecursiveProof(RootRollupPublicInputs.schema),
}),
z.object({
type: z.literal(ProvingRequestType.BASE_PARITY),
value: schemaForPublicInputsAndRecursiveProof(ParityPublicInputs.schema, RECURSIVE_PROOF_LENGTH),
}),
z.object({
type: z.literal(ProvingRequestType.ROOT_PARITY),
value: schemaForPublicInputsAndRecursiveProof(ParityPublicInputs.schema, NESTED_RECURSIVE_PROOF_LENGTH),
}),
z.object({
type: z.literal(ProvingRequestType.TUBE_PROOF),
value: schemaForRecursiveProofAndVerificationKey(TUBE_PROOF_LENGTH),
}),
]);

export type V2ProofOutput = z.infer<typeof V2ProofOutput>;

export const V2ProvingJobStatus = z.discriminatedUnion('status', [
z.object({ status: z.literal('in-queue') }),
z.object({ status: z.literal('in-progress') }),
z.object({ status: z.literal('not-found') }),
z.object({ status: z.literal('resolved'), value: V2ProofOutput }),
z.object({ status: z.literal('rejected'), error: z.string() }),
]);
export type V2ProvingJobStatus = z.infer<typeof V2ProvingJobStatus>;

export const V2ProvingJobResult = z.union([z.object({ value: V2ProofOutput }), z.object({ error: z.string() })]);
export type V2ProvingJobResult = z.infer<typeof V2ProvingJobResult>;
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
import { Fr } from '@aztec/foundation/fields';

import { NESTED_RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js';
import { makeHeader } from '../../tests/factories.js';
import { PrivateKernelEmptyInputData } from './private_kernel_empty_inputs.js';
import { makeRecursiveProof } from '../recursive_proof.js';
import { VerificationKeyAsFields } from '../verification_key.js';
import {
EmptyNestedData,
PrivateKernelEmptyInputData,
PrivateKernelEmptyInputs,
} from './private_kernel_empty_inputs.js';

describe('PrivateKernelEmptyInputData', () => {
it('serializes and deserializes', () => {
const obj = new PrivateKernelEmptyInputData(makeHeader(), Fr.random(), Fr.random(), Fr.random(), Fr.random());
expect(PrivateKernelEmptyInputData.fromString(obj.toString())).toEqual(obj);
});
});

describe('PrivateKernelEmptyInputs', () => {
it('serializes and deserializes', () => {
const obj = new PrivateKernelEmptyInputs(
new EmptyNestedData(makeRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH), VerificationKeyAsFields.makeFakeHonk()),
makeHeader(),
Fr.random(),
Fr.random(),
Fr.random(),
Fr.random(),
);

expect(PrivateKernelEmptyInputs.fromBuffer(obj.toBuffer())).toEqual(obj);
});
});

describe('EmptyNestedData', () => {
it('serializes and deserializes', () => {
const obj = new EmptyNestedData(
makeRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
VerificationKeyAsFields.makeFakeHonk(),
);
expect(EmptyNestedData.fromBuffer(obj.toBuffer())).toEqual(obj);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { hexSchemaFor } from '@aztec/foundation/schemas';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { type FieldsOf } from '@aztec/foundation/types';

import { type RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js';
import { RECURSIVE_PROOF_LENGTH } from '../../constants.gen.js';
import { Header } from '../header.js';
import { type RecursiveProof } from '../recursive_proof.js';
import { type VerificationKeyAsFields } from '../verification_key.js';
import { RecursiveProof } from '../recursive_proof.js';
import { VerificationKeyAsFields } from '../verification_key.js';

export class PrivateKernelEmptyInputData {
constructor(
Expand Down Expand Up @@ -92,6 +92,18 @@ export class PrivateKernelEmptyInputs {
fields.protocolContractTreeRoot,
);
}

static fromBuffer(buf: Buffer | BufferReader): PrivateKernelEmptyInputs {
const reader = BufferReader.asReader(buf);
return new PrivateKernelEmptyInputs(
reader.readObject(EmptyNestedData),
reader.readObject(Header),
reader.readObject(Fr),
reader.readObject(Fr),
reader.readObject(Fr),
reader.readObject(Fr),
);
}
}

export class EmptyNestedCircuitInputs {
Expand All @@ -109,4 +121,20 @@ export class EmptyNestedData {
toBuffer(): Buffer {
return serializeToBuffer(this.proof, this.vk);
}

static fromBuffer(buf: Buffer | BufferReader): EmptyNestedData {
const reader = BufferReader.asReader(buf);
const recursiveProof = reader.readObject(RecursiveProof);

if (recursiveProof.proof.length !== RECURSIVE_PROOF_LENGTH) {
throw new TypeError(
`Invalid proof length. Expected: ${RECURSIVE_PROOF_LENGTH} got: ${recursiveProof.proof.length}`,
);
}

return new EmptyNestedData(
recursiveProof as RecursiveProof<typeof RECURSIVE_PROOF_LENGTH>,
reader.readObject(VerificationKeyAsFields),
);
}
}
Loading