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: add double_verify integration test #4563

Closed
wants to merge 8 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
1 change: 0 additions & 1 deletion compiler/integration-tests/circuits/recursion/Prover.toml

This file was deleted.

This file was deleted.

26 changes: 16 additions & 10 deletions compiler/integration-tests/test/browser/recursion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ await initACVM();
const base_relative_path = '../../../../..';
const circuit_main = 'test_programs/execution_success/assert_statement_recursive';
const circuit_recursion = 'compiler/integration-tests/circuits/recursion';
const circuit_double_verify = 'test_programs/execution_success/double_verify_proof';

async function getCircuit(projectPath: string) {
const fm = createFileManager('/');
Expand All @@ -40,7 +41,7 @@ describe('It compiles noir program code, receiving circuit bytes and abi object.
circuit_main_toml = await new Response(await getFile(`${base_relative_path}/${circuit_main}/Prover.toml`)).text();
});

it('Should generate valid inner proof for correct input, then verify proof within a proof', async () => {
it('Should generate two valid inner proofs for correct input, then verify proofs within a proof', async () => {
const main_program = await getCircuit(`${base_relative_path}/${circuit_main}`);
const main_inputs: InputMap = TOML.parse(circuit_main_toml) as InputMap;

Expand All @@ -49,33 +50,38 @@ describe('It compiles noir program code, receiving circuit bytes and abi object.
const { witness: main_witnessUint8Array } = await new Noir(main_program).execute(main_inputs);

const main_proof = await main_backend.generateProof(main_witnessUint8Array);
const main_verification = await main_backend.verifyProof(main_proof);

logger.debug('main_verification', main_verification);

expect(main_verification).to.be.true;
const main_proof2 = await main_backend.generateProof(main_witnessUint8Array);

const numPublicInputs = 1;
const { proofAsFields, vkAsFields, vkHash } = await main_backend.generateRecursiveProofArtifacts(
main_proof,
numPublicInputs,
);
const {
proofAsFields: proofAsFields2,
vkAsFields: vkAsFields2,
vkHash: vkHash2,
} = await main_backend.generateRecursiveProofArtifacts(main_proof2, numPublicInputs);
expect(vkAsFields).to.be.deep.eq(vkAsFields2, 'two separate vks for the same program.');
expect(vkHash).to.be.eq(vkHash2, 'two separate vk hashes for the same program.');

const recursion_inputs: InputMap = {
verification_key: vkAsFields,
proof: proofAsFields,
public_inputs: [main_inputs.y as Field],
key_hash: vkHash,
proof_b: proofAsFields2,
};

logger.debug('recursion_inputs', recursion_inputs);

const recursion_program = await getCircuit(`${base_relative_path}/${circuit_recursion}`);
const recursion_program = await getCircuit(`${base_relative_path}/${circuit_double_verify}`);

const recursion_backend = new BarretenbergBackend(recursion_program);

const { witness: recursion_witnessUint8Array } = await new Noir(recursion_program).execute(recursion_inputs);

console.log('got here!');
const recursion_proof = await recursion_backend.generateProof(recursion_witnessUint8Array);

// Causes an "unreachable" error.
Expand All @@ -89,10 +95,10 @@ describe('It compiles noir program code, receiving circuit bytes and abi object.
//
// logger.debug('recursion_proofAsFields', recursion_proofAsFields);

const recursion_verification = await recursion_backend.verifyProof(recursion_proof);
// const recursion_verification = await recursion_backend.verifyProof(recursion_proof);

logger.debug('recursion_verification', recursion_verification);
// logger.debug('recursion_verification', recursion_verification);

expect(recursion_verification).to.be.true;
// expect(recursion_verification).to.be.true;
}).timeout(60 * 20e3);
});

This file was deleted.

96 changes: 96 additions & 0 deletions compiler/integration-tests/test/node/recursion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { expect } from 'chai';
import { Logger } from 'tslog';
import { Noir } from '@noir-lang/noir_js';

import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';
import { resolve, join } from 'path';
import { Field, InputMap } from '@noir-lang/noirc_abi';
import { createFileManager, compile } from '@noir-lang/noir_wasm';

const logger = new Logger({ name: 'test' });

const base_relative_path = '../../../../';
const circuit_main = './test_programs/execution_success/assert_statement_recursive';
const circuit_recursion = './compiler/integration-tests/circuits/recursion';
const circuit_double_verify = './test_programs/execution_success/double_verify_proof';

async function getCircuit(projectPath: string) {
console.log(__dirname);
const basePath = resolve(join(__dirname, base_relative_path));
console.log(basePath);
const absProjectPath = join(basePath, projectPath);
console.log(absProjectPath);
const fm = createFileManager(absProjectPath);
const result = await compile(fm);
if (!('program' in result)) {
throw new Error('Compilation failed');
}
return result.program;
}

describe('It compiles noir program code, receiving circuit bytes and abi object.', () => {
it('Should generate two valid inner proofs for correct input, then verify proofs within a proof', async () => {
const main_program = await getCircuit(circuit_main);
const main_inputs: InputMap = {
x: '3',
y: '3',
};

const main_backend = new BarretenbergBackend(main_program);

const { witness: main_witnessUint8Array } = await new Noir(main_program).execute(main_inputs);

const main_proof = await main_backend.generateProof(main_witnessUint8Array);
const main_proof2 = await main_backend.generateProof(main_witnessUint8Array);

const numPublicInputs = 1;
const { proofAsFields, vkAsFields, vkHash } = await main_backend.generateRecursiveProofArtifacts(
main_proof,
numPublicInputs,
);
const {
proofAsFields: proofAsFields2,
vkAsFields: vkAsFields2,
vkHash: vkHash2,
} = await main_backend.generateRecursiveProofArtifacts(main_proof2, numPublicInputs);
expect(vkAsFields).to.be.deep.eq(vkAsFields2, 'two separate vks for the same program.');
expect(vkHash).to.be.eq(vkHash2, 'two separate vk hashes for the same program.');

const recursion_inputs: InputMap = {
verification_key: vkAsFields,
proof: proofAsFields,
public_inputs: [main_inputs.y as Field],
key_hash: vkHash,
proof_b: proofAsFields2,
};

logger.debug('recursion_inputs', recursion_inputs);

const recursion_program = await getCircuit(circuit_double_verify);

const recursion_backend = new BarretenbergBackend(recursion_program);

const { witness: recursion_witnessUint8Array } = await new Noir(recursion_program).execute(recursion_inputs);

console.log('got here!');
const recursion_proof = await recursion_backend.generateProof(recursion_witnessUint8Array);

// Causes an "unreachable" error.
// Due to the fact that it's a non-recursive proof?
//
// const recursion_numPublicInputs = 1;
// const { proofAsFields: recursion_proofAsFields } = await recursion_backend.generateRecursiveProofArtifacts(
// recursion_proof,
// recursion_numPublicInputs,
// );
//
// logger.debug('recursion_proofAsFields', recursion_proofAsFields);

// const recursion_verification = await recursion_backend.verifyProof(recursion_proof);

// logger.debug('recursion_verification', recursion_verification);

// expect(recursion_verification).to.be.true;
}).timeout(60 * 20e3);
});

This file was deleted.

Loading