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

chore: merge BarretenbergVerifierBackend and BarretenbergBackend #5399

Merged
merged 2 commits into from
Jul 8, 2024
Merged
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
46 changes: 22 additions & 24 deletions tooling/noir_js_backend_barretenberg/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { type Barretenberg } from '@aztec/bb.js';
// minus the public inputs.
const numBytesInProofWithoutPublicInputs: number = 2144;

export class BarretenbergVerifierBackend implements VerifierBackend {
export class BarretenbergBackend implements Backend, VerifierBackend {
// These type assertions are used so that we don't
// have to initialize `api` and `acirComposer` in the constructor.
// These are initialized asynchronously in the `init` function,
Expand Down Expand Up @@ -60,29 +60,6 @@ export class BarretenbergVerifierBackend implements VerifierBackend {
}
}

/** @description Verifies a proof */
async verifyProof(proofData: ProofData): Promise<boolean> {
const proof = reconstructProofWithPublicInputs(proofData);
await this.instantiate();
await this.api.acirInitVerificationKey(this.acirComposer);
return await this.api.acirVerifyProof(this.acirComposer, proof);
}

async getVerificationKey(): Promise<Uint8Array> {
await this.instantiate();
await this.api.acirInitVerificationKey(this.acirComposer);
return await this.api.acirGetVerificationKey(this.acirComposer);
}

async destroy(): Promise<void> {
if (!this.api) {
return;
}
await this.api.destroy();
}
}

export class BarretenbergBackend extends BarretenbergVerifierBackend implements Backend {
/** @description Generates a proof */
async generateProof(compressedWitness: Uint8Array): Promise<ProofData> {
await this.instantiate();
Expand Down Expand Up @@ -144,4 +121,25 @@ export class BarretenbergBackend extends BarretenbergVerifierBackend implements
vkHash: vk[1].toString(),
};
}

/** @description Verifies a proof */
async verifyProof(proofData: ProofData): Promise<boolean> {
const proof = reconstructProofWithPublicInputs(proofData);
await this.instantiate();
await this.api.acirInitVerificationKey(this.acirComposer);
return await this.api.acirVerifyProof(this.acirComposer, proof);
}

async getVerificationKey(): Promise<Uint8Array> {
await this.instantiate();
await this.api.acirInitVerificationKey(this.acirComposer);
return await this.api.acirGetVerificationKey(this.acirComposer);
}

async destroy(): Promise<void> {
if (!this.api) {
return;
}
await this.api.destroy();
}
}
Loading