Skip to content

Commit ed1fa52

Browse files
authored
feat: export groth16 (#289)
* feat: export groth16 * feat: export groth16 * feat: export groth16 * feat: export groth16
1 parent 4beb9a4 commit ed1fa52

File tree

10 files changed

+103
-79
lines changed

10 files changed

+103
-79
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

recursion-gnark/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Convert the Gnark Groth16 proof over BN254 to ArkWorks Groth16 over BLS12381
55

66
## E2E test
77

8-
```
8+
```bash
99
cd cli
10-
cargo run -r test --system groth16 ../ffi/data/ ../ffi/data/proof.bin
10+
cargo run -r test --system groth16 --vk-path ../ffi/data/groth16_vk.bin --output-dir ../ffi/data --proof-path ../ffi/data/proof.bin
1111

1212
cd ffi
1313
cargo test -r

recursion-gnark/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ recursion-gnark-ffi = { path = "../ffi" }
99
clap = { version = "4.5.9", features = ["derive"] }
1010
bincode = "1.3.3"
1111
hex = "*"
12+
serde_json = "1.0.140"

recursion-gnark/cli/src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A simple CLI that wraps the gnark-ffi crate. This is called using Docker in gnark-ffi when the
22
//! native feature is disabled.
33
4-
use recursion_gnark_ffi::ffi::test;
4+
use recursion_gnark_ffi::ffi::build_groth16;
55

66
use clap::{Args, Parser, Subcommand};
77
use std::fs::File;
@@ -19,7 +19,11 @@ enum Command {
1919

2020
#[derive(Debug, Args)]
2121
struct TestArgs {
22-
data_dir: String,
22+
#[arg(short, long)]
23+
output_dir: String,
24+
#[arg(short, long)]
25+
vk_path: String,
26+
#[arg(short, long)]
2327
proof_path: String,
2428
#[arg(short, long)]
2529
system: String,
@@ -30,9 +34,13 @@ fn run_test(args: TestArgs) {
3034
let proof: recursion_gnark_ffi::Groth16Bn254Proof =
3135
bincode::deserialize_from(&mut file).expect("Failed to deserialize proof");
3236

37+
let public_input = serde_json::to_string(&proof.public_inputs).unwrap();
38+
3339
match args.system.as_str() {
3440
"plonk" => panic!("Unsupported system: {} or mismatched proof type", args.system),
35-
"groth16" => test(&args.data_dir, &proof.raw_proof),
41+
"groth16" => {
42+
build_groth16(&args.vk_path, &args.output_dir, &proof.raw_proof, &public_input)
43+
}
3644
_ => panic!("Unsupported system: {} or mismatched proof type", args.system),
3745
};
3846
}

recursion-gnark/ffi/data/groth16_vk_bls12381.json

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"curve": "bls12381",
44
"nPublic": 8,
55
"vk_alpha_1": [
6-
"284790626402138102544809744043020292682321694691200076291426364669421311674010082482656278484516959461501662842388",
7-
"1071040838313703974941269431559034788128463719346440723732748251009726633344319411261116985530618838591245477994989",
6+
"2681542168979724822142175221869242139042422794877557524293417725544033894627648072439835898097075335306953868174669",
7+
"1859872180673648233787021782295918469114774526108737238162040815867894938212292641772412868023573728813280486124231",
88
"1"
99
],
1010
"vk_beta_2": [
1111
[
12-
"466821508400785082872743362764300226357092918774014912705032660208454116510209268269885220035173992362938114737758",
13-
"865540270584771222442852920387447818916778189792259954132330825479960785878564406399486642293777210959296446546860"
12+
"2102709065771884964361790601311452048338411677698010331017927743702691936265256343659149038218902817230247675604822",
13+
"1299777871922323415698583969900746996406989828573914662281542123349637938665886753244623653136127454356193233796177"
1414
],
1515
[
16-
"2525830431385835575638083054651498378173492475717711587911672368197425186547352872756572267038104260850077076802005",
17-
"1719063393064016661812487295550967887394928433964402944452474740461878108902418261139531778515125740295323983300116"
16+
"3422537085981738727980396724252877745599392331714679438370477011296494454681783740478361373466071715954799137635811",
17+
"2490227739190106724738622223405195630779049436991821942733030805655630815434044853063479686260329843522155973458417"
1818
],
1919
[
2020
"1",
@@ -23,12 +23,12 @@
2323
],
2424
"vk_gamma_2": [
2525
[
26-
"3176734825284605057882066740462729143412495390147257615142557621379900240289947223476145986679303159939503062083764",
27-
"1133440769548266757383124777780779641713836672615651370618507329969983218291289676635016995179426028569876893675361"
26+
"2834183671509146882853840050643533385697496823382195465855127919157513248473842038883849737448025665460980974461069",
27+
"3529983679585561977615803006069964431941990645867119628691674810393234812516797241655213887008788150395100143929696"
2828
],
2929
[
30-
"3612489851202409734955256743975948485504189772480253363685640440129847004677552142311224201879262812420314888898496",
31-
"314441640746756155125000203157990945428259086303351347035838044906131230135366246682487075293563107746536490615609"
30+
"1299987619280279588482554174879113397536855138335507970838726527336212483236468538861714501736460038652442244739877",
31+
"1200059419713703392869118167186716557367025460552927172825842196107536695582588638572182080191110814868086322350733"
3232
],
3333
[
3434
"1",
@@ -37,12 +37,12 @@
3737
],
3838
"vk_delta_2": [
3939
[
40-
"1372244872659588528568213891695838299627894436688205563549078344505026980674768430641602645373941021652105749221471",
41-
"2649673321022157447899384391013519475888726518573337604143251743135267442892328413009236612329179764204879395994409"
40+
"2467348540608840376317606948799885677565153256620913619548736968304097594592100774399678538272953415017431862569920",
41+
"223231336832895576882071945911549539169142885829329511678228625277439067100050757877662933800150338895349435582369"
4242
],
4343
[
44-
"166209811661774558512760521887176325332239346683381266161174907878167022390687296366825847998708484891418293199232",
45-
"3555508828554433102270131395324841845793008119608507920364205594826168265149180910598159529028830282429418315894783"
44+
"1647670777292075892887001637071937780994250677139136508152582089795085539079732356607301227764492604215036370418949",
45+
"2337756248061112969064448396670114848190538202540070354782428288256392354888694222721311707393160662041271784472101"
4646
],
4747
[
4848
"1",
@@ -51,83 +51,83 @@
5151
],
5252
"IC": [
5353
[
54-
"3317870962199580219799360882780783900513799217976269301913927949142301595802262837300990141081062409621205013689318",
55-
"3131950041991045806694632897919636143160965864746424033276343505834210781147800612649348254284769619390173649672873",
54+
"3781626542945757019101221727936750693210170197546371204267700444090505006216926051004465122827357339686004297458193",
55+
"71985904437544583553271652259569382720539530998269578132508773703910334354165155796445752838776473597788629028615",
5656
"1"
5757
],
5858
[
59-
"986444082018678596715090153153811598406686480325959512141861110854914046939125185370965673376624108446518275131311",
60-
"3053263293035148126136006873214135263157196395186458680474271176025492432177657674423866973268771547554883884160821",
59+
"326112404284686405036082707909350463409195068468226243576886155827764933554980772271873910810558826849493110204325",
60+
"2942981964754034785537347160832895993418000253897937365104405975883174606547420787478471252257704313165735145315056",
6161
"1"
6262
],
6363
[
64-
"2036990761741975219372746944501652189631179108441327432556370526744445387158466249243377183651262073856952768908755",
65-
"108755733025821382751898721463990540020414979958160250259825822385243696246336162719724840250637762975942674248933",
64+
"2416391392157134590091987601213979619355824445503600451125666983152290947612007287957683798082138701266087437534374",
65+
"502513764159850513961096956968051209232178869043673022811636942796105030006543552819340625891368077473070631527512",
6666
"1"
6767
],
6868
[
69-
"3577321758878643233588012256809890723309069389197066750963010105805327179126889728296641104683553336364999578827334",
70-
"3866700329680809242964113485324810901388322460231939735697513758710102464796526479729132485614837136854984444543975",
69+
"3590482281221109797212164524611935481203502273447429092274508800759750236096161917148372936071517430395723472470305",
70+
"3039759225293174244940487814149024543442319327100233428634812048564864784231051857184427246565422723826786284001948",
7171
"1"
7272
],
7373
[
74-
"928904866195286502303331351292302744359970849826700948239220662551950782267535809378168213928865606034033370666999",
75-
"2240069625396846219052612202431605510624259447787721972339593030110053087829660199434778099344021002455549063291075",
74+
"1613021043133409072818339634408481002290936126694278031502085053360139968915105228638868367157698369122328806166483",
75+
"975376066136915637948094970626183002405329672192063911208248622661869554739831971658784766476744623576091432961172",
7676
"1"
7777
],
7878
[
79-
"966122928992161406971353012038124291750281681181537931562280866570021073524932744739027186910926869317180903968281",
80-
"2769360536433457510568688774995026283712573631760659429504769004123423082697747904909904623697327069664281326439423",
79+
"519647895655469672934492178339425063168106139369922859819968153837726928257862124329675622628735258453117909915436",
80+
"3477082187144345717389985070190045938417766778799433402703332078237972917312254091152279005354570550707020940956375",
8181
"1"
8282
],
8383
[
84-
"3533110157957092193664378231424866183131278839969296466229198455043202712864519232836834845029386482959810407504548",
85-
"2711898619976546533110900772274730945299698529421115344737769555801569986918172227342284841321484010238295736288556",
84+
"294523212544951131935462204051238808824662025024020893596361355171801871369808517418945659674767464628025141202705",
85+
"1151543398005096141280695280451690682320503361884199434197647822412008776734306014440488627653713784163874324904607",
8686
"1"
8787
],
8888
[
89-
"287583337187576690710769617235374115851893579628156919055837825155468991489667731652401957242465676180734850714525",
90-
"950214367268433031704590299965550464079054608063623953117404591105220935097928523341268830007800981771002982248012",
89+
"3305920888419756584715487307760757049538411207775531351713745579789357599026586315840998167876557946606758838177987",
90+
"2961766819532801296099534137857377304522637237446899109888828889188631975926895010117330720623988755383288879599425",
9191
"1"
9292
],
9393
[
94-
"2947194038654703600230793534617245045914984234543919270056942052891887661069162764015710510407828502514702288907613",
95-
"1993685152364878122710353900510746079547012689243672094800601558787134239664555086093753912640308711058335402674203",
94+
"2331366111503016742881472153729005006757772365476308102431181806710659442419402109332141782983029722980310570449682",
95+
"643309021429917831798895897065448812162206104099860123634189414209737426438718080938417235729025227913091126757945",
9696
"1"
9797
],
9898
[
99-
"353427706286625166846309150610015058601347371846183947987893371732439382124660698930454758550884256067588302868477",
100-
"665850952700138549937511778315265951615493169011884839727598511743089302590117929215685436733780055039318495688028",
99+
"933820797736095697765281918908617490588293029273872036940692026990864049162191586753168921607149338531526983070045",
100+
"1926570206663148042772862610460679029657513353550644738256794759485862155176184497295704810164212038236064954165567",
101101
"1"
102102
]
103103
],
104104
"vk_alphabeta_12": [
105105
[
106106
[
107-
"2368281456765728580239495840556335542949183357658068990337066958016795747400086782945812514435266934207360340050202",
108-
"1491436296702041430694284776327227460841213299121532419618695790786948500849884787755839269776867508077953526218438"
107+
"155863352589595411197563153383314084139144741167328717365466979464126660144144493216445021325676428610877494459589",
108+
"1126730698990536858214284359769476081119770420179775245091823903402784694688694658248056246440698558911645775758456"
109109
],
110110
[
111-
"2208426842509314074946183122639253587935044503624088944329547337899895406378026874705163305534599359287178105122173",
112-
"3792346171276356864025824554588667041726521210576066777595300532974377475710014922102394295415409586793664413362765"
111+
"3430302453588505191613328604182335767357745295713480432134952155646961409402314556057783405411842588174201899166879",
112+
"1112607421272553451136359344183865334620272891306549800269958522926425145703171562078338891180405848534303055938554"
113113
],
114114
[
115-
"3467897114719868018142111749823717712537230391724722235627155527741235059013840851237825633805572713885360433473280",
116-
"1636774677152821765449233841413063061124036095406968652296911485921929462091666470132115884192296322489822807760395"
115+
"1361536037583104895431961775573414500282854767587074314406283810774097756356097117687769071454374460401629884761373",
116+
"3163972151675551722292083771466254557985427161691147371032089872977284578328473116172020486004820381220162889333496"
117117
]
118118
],
119119
[
120120
[
121-
"2869430956416926925205414101696507180851520165566447573456571053298784069519842504335088445360447858389524675613434",
122-
"1182025582438281620124274959335338018132810138531152578845837815690044710191556988659292271463183214665220423488566"
121+
"3652934816727248537990226198309149306001122733955933263956238967147124887981197759999383421563539014213847600570999",
122+
"3376599583571807826520342305157383842365649611383079616753608747788322163715464121463682067082700448495804230906255"
123123
],
124124
[
125-
"208017364808085454743851469721737601321492928744083668711051112161703486881967542353672832560116246011378237121202",
126-
"910960910781191577985633199937403012858478832684720122957729643313885201881670808057125910871304265250612670302370"
125+
"2541259117891335006036186330154057884113698866080868699211794882975483107712032568137104366733487687280935285562829",
126+
"1853412821473682407438192275986169920645580125875767840734263805357529354561321046697760220830879925745118778339140"
127127
],
128128
[
129-
"173693374081853054762431750088609067707150372290999555062163345344076189195418775825243720365394067626585665775295",
130-
"3052458445169642069085426348171435873566983741339202806851076211242702740746107311834211487894068749357934167958709"
129+
"631634847635790626850598384851331945843308392574207753031775042986318937230285246049375378176016409169485837266192",
130+
"2631329524641977060598796809348453731160509232968333547987972420323969631160347450971441410379214241115843875582191"
131131
]
132132
]
133133
]

recursion-gnark/ffi/data/proof_bls12381.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
22
"pi_a": [
3-
"1940263214629735212508098607781712625397253060024854489283139556169077492114479032825543351267082357299131674497922",
4-
"2619060241184431939357580121279474560697645633629344613192690532090607485494358197414694290380367875005803760857288",
3+
"2023121272951426315039901698353037047817897983687242982797055439451647922624815274135045441005751062523987277129977",
4+
"3863328116787753116043442233320350950091873839700941923187210525853570598684023525820694042434181487858794217495886",
55
"1"
66
],
77
"pi_b": [
88
[
9-
"1882601953269844650715439924140794470936306116387058564773659052370363955419889184790476376929515419583667878293854",
10-
"3266034465973981339144904777977939955340044854774347711761256847557435847098654634965237811452638121267017904557572"
9+
"581703759686924712720064086837769589808366286174410783560263131206817530285642856655108060227182088496559185131665",
10+
"3311997253402999658936153582365660573543282228220406662655585132991857064825049910369513199817023580493442960953049"
1111
],
1212
[
13-
"3957284676673343846382800767038269871012491494084960115998377020651608911906574782390491071353285109220716984291251",
14-
"527820883107100381517429176815260635617494391382930923243221852731903371161824947436511300449284105878532944387642"
13+
"2671838232050712139587044324594232569111868732434818207285897328400928131678502332595237473105301764404903066266668",
14+
"2957792508511823469315608930217100635807862942554499367945113167330650062262316616887173890473045768549132095907240"
1515
],
1616
[
1717
"1",
1818
"0"
1919
]
2020
],
2121
"pi_c": [
22-
"591534238438112497785839696235498310821886153407028469846945855047299687039546696478969488100637730056641120188790",
23-
"629684770113023172843592205045535353342362806487019975233306557583781688004528784784814161959444418830390840431849",
22+
"993465835737908994149108560056715459070949583308042707968055537541147555364343402556628116254709672035437284622061",
23+
"3796716515682349684420629021674565351253118942718064061819490821315998853404819934181887143550501318622359389913816",
2424
"1"
2525
],
2626
"protocol": "groth16",

recursion-gnark/ffi/go/eigen/build.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"encoding/hex"
66
"encoding/json"
7-
"fmt"
87
"log"
98
"os"
109
"sync"
@@ -21,7 +20,7 @@ var globalR1csInitialized = false
2120
var globalPk groth16.ProvingKey = groth16.NewProvingKey(ecc.BN254)
2221
var globalPkInitialized = false
2322

24-
func BuildGroth16(dataDir string, verifyCmdProof string) {
23+
func BuildGroth16(vk_path string, outputDir string, verifyCmdProof string, publicInput string) {
2524
// Load proof
2625
proofDecodedBytes, err := hex.DecodeString(verifyCmdProof)
2726
if err != nil {
@@ -37,7 +36,7 @@ func BuildGroth16(dataDir string, verifyCmdProof string) {
3736
}
3837

3938
// Load vkey
40-
vkFile, err := os.Open(fmt.Sprintf("%s/groth16_vk.bin", dataDir))
39+
vkFile, err := os.Open(vk_path)
4140
if err != nil {
4241
panic(err)
4342
}
@@ -49,11 +48,7 @@ func BuildGroth16(dataDir string, verifyCmdProof string) {
4948
}
5049

5150
// Load public signals
52-
publicSignalsData, err := os.ReadFile(fmt.Sprintf("%s/public_inputs.json", dataDir))
53-
if err != nil {
54-
log.Fatalf("failed to read public signals: %v", err)
55-
}
56-
publicSignals, err := UnmarshalPublicSignalsJSON(publicSignalsData)
51+
publicSignals, err := UnmarshalPublicSignalsJSON([]byte(publicInput))
5752
if err != nil {
5853
log.Fatalf("failed to unmarshal public signals: %v", err)
5954
}
@@ -78,23 +73,23 @@ func BuildGroth16(dataDir string, verifyCmdProof string) {
7873
if err != nil {
7974
log.Fatalf("failed to marshal proof: %v", err)
8075
}
81-
if err := os.WriteFile(dataDir+"/proof_bls12381.json", data, 0644); err != nil {
76+
if err := os.WriteFile(outputDir + "/proof_bls12381.json", data, 0644); err != nil {
8277
log.Fatalf("failed to write proof: %v", err)
8378
}
8479
// Write the verifier key.
8580
data, err = json.MarshalIndent(blsVk, "", " ")
8681
if err != nil {
8782
log.Fatalf("failed to marshal verification key: %v", err)
8883
}
89-
if err := os.WriteFile(dataDir+"/groth16_vk_bls12381.json", data, 0644); err != nil {
84+
if err := os.WriteFile(outputDir + "/groth16_vk_bls12381.json", data, 0644); err != nil {
9085
log.Fatalf("failed to write verification key: %v", err)
9186
}
9287
// Write the public inputs.
9388
data, err = json.MarshalIndent(blsPub, "", " ")
9489
if err != nil {
9590
log.Fatalf("failed to marshal public value: %v", err)
9691
}
97-
if err := os.WriteFile(dataDir+"/public_inputs_bls12381.json", data, 0644); err != nil {
92+
if err := os.WriteFile(outputDir + "/public_inputs_bls12381.json", data, 0644); err != nil {
9893
log.Fatalf("failed to write public value: %v", err)
9994
}
10095
}

recursion-gnark/ffi/go/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import (
1414
func main() {}
1515

1616
//export BuildGroth16
17-
func BuildGroth16(dataDir *C.char, proof *C.char) {
18-
dataDirString := C.GoString(dataDir)
17+
func BuildGroth16(vkPath *C.char, outputDir *C.char, proof *C.char, publicInputJson *C.char) {
18+
vkPathString := C.GoString(vkPath)
19+
outputDirString := C.GoString(outputDir)
1920
proofString := C.GoString(proof)
20-
eigen.BuildGroth16(dataDirString, proofString)
21+
publicInputJsonString := C.GoString(publicInputJson)
22+
eigen.BuildGroth16(vkPathString, outputDirString, proofString, publicInputJsonString)
2123
}
2224

2325
//export FreeString

0 commit comments

Comments
 (0)