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: adding autogenerated docs for noirjs #3035

Closed
wants to merge 4 commits into from
Closed
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
9 changes: 7 additions & 2 deletions tooling/noir_js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
"noImplicitAny": false,
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
"exclude": ["node_modules"],
"references": [
{
"path": "../noir_js_types"
}
]
}
5 changes: 5 additions & 0 deletions tooling/noir_js/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"entryPoints": ["src/index.ts"],
"excludeInternal": true,
"disableSources": true,
}
30 changes: 21 additions & 9 deletions tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
const numBytesInProofWithoutPublicInputs: number = 2144;

export class BarretenbergBackend implements Backend {
// 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,
// constructors cannot be asynchronous which is why we do this.
/** @internal */
private api: any;
/** @internal */
private acirComposer: any;
/** @internal */
private acirUncompressedBytecode: Uint8Array;
/** @internal */
private numberOfThreads = 1;

constructor(acirCircuit: CompiledCircuit, numberOfThreads = 1) {
Expand All @@ -22,7 +22,15 @@ export class BarretenbergBackend implements Backend {
this.acirUncompressedBytecode = acirToUint8Array(acirBytecodeBase64);
}

private async instantiate(): Promise<void> {
/**
*
* This async method is called by the Noir class.
* It allocates resources, decompresses the bytecode, and inits the SRS.
*
* @param numberOfThreads - The number of threads to be used by the backend. Defaults to 1.
*
*/
async instantiate(): Promise<void> {
if (!this.api) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
Expand All @@ -44,6 +52,7 @@ export class BarretenbergBackend implements Backend {
//
// The settings for this proof are the same as the settings for a "normal" proof
// ie one that is not in the recursive setting.
/** @internal */
async generateFinalProof(decompressedWitness: Uint8Array): Promise<ProofData> {
const makeEasyToVerifyInCircuit = false;
return this.generateProof(decompressedWitness, makeEasyToVerifyInCircuit);
Expand All @@ -60,13 +69,13 @@ export class BarretenbergBackend implements Backend {
// We set `makeEasyToVerifyInCircuit` to true, which will tell the backend to
// generate the proof using components that will make the proof
// easier to verify in a circuit.
/** @internal */
async generateIntermediateProof(witness: Uint8Array): Promise<ProofData> {
const makeEasyToVerifyInCircuit = true;
return this.generateProof(witness, makeEasyToVerifyInCircuit);
}

/** @internal */
async generateProof(decompressedWitness: Uint8Array, makeEasyToVerifyInCircuit: boolean): Promise<ProofData> {
await this.instantiate();
const proofWithPublicInputs = await this.api.acirCreateProof(
this.acirComposer,
this.acirUncompressedBytecode,
Expand Down Expand Up @@ -100,6 +109,7 @@ export class BarretenbergBackend implements Backend {
// method.
//
// The number of public inputs denotes how many public inputs are in the inner proof.
/** @internal */
async generateIntermediateProofArtifacts(
proofData: ProofData,
numOfPublicInputs = 0,
Expand All @@ -108,7 +118,6 @@ export class BarretenbergBackend implements Backend {
vkAsFields: string[];
vkHash: string;
}> {
await this.instantiate();
const proof = reconstructProofWithPublicInputs(proofData);
const proofAsFields = await this.api.acirSerializeProofIntoFields(this.acirComposer, proof, numOfPublicInputs);

Expand All @@ -126,25 +135,28 @@ export class BarretenbergBackend implements Backend {
};
}

/** @internal */
async verifyFinalProof(proofData: ProofData): Promise<boolean> {
const proof = reconstructProofWithPublicInputs(proofData);
const makeEasyToVerifyInCircuit = false;
const verified = await this.verifyProof(proof, makeEasyToVerifyInCircuit);
return verified;
}

/** @internal */
async verifyIntermediateProof(proofData: ProofData): Promise<boolean> {
const proof = reconstructProofWithPublicInputs(proofData);
const makeEasyToVerifyInCircuit = true;
return this.verifyProof(proof, makeEasyToVerifyInCircuit);
}

/** @internal */
async verifyProof(proof: Uint8Array, makeEasyToVerifyInCircuit: boolean): Promise<boolean> {
await this.instantiate();
await this.api.acirInitVerificationKey(this.acirComposer);
return await this.api.acirVerifyProof(this.acirComposer, proof, makeEasyToVerifyInCircuit);
}

/** @internal */
async destroy(): Promise<void> {
if (!this.api) {
return;
Expand Down
7 changes: 6 additions & 1 deletion tooling/noir_js_backend_barretenberg/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
"noImplicitAny": false,
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules"],
"references": [
{
"path": "../noir_js_types"
}
]
}
5 changes: 5 additions & 0 deletions tooling/noir_js_backend_barretenberg/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"entryPoints": ["src/index.ts"],
"excludeInternal": true,
"disableSources": true,
}
3 changes: 2 additions & 1 deletion tooling/noir_js_types/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lib
lib
*.tsbuildinfo
3 changes: 2 additions & 1 deletion tooling/noir_js_types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"composite": true,
"declaration": true,
"module": "ESNext",
"moduleResolution": "node",
Expand All @@ -9,4 +10,4 @@
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
}