Skip to content

Commit

Permalink
chore: throw together janky test
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Mar 15, 2024
1 parent 4cf700b commit dca48dc
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
5 changes: 5 additions & 0 deletions compiler/integration-tests/circuits/double_verify/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "double_verify"
type = "bin"
authors = [""]
[dependencies]
23 changes: 23 additions & 0 deletions compiler/integration-tests/circuits/double_verify/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use dep::std;

fn main(
verification_key: [Field; 114],
proof: [Field; 93],
proof2: [Field; 93],
public_inputs: [Field; 1],
key_hash: Field
) {
std::verify_proof(
verification_key.as_slice(),
proof.as_slice(),
public_inputs.as_slice(),
key_hash
);

std::verify_proof(
verification_key.as_slice(),
proof2.as_slice(),
public_inputs.as_slice(),
key_hash
)
}
1 change: 0 additions & 1 deletion compiler/integration-tests/circuits/recursion/Prover.toml

This file was deleted.

58 changes: 58 additions & 0 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 = 'compiler/integration-tests/circuits/double_verify';

async function getCircuit(projectPath: string) {
const fm = createFileManager('/');
Expand Down Expand Up @@ -95,4 +96,61 @@ describe('It compiles noir program code, receiving circuit bytes and abi object.

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

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;

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 } = await main_backend.generateRecursiveProofArtifacts(
main_proof2,
numPublicInputs,
);

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

logger.debug('recursion_inputs', recursion_inputs);

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);

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);
});

0 comments on commit dca48dc

Please sign in to comment.