Skip to content

Commit

Permalink
Merge branch 'master' of github.com:noir-lang/noir into member-access…
Browse files Browse the repository at this point in the history
…-formatter
  • Loading branch information
jonybur committed Oct 11, 2023
2 parents 60ce746 + 12daad1 commit 582bdcf
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 36 deletions.
6 changes: 5 additions & 1 deletion acvm-repo/acvm/src/compiler/transformers/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ impl FallbackTransformer {
}

Ok((
Circuit { current_witness_index: witness_idx, opcodes: acir_supported_opcodes, ..acir },
Circuit {
current_witness_index: witness_idx - 1,
opcodes: acir_supported_opcodes,
..acir
},
new_opcode_positions,
))
}
Expand Down
8 changes: 1 addition & 7 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,13 +1864,7 @@ impl Context {
mod tests {
use std::{collections::HashMap, rc::Rc};

use acvm::{
acir::{
circuit::Opcode,
native_types::{Expression, Witness},
},
FieldElement,
};
use acvm::FieldElement;

use crate::{
brillig::Brillig,
Expand Down
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';
9 changes: 6 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 @@ -20,6 +19,10 @@ export class Noir {
}
}

async destroy(): Promise<void> {
await this.backend?.destroy();
}

private getBackend(): Backend {
if (this.backend === undefined) throw new Error('Operation requires a backend but none was provided');
return this.backend;
Expand All @@ -30,7 +33,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.

15 changes: 9 additions & 6 deletions tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* 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';
import { BackendOptions } from './types.js';

// This is the number of bytes in a UltraPlonk proof
// minus the public inputs.
Expand All @@ -14,11 +16,12 @@ export class BarretenbergBackend implements Backend {
private api: any;
private acirComposer: any;
private acirUncompressedBytecode: Uint8Array;
private numberOfThreads = 1;

constructor(acirCircuit: CompiledCircuit, numberOfThreads = 1) {
constructor(
acirCircuit: CompiledCircuit,
private options: BackendOptions = { threads: 1 },
) {
const acirBytecodeBase64 = acirCircuit.bytecode;
this.numberOfThreads = numberOfThreads;
this.acirUncompressedBytecode = acirToUint8Array(acirBytecodeBase64);
}

Expand All @@ -27,7 +30,7 @@ export class BarretenbergBackend implements Backend {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const { Barretenberg, RawBuffer, Crs } = await import('@aztec/bb.js');
const api = await Barretenberg.new(this.numberOfThreads);
const api = await Barretenberg.new(this.options.threads);

const [_exact, _total, subgroupSize] = await api.acirGetCircuitSizes(this.acirUncompressedBytecode);
const crs = await Crs.new(subgroupSize + 1);
Expand Down Expand Up @@ -65,12 +68,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
3 changes: 3 additions & 0 deletions tooling/noir_js_backend_barretenberg/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type BackendOptions = {
threads: number;
};
2 changes: 1 addition & 1 deletion tooling/noir_js_types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface Backend {
generateIntermediateProof(decompressedWitness: Uint8Array): Promise<ProofData>;

verifyFinalProof(proofData: ProofData): Promise<boolean>;

verifyIntermediateProof(proofData: ProofData): Promise<boolean>;
destroy(): Promise<void>;
}

export type ProofData = {
Expand Down

0 comments on commit 582bdcf

Please sign in to comment.