-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
197 additions
and
0 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,90 @@ | ||
{ | ||
"protocol": "groth16", | ||
"curve": "bn128", | ||
"nPublic": 2, | ||
"vk_alpha_1": [ | ||
"20491192805390485299153009773594534940189261866228447918068658471970481763042", | ||
"9383485363053290200918347156157836566562967994039712273449902621266178545958", | ||
"1" | ||
], | ||
"vk_beta_2": [ | ||
[ | ||
"6375614351688725206403948262868962793625744043794305715222011528459656738731", | ||
"4252822878758300859123897981450591353533073413197771768651442665752259397132" | ||
], | ||
[ | ||
"10505242626370262277552901082094356697409835680220590971873171140371331206856", | ||
"21847035105528745403288232691147584728191162732299865338377159692350059136679" | ||
], | ||
["1", "0"] | ||
], | ||
"vk_gamma_2": [ | ||
[ | ||
"10857046999023057135944570762232829481370756359578518086990519993285655852781", | ||
"11559732032986387107991004021392285783925812861821192530917403151452391805634" | ||
], | ||
[ | ||
"8495653923123431417604973247489272438418190587263600148770280649306958101930", | ||
"4082367875863433681332203403145435568316851327593401208105741076214120093531" | ||
], | ||
["1", "0"] | ||
], | ||
"vk_delta_2": [ | ||
[ | ||
"3467004866717634776339573347423169002547635002985878815508898961522743506452", | ||
"19865331138541507750394553392171827109124121759749012695741881283803108508347" | ||
], | ||
[ | ||
"2189040294157466407187767498553323210668670372829423239655416479671231034454", | ||
"9060993844443059227358689399147552366673505348777583132029617367152835581644" | ||
], | ||
["1", "0"] | ||
], | ||
"vk_alphabeta_12": [ | ||
[ | ||
[ | ||
"2029413683389138792403550203267699914886160938906632433982220835551125967885", | ||
"21072700047562757817161031222997517981543347628379360635925549008442030252106" | ||
], | ||
[ | ||
"5940354580057074848093997050200682056184807770593307860589430076672439820312", | ||
"12156638873931618554171829126792193045421052652279363021382169897324752428276" | ||
], | ||
[ | ||
"7898200236362823042373859371574133993780991612861777490112507062703164551277", | ||
"7074218545237549455313236346927434013100842096812539264420499035217050630853" | ||
] | ||
], | ||
[ | ||
[ | ||
"7077479683546002997211712695946002074877511277312570035766170199895071832130", | ||
"10093483419865920389913245021038182291233451549023025229112148274109565435465" | ||
], | ||
[ | ||
"4595479056700221319381530156280926371456704509942304414423590385166031118820", | ||
"19831328484489333784475432780421641293929726139240675179672856274388269393268" | ||
], | ||
[ | ||
"11934129596455521040620786944827826205713621633706285934057045369193958244500", | ||
"8037395052364110730298837004334506829870972346962140206007064471173334027475" | ||
] | ||
] | ||
], | ||
"IC": [ | ||
[ | ||
"18635637960557560857094512684047887771596119327447282264110915689478359176884", | ||
"2787739109285944951079006253283606975566487445507222876760682453501866793407", | ||
"1" | ||
], | ||
[ | ||
"5924520914420601398188001890215477493578059223690495899194579533928493711633", | ||
"10458548929339196911259801917183441320857030738864516659971366674948828826220", | ||
"1" | ||
], | ||
[ | ||
"700433635233066042387364180517373526251183001161528242738155819104314938031", | ||
"5917976447441905930232643207659393469418720332008787407970690068286695117993", | ||
"1" | ||
] | ||
] | ||
} |
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,26 @@ | ||
{ | ||
"root": "0x1d0372864732dfcd91c18414fd4126e1e38293be237aad4315a026bf23d02717", | ||
"signal_hash": "0xbc6bb462e38af7da48e0ae7b5cbae860141c04e5af2cf92328cd6548df111f", | ||
"external_nullifier_hash": "0xfd3a1e9736c12a5d4a31f26362b577ccafbd523d358daf40cdc04d90e17f77", | ||
"nullifier_hash": "0x4b7790813c37c910b41236334ce9b1841d430e3b4874e89778e1afd0fd3a7b6", | ||
"proof": [ | ||
[ | ||
"0x1367c9f9d019f56eb5afc3194d88878fefa247f6b199c5ceca99c358d73b74f3", | ||
"0x165ca9355cda35740d5077ca6c46d39ad6ae1a43ae4cfaa9b0fa4ce7a8afa6a9" | ||
], | ||
[ | ||
[ | ||
"0xf8624ae493b6ded53aeb34909405e6b004f87de66d017032258c644192bfad3", | ||
"0xfc743393098e3793d3012882ae655ee6eba62ee991ae353b7f5a857cf666016" | ||
], | ||
[ | ||
"0x2b868474fed386af810dbb3b433f6cedbddf26e9d646949558a1829cecc44738", | ||
"0x9e057efc9e6731bca034e4da089406af4f58bd667cc30194950ab98a8632169" | ||
] | ||
], | ||
[ | ||
"0x18288f4944f31607dd7d338b4eb8acec173ff843f15b28d070937be4d97dff5f", | ||
"0x1567e0b2d66af4df46179f4fdc120ccd6d3976847693a22147cdf819810f44a9" | ||
] | ||
] | ||
} |
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,81 @@ | ||
use std::{fmt::Debug, vec}; | ||
|
||
use axiom_circuit::subquery::groth16::{parse_groth16_input, Groth16Input}; | ||
use axiom_sdk::{ | ||
axiom::{AxiomAPI, AxiomComputeFn, AxiomComputeInput, AxiomResult}, | ||
cmd::run_cli, | ||
halo2_base::{gates::RangeInstructions, AssignedValue}, | ||
subquery::groth16::assign_groth16_input, | ||
Fr, | ||
}; | ||
use serde_json::{json, Value}; | ||
|
||
#[AxiomComputeInput] | ||
pub struct Groth16ClientInput { | ||
pub dummy: u64, | ||
} | ||
|
||
const MAX_PROOFS: usize = 16; | ||
|
||
pub fn parse_worldcoin_input() -> Groth16Input<Fr> { | ||
let vk_string: String = include_str!("../data/worldcoin/vk.json").to_string(); | ||
|
||
let input_json_str: &str = include_str!("../data/worldcoin/worldcoin_input.json"); | ||
|
||
let input_json: Value = serde_json::from_str(input_json_str).unwrap(); | ||
|
||
let mut public_input_json = json!([]); | ||
public_input_json[0] = input_json["root"].clone(); | ||
public_input_json[1] = input_json["nullifierHash"].clone(); | ||
public_input_json[2] = input_json["signalHash"].clone(); | ||
public_input_json[3] = input_json["externalNullifierHash"].clone(); | ||
|
||
// root, nullifierHash, signalHash, externalNullifierHash | ||
|
||
let pub_string = serde_json::to_string(&public_input_json).unwrap(); | ||
|
||
let proof = input_json["proof"].clone(); | ||
|
||
let pf_string = json!({ | ||
"pi_a": [proof[0][0], proof[0][1], "1"], | ||
"pi_b": [proof[1][0], proof[1][1], ["1", "0"]], | ||
"pi_c": [proof[2][0], proof[2][1], "1"], | ||
"protocol": "groth16", | ||
"curve": "bn128" | ||
}) | ||
.to_string(); | ||
|
||
let input = parse_groth16_input(vk_string, pf_string, pub_string); | ||
input | ||
} | ||
|
||
impl AxiomComputeFn for Groth16ClientInput { | ||
fn compute( | ||
api: &mut AxiomAPI, | ||
_: Groth16ClientCircuitInput<AssignedValue<Fr>>, | ||
) -> Vec<AxiomResult> { | ||
let zero = api.ctx().load_zero(); | ||
|
||
let mut return_vec: Vec<AxiomResult> = Vec::new(); | ||
return_vec.reserve(MAX_PROOFS); | ||
|
||
for i in 1..=MAX_PROOFS { | ||
let input = parse_worldcoin_input(); | ||
let assigned_input = assign_groth16_input(api, input); | ||
let nullifier_hash: AxiomResult = assigned_input.public_inputs[1].into(); | ||
let signal_hash: AxiomResult = assigned_input.public_inputs[2].into(); | ||
let verify = api.groth16_verify(assigned_input); | ||
let verify = api.from_hi_lo(verify); | ||
|
||
api.range.check_less_than(api.ctx(), zero, verify, 1); | ||
return_vec.push(nullifier_hash); | ||
return_vec.push(signal_hash) | ||
} | ||
|
||
return_vec | ||
} | ||
} | ||
|
||
fn main() { | ||
run_cli::<Groth16ClientInput>(); | ||
} |