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: set up noir_js in integration tests #2871

Merged
merged 11 commits into from
Sep 28, 2023
1 change: 0 additions & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ jobs:
forge create --rpc-url http://127.0.0.1:8545 --mnemonic "test test test test test test test test test test test junk" src/1_mul.sol:UltraVerifier --json > mul_output.json
forge create --rpc-url http://127.0.0.1:8545 --mnemonic "test test test test test test test test test test test junk" src/main.sol:UltraVerifier --json > main_output.json


- name: Setup `integration-tests`
run: |
yarn workspace @noir-lang/source-resolver build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import newCompiler, {
init_log_level as compilerLogLevel,
} from "@noir-lang/noir_wasm";
import { decompressSync as gunzip } from "fflate";
import { acvm, abi } from "@noir-lang/noir_js";
import { acvm, abi, generateWitness } from "@noir-lang/noir_js";

// @ts-ignore
import { Barretenberg, RawBuffer, Crs } from "@aztec/bb.js";
Expand All @@ -17,8 +17,8 @@ import * as TOML from "smol-toml";

const logger = new Logger({ name: "test", minLevel: TEST_LOG_LEVEL });

const { default: initACVM, executeCircuit, compressWitness } = acvm;
const { default: newABICoder, abiEncode } = abi;
const { default: initACVM } = acvm;
const { default: newABICoder } = abi;

await newCompiler();
await newABICoder();
Expand Down Expand Up @@ -54,7 +54,7 @@ await api.srsInitSrs(

const acirComposer = await api.acirNewAcirComposer(CIRCUIT_SIZE);

async function getCircuit(noirSource) {
async function getCircuit(noirSource: string) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
initializeResolver((id: string) => {
logger.debug("source-resolver: resolving:", id);
Expand All @@ -64,18 +64,6 @@ async function getCircuit(noirSource) {
return compile({});
}

async function generateWitness(acir, abi, inputs) {
const witnessMap: WitnessMap = abiEncode(abi, inputs, null);

const compressedByteCode = Uint8Array.from(atob(acir), (c) =>
c.charCodeAt(0),
);

return executeCircuit(compressedByteCode, witnessMap, () => {
throw Error("unexpected oracle");
});
}

async function generateProof(
acirUint8Array: Uint8Array,
witnessUint8Array: Uint8Array,
Expand Down Expand Up @@ -127,22 +115,21 @@ describe("It compiles noir program code, receiving circuit bytes and abi object.
});

it("Should generate valid inner proof for correct input, then verify proof within a proof", async () => {
//@ts-ignore
const { circuit: main_circuit, abi: main_abi } =
await getCircuit(circuit_main_source);
const main_inputs = TOML.parse(circuit_main_toml);

const main_witness = await generateWitness(
main_circuit,
main_abi,
const main_witnessUint8Array = await generateWitness(
{
bytecode: main_circuit,
abi: main_abi,
},
main_inputs,
);
const main_compressedByteCode = Uint8Array.from(atob(main_circuit), (c) =>
c.charCodeAt(0),
);
const main_compressedWitness = compressWitness(main_witness);
const main_acirUint8Array = gunzip(main_compressedByteCode);
const main_witnessUint8Array = gunzip(main_compressedWitness);

const optimizeMainProofForRecursion = true;

Expand Down Expand Up @@ -181,7 +168,7 @@ describe("It compiles noir program code, receiving circuit bytes and abi object.
public_inputs: [main_inputs.y],
key_hash: vkHash,
// eslint-disable-next-line prettier/prettier
input_aggregation_object: ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]
input_aggregation_object: ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
};

logger.debug("recursion_inputs", recursion_inputs);
Expand All @@ -190,9 +177,11 @@ describe("It compiles noir program code, receiving circuit bytes and abi object.
circuit_recursion_source,
);

const recursion_witness = await generateWitness(
recursion_circuit,
recursion_abi,
const recursion_witnessUint8Array = await generateWitness(
{
bytecode: recursion_circuit,
abi: recursion_abi,
},
recursion_inputs,
);

Expand All @@ -201,9 +190,7 @@ describe("It compiles noir program code, receiving circuit bytes and abi object.
(c) => c.charCodeAt(0),
);

const recursion_compressedWitness = compressWitness(recursion_witness);
const recursion_acirUint8Array = gunzip(recursion_compressedByteCode);
const recursion_witnessUint8Array = gunzip(recursion_compressedWitness);

const optimizeRecursionProofForRecursion = false;

Expand Down
1 change: 0 additions & 1 deletion tooling/noir_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0",
"clean": "rm -rf ./lib"

},
"devDependencies": {
"@aztec/bb.js": "0.7.2",
Expand Down
5 changes: 4 additions & 1 deletion tooling/noir_js/src/witness_generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { executeCircuit } from '@noir-lang/acvm_js';
import { witnessMapToUint8Array } from './serialize.js';

// Generates the witnesses needed to feed into the chosen proving system
export async function generateWitness(compiledProgram, inputs): Promise<Uint8Array> {
export async function generateWitness(
compiledProgram: { bytecode: string; abi: unknown },
inputs: unknown,
): Promise<Uint8Array> {
// Throws on ABI encoding error
const witnessMap = abiEncode(compiledProgram.abi, inputs, null);

Expand Down