Skip to content

Commit

Permalink
reading input files + proof generation works
Browse files Browse the repository at this point in the history
Janmajayamall committed Oct 4, 2022

Verified

This commit was signed with the committer’s verified signature.
TheLocehiliosan Tim Byrne
1 parent c01409a commit 3ad21d8
Showing 8 changed files with 234 additions and 166 deletions.
Binary file added maze-cli/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions maze-cli/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2022-08-23
218 changes: 52 additions & 166 deletions maze-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::Parser;
use halo2_curves::bn256::{Bn256, Fq, Fr, G1Affine};
use halo2_proofs::{
circuit::{floor_planner::V1, Layouter, Value},
@@ -185,29 +186,15 @@ struct Accumulation {
}

impl Accumulation {
pub fn new<const N: usize>(testdata: Testdata<N>) -> Self {
let params =
ParamsKZG::<Bn256>::setup(2 as u32, ChaCha20Rng::from_seed(Default::default()));
pub fn new(
vk: VerifyingKey<Bn256>,
public_signals: Vec<PublicSignals<Fr>>,
proofs: Vec<Proof<Bn256>>,
) -> Self {
let params = ParamsKZG::<Bn256>::setup(2, ChaCha20Rng::from_seed(Default::default()));

let vk: VerifyingKey<Bn256> = serde_json::from_str(testdata.vk).unwrap();
let protocol = compile(&vk);

let public_signals = testdata
.public_signals
.iter()
.map(|public_signals| {
serde_json::from_str::<PublicSignals<Fr>>(public_signals).unwrap()
})
.collect_vec();
let proofs = testdata
.proofs
.iter()
.map(|proof| {
serde_json::from_str::<Proof<Bn256>>(proof)
.unwrap()
.to_compressed_le()
})
.collect_vec();
let proofs: Vec<Vec<u8>> = proofs.iter().map(|p| p.to_compressed_le()).collect();

let mut accumulators = public_signals
.iter()
@@ -341,157 +328,56 @@ impl Circuit<Fr> for Accumulation {
}
}

pub struct Testdata<const N: usize> {
pub struct Data<const N: usize> {
pub vk: &'static str,
pub proofs: [&'static str; N],
pub public_signals: [&'static str; N],
}

fn main() {}

// pub const TESTDATA_HALO2: Testdata<1> = Testdata {
// vk: r#"
// {
// "protocol": "plonk",
// "curve": "bn128",
// "nPublic": 1,
// "power": 11,
// "k1": "2",
// "k2": "3",
// "Qm": [
// "3349529800503134758031206628826762579744090389775720856324415703418132588272",
// "1047380119467254909383032258743707561779783672376181143324721807183433895005",
// "1"
// ],
// "Ql": [
// "7767045214241100521202624210544067470568603896753786311669908116745944438330",
// "2761503195407699512821418421837091792920914786423811892261268458108417046825",
// "1"
// ],
// "Qr": [
// "2975170524298576570303711212258436671762476108775473882749069044845953535499",
// "14378372896685219137765897674012660076935852372658477152445798047040143090024",
// "1"
// ],
// "Qo": [
// "9954726969673494279518385350127630762618300791674628690913856164268433703179",
// "13965759471775973075363285410020114951590804896282136534205026646287563189772",
// "1"
// ],
// "Qc": [
// "16212144331199537797769995963505212438301349409393139691774264125327619032439",
// "17085616814509624070169907909376975087673229154027196667482507285696043222953",
// "1"
// ],
// "S1": [
// "21427438936074527438404157582664231491469818071679458860143386701810092744404",
// "19911030453621062116641782598975750504385985365438849435660556532368164383429",
// "1"
// ],
// "S2": [
// "13802677720850567775992768839702562890586195816216161661887530587428202866726",
// "7079192343351352262490439774376827531848577755489091121777421558213991392309",
// "1"
// ],
// "S3": [
// "7382434879293711723612677553350129386486281744510841088538187725327021521690",
// "11862269561183216572203078221388721953182973401672938240744501637694249454749",
// "1"
// ],
// "X_2": [
// [
// "17697945884356840746175007528786997911945651836283409056261355173034919217326",
// "11501088178268619001213046246621713845912613526390023569108826835703460118408"
// ],
// [
// "2426853463090583396092113656235496011757344467781401934015976708559998134240",
// "18934756257331934407911971941197693338781042972388885568003065304450754441155"
// ],
// [
// "1",
// "0"
// ]
// ],
// "w": "1120550406532664055539694724667294622065367841900378087843176726913374367458"
// }
// "#,
// proofs: [r#"{
// "A": [
// "11061059603189782590330418259165078776630514368672082688811243104044860101540",
// "21668757428762543016671135403653337903225051298789513367270755978051709738572",
// "1"
// ],
// "B": [
// "15086270057259696475553262311245448542212613657734428927573100611839505480405",
// "15018511197851761273177786510821312288823130543628495195956277770824042190722",
// "1"
// ],
// "C": [
// "14972338772264545077554193622334454585886430717733475952116247858333029051612",
// "18054617390851292490340784872096307735301268676836314087254309676459499099352",
// "1"
// ],
// "Z": [
// "14382338141451024608292942544807617949449861494221150754991236959826838416669",
// "10385796778063295246729293672521215747529662283495782347357027111939539405273",
// "1"
// ],
// "T1": [
// "12751261278277586544140220350597873383550169238072927910121553847855318517163",
// "10945599048902805478868261214279777223927364741842524822724265316476458100695",
// "1"
// ],
// "T2": [
// "5973795993600689757811815813854288461127743059999624555641758467641758046626",
// "8726815948989040187593929257900012211722987404525002145019657362525782979044",
// "1"
// ],
// "T3": [
// "21072089102306420569765505555148563215048857791981467046074242987486533089930",
// "17535943633965333368863208309663816996221234488938464214457981145265544794225",
// "1"
// ],
// "eval_a": "19726214196348323683839603021032263816939421240984180066385077192452675481471",
// "eval_b": "2333267538690138233648092707823188338618694351416835528648245962758838356337",
// "eval_c": "10971899192792562347132356007458724596801409552494366719278016565035749074651",
// "eval_s1": "6159818742975066475291358495938614244240245684888756593045209785852937729279",
// "eval_s2": "15197205121556034064086123849398780541310753223034430556904169800753100031633",
// "eval_zw": "5530376799911596881715592680894011517238842016192161340525184837122297439950",
// "eval_r": "19659936227615256346904535692177058613252049032763580820688462126145909608495",
// "Wxi": [
// "6740641879457334845854395780205816355956771529536935615443431702468550162214",
// "21183255617191143724097347727344457324556551775846802887934369815266291584190",
// "1"
// ],
// "Wxiw": [
// "21335840114976920556842587201078357495072120383201015684328760344203390789325",
// "8096904663846811709871156788274714302796579221932332607896751009422510513707",
// "1"
// ],
// "protocol": "plonk",
// "curve": "bn128"
// }"#],
// public_signals: [r#"[
// "16071293540883839718875621424443923800287184249862748659884745950088030321914"
// ]"#],
// };

// #[derive(Parser)]
// struct Cli {
// vk: std::path::PathBuf,
// proofs_dir: std::path::PathBuf,
// public_signals_dir: std::path::PathBuf,
// count: usize,
// }
#[derive(Parser)]
struct Cli {
vk: std::path::PathBuf,
input_dir: std::path::PathBuf,
count: usize,
}

// fn parse_cmds() {
// // (1) Read files into Testdata struct
// // (2) Check whether it works
// // (3) Export solidity verifier bytecode
// // (4)
// let args = Cli::parse();
// // let d = File::open("path").unwrap();
// }
fn main() {
// (1) Read files into Testdata struct
// (2) Check whether it works
// (3) Export solidity verifier bytecode
// (4)
let args = Cli::parse();

let vk = std::fs::read_to_string(&args.vk).unwrap();
let mut proofs: Vec<String> = vec![];
let mut public_signals: Vec<String> = vec![];

(0..args.count).for_each(|i| {
let mut proof = args.input_dir.clone();
proof.extend(vec![format!("proof{}.json", i + 1)]);
proofs.push(std::fs::read_to_string(proof).unwrap());

let mut public = args.input_dir.clone();
public.extend(vec![format!("public{}.json", i + 1)]);
public_signals.push(std::fs::read_to_string(public).unwrap());
});

let vk: VerifyingKey<Bn256> = serde_json::from_str(vk.as_str()).unwrap();
let public_signals = public_signals
.iter()
.map(|public_signals| serde_json::from_str::<PublicSignals<Fr>>(public_signals).unwrap())
.collect_vec();
let proofs = proofs
.iter()
.map(|proof| serde_json::from_str::<Proof<Bn256>>(proof).unwrap())
.collect_vec();

// building circuit
let circuit = Accumulation::new(vk, public_signals, proofs);

let mock_prover = MockProver::run(21, &circuit, vec![circuit.instances.clone()]).unwrap();
mock_prover.assert_satisfied();
}

// fn main() {
// let params = gen_srs(21);
56 changes: 56 additions & 0 deletions maze-cli/testdata/proof1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"A": [
"11061059603189782590330418259165078776630514368672082688811243104044860101540",
"21668757428762543016671135403653337903225051298789513367270755978051709738572",
"1"
],
"B": [
"15086270057259696475553262311245448542212613657734428927573100611839505480405",
"15018511197851761273177786510821312288823130543628495195956277770824042190722",
"1"
],
"C": [
"14972338772264545077554193622334454585886430717733475952116247858333029051612",
"18054617390851292490340784872096307735301268676836314087254309676459499099352",
"1"
],
"Z": [
"14382338141451024608292942544807617949449861494221150754991236959826838416669",
"10385796778063295246729293672521215747529662283495782347357027111939539405273",
"1"
],
"T1": [
"12751261278277586544140220350597873383550169238072927910121553847855318517163",
"10945599048902805478868261214279777223927364741842524822724265316476458100695",
"1"
],
"T2": [
"5973795993600689757811815813854288461127743059999624555641758467641758046626",
"8726815948989040187593929257900012211722987404525002145019657362525782979044",
"1"
],
"T3": [
"21072089102306420569765505555148563215048857791981467046074242987486533089930",
"17535943633965333368863208309663816996221234488938464214457981145265544794225",
"1"
],
"eval_a": "19726214196348323683839603021032263816939421240984180066385077192452675481471",
"eval_b": "2333267538690138233648092707823188338618694351416835528648245962758838356337",
"eval_c": "10971899192792562347132356007458724596801409552494366719278016565035749074651",
"eval_s1": "6159818742975066475291358495938614244240245684888756593045209785852937729279",
"eval_s2": "15197205121556034064086123849398780541310753223034430556904169800753100031633",
"eval_zw": "5530376799911596881715592680894011517238842016192161340525184837122297439950",
"eval_r": "19659936227615256346904535692177058613252049032763580820688462126145909608495",
"Wxi": [
"6740641879457334845854395780205816355956771529536935615443431702468550162214",
"21183255617191143724097347727344457324556551775846802887934369815266291584190",
"1"
],
"Wxiw": [
"21335840114976920556842587201078357495072120383201015684328760344203390789325",
"8096904663846811709871156788274714302796579221932332607896751009422510513707",
"1"
],
"protocol": "plonk",
"curve": "bn128"
}
56 changes: 56 additions & 0 deletions maze-cli/testdata/proof2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"A": [
"18557919750987021662789729515107849827489087218915945805083138342267094304069",
"905132736063861827135012958416653462937915728725596025851402389152738938984",
"1"
],
"B": [
"16745291603031414963102184752002564190615870609183577935000834227706624205813",
"17808793187825541732893545349077855124782193483585527391550381972308154929634",
"1"
],
"C": [
"8229817382076001513448484464902656165695833231742557449507687858778609418470",
"18191822339695029088256876645333932112536644350224285253064314166304831383536",
"1"
],
"Z": [
"9505186012120395566352035333983963251769344959182929679047732995428191242861",
"11177258260422078059955740361456986234166742731641437768783756775564498383203",
"1"
],
"T1": [
"7898884255941828713659723265121622087697055841930076063904367637338289819439",
"16946083805146156803561845866155732046864907931648741811003075463148803556295",
"1"
],
"T2": [
"12238478250706660929949506202301899777614019881533995980501590875196399868461",
"15767260934784196857478979667792666928148412036367069453359384091402079446906",
"1"
],
"T3": [
"12575578657680774514839438896860867204364882877501527498510232176041652420775",
"830986643960982029526419221577216568100541311560380146586899689118389679797",
"1"
],
"eval_a": "3401472054706128119779068941209727798059443648351540360543019835435223635345",
"eval_b": "18485471893262667776821071373423007634745067950568763836587646973471241017094",
"eval_c": "18328310607202052258583298685346218527820932102603627306530914531545533940126",
"eval_s1": "10601899109180794584299488925405322494100904557730776713230589811436330838434",
"eval_s2": "17986370718649072841716658598000564453741411490269838211573603656003235039001",
"eval_zw": "1911511887475020829021904719505427242304728264359848946516519855666069855218",
"eval_r": "13644884437865111035828905767228430580540982352417763898229321171101079783852",
"Wxi": [
"12138007777634003786786436996224034369301029714948862620492158469056098103476",
"20373562335465211178242028739833303134193937365524766196749114251341277345812",
"1"
],
"Wxiw": [
"3154245644827768953242932946211119055288741567415542891389956651903617976817",
"5375713734703869448763658151597042055598546208909952971007574880546564439058",
"1"
],
"protocol": "plonk",
"curve": "bn128"
}
3 changes: 3 additions & 0 deletions maze-cli/testdata/public1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"16071293540883839718875621424443923800287184249862748659884745950088030321914"
]
3 changes: 3 additions & 0 deletions maze-cli/testdata/public2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"18867351787238931737636874224083095280341863992090348121226613508690509506910"
]
63 changes: 63 additions & 0 deletions maze-cli/testdata/verification_key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"protocol": "plonk",
"curve": "bn128",
"nPublic": 1,
"power": 11,
"k1": "2",
"k2": "3",
"Qm": [
"3349529800503134758031206628826762579744090389775720856324415703418132588272",
"1047380119467254909383032258743707561779783672376181143324721807183433895005",
"1"
],
"Ql": [
"7767045214241100521202624210544067470568603896753786311669908116745944438330",
"2761503195407699512821418421837091792920914786423811892261268458108417046825",
"1"
],
"Qr": [
"2975170524298576570303711212258436671762476108775473882749069044845953535499",
"14378372896685219137765897674012660076935852372658477152445798047040143090024",
"1"
],
"Qo": [
"9954726969673494279518385350127630762618300791674628690913856164268433703179",
"13965759471775973075363285410020114951590804896282136534205026646287563189772",
"1"
],
"Qc": [
"16212144331199537797769995963505212438301349409393139691774264125327619032439",
"17085616814509624070169907909376975087673229154027196667482507285696043222953",
"1"
],
"S1": [
"21427438936074527438404157582664231491469818071679458860143386701810092744404",
"19911030453621062116641782598975750504385985365438849435660556532368164383429",
"1"
],
"S2": [
"13802677720850567775992768839702562890586195816216161661887530587428202866726",
"7079192343351352262490439774376827531848577755489091121777421558213991392309",
"1"
],
"S3": [
"7382434879293711723612677553350129386486281744510841088538187725327021521690",
"11862269561183216572203078221388721953182973401672938240744501637694249454749",
"1"
],
"X_2": [
[
"17697945884356840746175007528786997911945651836283409056261355173034919217326",
"11501088178268619001213046246621713845912613526390023569108826835703460118408"
],
[
"2426853463090583396092113656235496011757344467781401934015976708559998134240",
"18934756257331934407911971941197693338781042972388885568003065304450754441155"
],
[
"1",
"0"
]
],
"w": "1120550406532664055539694724667294622065367841900378087843176726913374367458"
}

0 comments on commit 3ad21d8

Please sign in to comment.