Skip to content

Commit

Permalink
chore: standardize ACIR serialization format in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Oct 11, 2023
1 parent 35f7a9d commit 52bf717
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tooling/noir_js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import * as abi from '@noir-lang/noirc_abi';

export { acvm, abi };

export { acirToUint8Array, witnessMapToUint8Array } from './serialize.js';
export { WitnessMap } from '@noir-lang/acvm_js';

export { Noir } from './program.js';
5 changes: 2 additions & 3 deletions tooling/noir_js/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
import { generateWitness } from './witness_generation.js';
import initAbi, { abiDecode, InputMap, InputValue } from '@noir-lang/noirc_abi';
import initACVM from '@noir-lang/acvm_js';
import { witnessMapToUint8Array } from './serialize.js';
import initACVM, { compressWitness } from '@noir-lang/acvm_js';

export class Noir {
constructor(
Expand All @@ -30,7 +29,7 @@ export class Noir {
await this.init();
const witness = await generateWitness(this.circuit, inputs);
const { return_value: returnValue } = abiDecode(this.circuit.abi, witness);
return { witness: witnessMapToUint8Array(witness), returnValue };
return { witness: compressWitness(witness), returnValue };
}

// Initial inputs to your program
Expand Down
17 changes: 0 additions & 17 deletions tooling/noir_js/src/serialize.ts

This file was deleted.

5 changes: 3 additions & 2 deletions tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { decompressSync as gunzip } from 'fflate';
import { acirToUint8Array } from './serialize.js';
import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';

Expand Down Expand Up @@ -65,12 +66,12 @@ export class BarretenbergBackend implements Backend {
return this.generateProof(witness, makeEasyToVerifyInCircuit);
}

async generateProof(decompressedWitness: Uint8Array, makeEasyToVerifyInCircuit: boolean): Promise<ProofData> {
async generateProof(compressedWitness: Uint8Array, makeEasyToVerifyInCircuit: boolean): Promise<ProofData> {
await this.instantiate();
const proofWithPublicInputs = await this.api.acirCreateProof(
this.acirComposer,
this.acirUncompressedBytecode,
decompressedWitness,
gunzip(compressedWitness),
makeEasyToVerifyInCircuit,
);

Expand Down

0 comments on commit 52bf717

Please sign in to comment.