-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add integration test for verifying a recursive proof onchain
- Loading branch information
1 parent
37315f8
commit 16d1c23
Showing
6 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ const config: HardhatUserConfig = { | |
}, | ||
}, | ||
}, | ||
mocha: { | ||
timeout: 5 * 60 * 1000, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
compiler/integration-tests/test/node/onchain_recursive_verification.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect } from 'chai'; | ||
import { ethers } from 'hardhat'; | ||
|
||
import { readFileSync } from 'node:fs'; | ||
import { resolve } from 'path'; | ||
import toml from 'toml'; | ||
|
||
import { compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm'; | ||
import { Noir } from '@noir-lang/noir_js'; | ||
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg'; | ||
import { Field, InputMap } from '@noir-lang/noirc_abi'; | ||
|
||
compilerLogLevel('INFO'); | ||
|
||
it(`smart contract can verify a recursive proof`, async () => { | ||
const main_source_path = resolve(`./circuits/main/src/main.nr`); | ||
const main_program = compile(main_source_path); | ||
|
||
const recursion_source_path = resolve(`./circuits/recursion/src/main.nr`); | ||
const recursion_program = compile(recursion_source_path); | ||
|
||
// Intermediate proof | ||
|
||
const main_backend = new BarretenbergBackend(main_program); | ||
const main = new Noir(main_program); | ||
|
||
const main_prover_toml = readFileSync(resolve(`./circuits/main/Prover.toml`)).toString(); | ||
const main_inputs = toml.parse(main_prover_toml); | ||
|
||
const { witness: main_witness } = await main.execute(main_inputs); | ||
const intermediate_proof = await main_backend.generateIntermediateProof(main_witness); | ||
|
||
expect(await main_backend.verifyIntermediateProof(intermediate_proof)).to.be.true; | ||
|
||
const { proofAsFields, vkAsFields, vkHash } = await main_backend.generateIntermediateProofArtifacts( | ||
intermediate_proof, | ||
1, // 1 public input | ||
); | ||
|
||
// Final proof | ||
|
||
const recursion_backend = new BarretenbergBackend(recursion_program); | ||
const recursion = new Noir(recursion_program, recursion_backend); | ||
|
||
const recursion_inputs: InputMap = { | ||
verification_key: vkAsFields, | ||
proof: proofAsFields, | ||
public_inputs: [main_inputs.y as Field], | ||
key_hash: vkHash, | ||
input_aggregation_object: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], | ||
}; | ||
|
||
const recursion_proof = await recursion.generateFinalProof(recursion_inputs); | ||
|
||
// Smart contract verification | ||
|
||
const contract = await ethers.deployContract('contracts/recursion.sol:UltraVerifier', []); | ||
|
||
const result = await contract.verify.staticCall(recursion_proof.proof, recursion_proof.publicInputs); | ||
|
||
expect(result).to.be.true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ | |
"nixpkgs", | ||
"noirc", | ||
"noirup", | ||
"nomicfoundation", | ||
"pedersen", | ||
"peekable", | ||
"plonkc", | ||
|