-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mv/dyn-nested-slice-builtin
- Loading branch information
Showing
7 changed files
with
98 additions
and
18 deletions.
There are no files selected for viewing
23 changes: 13 additions & 10 deletions
23
compiler/integration-tests/circuits/recursion/src/main.nr
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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
use dep::std; | ||
|
||
fn main( | ||
verification_key: [Field; 114], | ||
proof: [Field; 94], | ||
public_inputs: [Field; 1], | ||
key_hash: Field, | ||
input_aggregation_object: [Field; 16] | ||
) -> pub [Field; 16] { | ||
let vk : [Field] = verification_key; | ||
let p : [Field] = proof; | ||
let pi : [Field] = public_inputs; | ||
std::verify_proof(vk, p, pi, key_hash, input_aggregation_object) | ||
verification_key : [Field; 114], | ||
proof : [Field; 94], | ||
public_inputs : [Field; 1], | ||
key_hash : Field, | ||
) -> pub [Field;16]{ | ||
let input_aggregation_object = [0; 16]; | ||
std::verify_proof( | ||
verification_key.as_slice(), | ||
proof.as_slice(), | ||
public_inputs.as_slice(), | ||
key_hash, | ||
input_aggregation_object | ||
) | ||
} |
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
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
import { expect } from 'chai'; | ||
import { ethers } from 'hardhat'; | ||
|
||
import { readFileSync } from 'node:fs'; | ||
import { resolve } from 'path'; | ||
import toml from 'toml'; | ||
|
||
import { compile, CompiledProgram, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm'; | ||
import { Noir } from '@noir-lang/noir_js'; | ||
import { BarretenbergBackend, flattenPublicInputs } 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 inner_source_path = resolve(`../../test_programs/execution_success/assert_statement/src/main.nr`); | ||
const inner_program = (compile(inner_source_path) as { program: CompiledProgram }).program; | ||
|
||
const recursion_source_path = resolve(`./circuits/recursion/src/main.nr`); | ||
const recursion_program = (compile(recursion_source_path) as { program: CompiledProgram }).program; | ||
|
||
// Intermediate proof | ||
|
||
const inner_backend = new BarretenbergBackend(inner_program); | ||
const inner = new Noir(inner_program); | ||
|
||
const inner_prover_toml = readFileSync( | ||
resolve(`../../test_programs/execution_success/assert_statement/Prover.toml`), | ||
).toString(); | ||
const inner_inputs = toml.parse(inner_prover_toml); | ||
|
||
const { witness: main_witness } = await inner.execute(inner_inputs); | ||
const intermediate_proof = await inner_backend.generateIntermediateProof(main_witness); | ||
|
||
expect(await inner_backend.verifyIntermediateProof(intermediate_proof)).to.be.true; | ||
|
||
const { proofAsFields, vkAsFields, vkHash } = await inner_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: [inner_inputs.y as Field], | ||
key_hash: vkHash, | ||
}; | ||
|
||
const recursion_proof = await recursion.generateFinalProof(recursion_inputs); | ||
expect(await recursion.verifyFinalProof(recursion_proof)).to.be.true; | ||
|
||
// Smart contract verification | ||
|
||
const contract = await ethers.deployContract('contracts/recursion.sol:UltraVerifier', []); | ||
|
||
const result = await contract.verify.staticCall( | ||
recursion_proof.proof, | ||
flattenPublicInputs(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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ | |
"nixpkgs", | ||
"noirc", | ||
"noirup", | ||
"nomicfoundation", | ||
"pedersen", | ||
"peekable", | ||
"plonkc", | ||
|
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