Skip to main content
Version: v0.17.0

BarretenbergBackend

Table of Contents

constructor

The constructor is a method used to create and initialize objects created within the BarretenbergBackend class. In this class, you should pass at least one argument for the circuit.

Syntax

constructor(acirCircuit, (numberOfThreads = 1));

Parameters

ParameterTypeDescription
acirCircuitObjectA circuit represented in a json format, containing the ABI and bytecode typically obtained by running nargo compile. This is the same circuit expected to be passed to the Noir class
numberOfThreadsNumber (optional)The number of threads to be used by the backend. Defaults to 1.

Usage

const backend = new BarretenbergBackend(acirCircuit);

generateFinalProof

An async wrapper around the generateProof method that passes a false flag. Usually called by the Noir class.

Syntax

async generateFinalProof(decompressedWitness)

Parameters

ParameterTypeDescription
decompressedWitnessObjectThe decompressed witness for generating the final proof.

Returns

Return valueTypeDescription
proofPromise<Uint8Array>An array with the byte representation of the final proof.

Usage

const finalProof = await backend.generateFinalProof(decompressedWitness);

generateIntermediateProof

An async wrapper around the generateProof method that passes a true flag. It's not currently being used by the Noir class, but developers can call this method directly to use Noir's recursive features.

Syntax

async generateIntermediateProof(witness)

Parameters

ParameterTypeDescription
witnessObjectThe witness for generating the intermediate proof.

Returns

Return valueTypeDescription
proofPromise<Uint8Array>An array with the byte representation of the intermediate proof

Usage

const intermediateProof = await backend.generateIntermediateProof(witness);

generateProof

This async method generates a proof. Takes the witness generated by ACVM, and a boolean that evaluates to true when the proof is meant to be verified in another circuit. Not currently used by the Noir class.

Syntax

async generateProof(decompressedWitness, makeEasyToVerifyInCircuit)

Parameters

ParameterTypeDescription
decompressedWitnessObjectThe decompressed witness for generating the proof.
makeEasyToVerifyInCircuitBooleanA flag indicating whether to generate proof components for easy verification within a circuit.

Returns

Return valueTypeDescription
proofPromise<Uint8Array>An array with the byte representation of the proof

Usage

const proof = await backend.generateProof(decompressedWitness, makeEasyToVerifyInCircuit);

generateIntermediateProofArtifacts

This async method returns the artifacts needed to verify the intermediate proof in another circuit. It's not currently being used by the Noir class, but developers can call this method directly to use Noir's recursive features.

Syntax

async generateIntermediateProofArtifacts(proof, numOfPublicInputs = 0)

Parameters

ParameterTypeDescription
proofObjectThe proof object.
numOfPublicInputsNumber (optional)The number of public inputs in the inner proof, defaulting to 0.

Returns

Return valueTypeDescription
proofAsFieldsstring[]An array of strings with the hexadecimal representation of the Fields that make up a proof
vkAsFieldsstring[]An array of strings with the hexadecimal representation of the Fields that make up the verification key
vkHashstringA pedersen hash of the verification key

Usage

const artifacts = await backend.generateIntermediateProofArtifacts(proof, numOfPublicInputs);

verifyFinalProof

An async wrapper around verifyProof that sets the false flag. Usually called by the Noir class.

Syntax

async verifyFinalProof(proof)

Parameters

ParameterTypeDescription
proofObjectThe proof object to verify.

Returns

Return valueTypeDescription
verifiedPromise <boolean>A boolean for whether the proof was verified

Usage

const isValidFinal = await backend.verifyFinalProof(proof);

verifyIntermediateProof

An async wrapper around verifyProof that sets the true flag. It's not currently being used by the Noir class, but developers can call this method directly to use Noir's recursive features.

Syntax

async verifyIntermediateProof(proof)

Parameters

ParameterTypeDescription
proofObjectThe intermediate proof object to verify.

Returns

Return valueTypeDescription
verifiedPromise <boolean>A boolean for whether the proof was verified

Usage

const isValidIntermediate = await backend.verifyIntermediateProof(proof);

verifyProof

This async method verifies a proof. Takes the proof, and a boolean that evaluates to true when the proof is intermediate.

Syntax

async verifyProof(proof, makeEasyToVerifyInCircuit)

Parameters

ParameterTypeDescription
proofObjectThe proof object to verify
makeEasyToVerifyInCircuitBooleanA flag indicating whether the proof is intermediate or final

Returns

ParameterTypeDescription
verifiedPromise<boolean>A boolean for whether the proof was verified

Usage

const isValid = await backend.verifyProof(proof, makeEasyToVerifyInCircuit);

destroy

This method destroys the resources allocated in the instantiate method. Noir doesn't currently call this method, but it's highly recommended that developers do so in order to save resources.

Syntax

async destroy()

Parameters

This method takes no parameters.

Usage

await backend.destroy();