From f0be91b52abcd17620cc48f994cd12c5e73cf14e Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Wed, 3 Jul 2024 15:50:05 +0000 Subject: [PATCH 1/2] chore: merge `BarretenbergVerifierBackend` and `BarretenbergBackend` --- .../src/backend.ts | 46 +++++++++---------- .../src/verifier.ts | 4 +- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/tooling/noir_js_backend_barretenberg/src/backend.ts b/tooling/noir_js_backend_barretenberg/src/backend.ts index 96c4d13aa61..8ede6a07b50 100644 --- a/tooling/noir_js_backend_barretenberg/src/backend.ts +++ b/tooling/noir_js_backend_barretenberg/src/backend.ts @@ -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, @@ -60,29 +60,6 @@ export class BarretenbergVerifierBackend implements VerifierBackend { } } - /** @description Verifies a proof */ - async verifyProof(proofData: ProofData): Promise { - const proof = reconstructProofWithPublicInputs(proofData); - await this.instantiate(); - await this.api.acirInitVerificationKey(this.acirComposer); - return await this.api.acirVerifyProof(this.acirComposer, proof); - } - - async getVerificationKey(): Promise { - await this.instantiate(); - await this.api.acirInitVerificationKey(this.acirComposer); - return await this.api.acirGetVerificationKey(this.acirComposer); - } - - async destroy(): Promise { - if (!this.api) { - return; - } - await this.api.destroy(); - } -} - -export class BarretenbergBackend extends BarretenbergVerifierBackend implements Backend { /** @description Generates a proof */ async generateProof(compressedWitness: Uint8Array): Promise { await this.instantiate(); @@ -144,4 +121,25 @@ export class BarretenbergBackend extends BarretenbergVerifierBackend implements vkHash: vk[1].toString(), }; } + + /** @description Verifies a proof */ + async verifyProof(proofData: ProofData): Promise { + const proof = reconstructProofWithPublicInputs(proofData); + await this.instantiate(); + await this.api.acirInitVerificationKey(this.acirComposer); + return await this.api.acirVerifyProof(this.acirComposer, proof); + } + + async getVerificationKey(): Promise { + await this.instantiate(); + await this.api.acirInitVerificationKey(this.acirComposer); + return await this.api.acirGetVerificationKey(this.acirComposer); + } + + async destroy(): Promise { + if (!this.api) { + return; + } + await this.api.destroy(); + } } diff --git a/tooling/noir_js_backend_barretenberg/src/verifier.ts b/tooling/noir_js_backend_barretenberg/src/verifier.ts index fe9fa9cfffd..5151ed87cd9 100644 --- a/tooling/noir_js_backend_barretenberg/src/verifier.ts +++ b/tooling/noir_js_backend_barretenberg/src/verifier.ts @@ -1,9 +1,9 @@ -import { ProofData } from '@noir-lang/types'; +import { ProofData, VerifierBackend } from '@noir-lang/types'; import { BackendOptions } from './types.js'; import { flattenPublicInputsAsArray } from './public_inputs.js'; import { type Barretenberg } from '@aztec/bb.js'; -export class BarretenbergVerifier { +export class BarretenbergVerifier implements 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, From f57b6c510313bacbb5ea59c4ce50113f92b94f5c Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Wed, 3 Jul 2024 16:13:52 +0000 Subject: [PATCH 2/2] . --- tooling/noir_js_backend_barretenberg/src/verifier.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tooling/noir_js_backend_barretenberg/src/verifier.ts b/tooling/noir_js_backend_barretenberg/src/verifier.ts index 5151ed87cd9..fe9fa9cfffd 100644 --- a/tooling/noir_js_backend_barretenberg/src/verifier.ts +++ b/tooling/noir_js_backend_barretenberg/src/verifier.ts @@ -1,9 +1,9 @@ -import { ProofData, VerifierBackend } from '@noir-lang/types'; +import { ProofData } from '@noir-lang/types'; import { BackendOptions } from './types.js'; import { flattenPublicInputsAsArray } from './public_inputs.js'; import { type Barretenberg } from '@aztec/bb.js'; -export class BarretenbergVerifier implements VerifierBackend { +export class BarretenbergVerifier { // 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,