-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from vlayer-xyz/leo/recursive-proofs
Recursive proofs
- Loading branch information
Showing
8 changed files
with
113 additions
and
39 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"printWidth": 120 | ||
} |
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,8 +1,9 @@ | ||
[workspace] | ||
members = [ | ||
"circuits/poseidon", | ||
"circuits/rlp", | ||
"circuits/keccak", | ||
"circuits/keccak_2x", | ||
"circuits/rlp" | ||
"circuits/recursive_poseidon" | ||
] | ||
default-member = "circuits/keccak" |
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,3 @@ | ||
[package] | ||
name = "recursive_poseidon" | ||
type = "bin" |
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,15 @@ | ||
use dep::std; | ||
|
||
fn main( | ||
verification_key: [Field; 114], | ||
proof: [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 | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { initCircuit, readInputMap } from "./utils.js"; | ||
import { InputMap } from "@noir-lang/noir_js"; | ||
import { Field } from "@noir-lang/noirc_abi"; | ||
import assert from "assert"; | ||
|
||
const packageName = "poseidon"; | ||
const poseidon = await initCircuit(packageName); | ||
|
||
const poseidonInputs = await readInputMap(packageName); | ||
|
||
let { witness: poseidonWitness } = await poseidon.noir.execute(poseidonInputs); | ||
|
||
console.time("poseidon.bb.generateIntermediateProof"); | ||
const poseidonProof = await poseidon.bb.generateIntermediateProof(poseidonWitness); | ||
console.timeEnd("poseidon.bb.generateIntermediateProof"); | ||
|
||
console.time("poseidon.bb.verifyIntermediateProof"); | ||
const poseidonProofVerification = await poseidon.bb.verifyIntermediateProof(poseidonProof); | ||
assert(poseidonProofVerification, "Poseidon proof verification failed"); | ||
console.timeEnd("poseidon.bb.verifyIntermediateProof"); | ||
|
||
console.time("generateIntermediateProofArtifacts"); | ||
const numPublicInputs = 1; | ||
const { proofAsFields, vkAsFields, vkHash } = await poseidon.bb.generateIntermediateProofArtifacts( | ||
poseidonProof, | ||
numPublicInputs, | ||
); | ||
console.timeEnd("generateIntermediateProofArtifacts"); | ||
|
||
await poseidon.noir.destroy(); | ||
|
||
// RECURSIVE PROOF | ||
const recursivePoseidon = await initCircuit("recursive_poseidon"); | ||
const recursionInputs: InputMap = { | ||
verification_key: vkAsFields, | ||
proof: proofAsFields, | ||
public_inputs: [(await readInputMap(packageName)).x as Field], | ||
key_hash: vkHash, | ||
}; | ||
const { witness: recursivePoseidonWitness } = await recursivePoseidon.noir.execute(recursionInputs); | ||
|
||
console.time("recursivePoseidon.bb.generateFinalProof"); | ||
const recursivePoseidonProof = await recursivePoseidon.bb.generateFinalProof(recursivePoseidonWitness); | ||
console.timeEnd("recursivePoseidon.bb.generateFinalProof"); | ||
|
||
console.time("recursivePoseidon.bb.verifyFinalProof"); | ||
const recursivePoseidonProofVerification = await recursivePoseidon.bb.verifyFinalProof(recursivePoseidonProof); | ||
assert(recursivePoseidonProofVerification, "Recursive Poseidon proof verification failed"); | ||
console.timeEnd("recursivePoseidon.bb.verifyFinalProof"); | ||
|
||
await recursivePoseidon.noir.destroy(); |
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