Skip to content

Commit 94d7a22

Browse files
committedNov 14, 2023
feat: Groth validation
1 parent ba921d3 commit 94d7a22

File tree

6 files changed

+207
-5
lines changed

6 files changed

+207
-5
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*~
22
dist-newstyle/
3+
cabal.project.local
4+
.vscode

‎groth-pairing.cabal

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cabal-version: 2.4
1+
cabal-version: 3.6
22
name: groth-pairing
33
version: 0.1.0.0
44
synopsis: Elliptic curve pairing.
@@ -20,14 +20,14 @@ category: ZKP
2020
extra-source-files: CHANGELOG.md
2121

2222
library
23-
exposed-modules: BLS12381, BN128, Utils, MyLib
23+
exposed-modules: BLS12381, BN128, Utils, MyLib, Groth16.Proof
2424

2525
-- Modules included in this library but not exported.
2626
-- other-modules:
2727

2828
-- LANGUAGE extensions used by modules in this package.
2929
-- other-extensions:
30-
build-depends: base ^>=4.14.3.0
30+
build-depends: base ^>=4.17.2.0
3131
hs-source-dirs: src
3232
default-language: Haskell2010
3333

@@ -40,7 +40,7 @@ executable pairing
4040
-- LANGUAGE extensions used by modules in this package.
4141
-- other-extensions:
4242
build-depends:
43-
base ^>=4.14.3.0,
43+
base ^>=4.17.2.0,
4444
groth-pairing
4545

4646
hs-source-dirs: app
@@ -51,4 +51,4 @@ test-suite pairing-test
5151
type: exitcode-stdio-1.0
5252
hs-source-dirs: test
5353
main-is: MyLibTest.hs
54-
build-depends: base ^>=4.14.3.0
54+
build-depends: base ^>=4.17.2.0

‎hie.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cradle:
2+
cabal:

‎src/Groth16/Proof.hs

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
module Groth16.Proof where
2+
import Data.Maybe (fromJust)
3+
import GHC.Exception (fromCallSiteList, ratioZeroDenomException)
4+
import BLS12381 (Fp1 (..), Fp12 (..), Fp2 (..), Fp6 (..),
5+
G1, G2, EllipticCurve (..), ecExp, pairing)
6+
7+
8+
piA :: G1
9+
piA = EC (Fp1 3984352275393513407707458752223381552625938981874722736014424587477519416324786265219287577738019481427124666148577)
10+
(Fp1 3934357811246215342496484974341718744307142950543561986855369767107187586719026787540296884547368402577497158247886)
11+
piB :: G2
12+
piB = EC (Fp2 1383768228561621316627203185691386271068632930515025058311040033286484194936249393773572848513907248314714565823954
13+
3372051825839361802267191902926554912410385994757553252424676676340216183130863424210420817445471978026226922337833)
14+
(Fp2 173769527298906309724813645384929913748747002524984682791528623242175734184686578339273192650865422687981596071356
15+
1221155903482790553508449256524896113531260560029665446099564785219231367859438371011146458551163658702696619239964)
16+
17+
18+
eAB :: Fp12
19+
eAB = pairing piA piB
20+
21+
vkAlpha :: G1
22+
vkAlpha = EC (Fp1 884254335835973708623649726843225902515012882730292989362595689678679572079921231771317068170806996078338505579806)
23+
(Fp1 3768977299080966250688020815019979226470712404975382082543343112954422303817680439779613820354767573782934373316440)
24+
25+
vkBeta :: G2
26+
vkBeta = EC (Fp2 2720547088220552322101421658501053569361804801106447169991638985241299183616270020289525175877218022943839744678186
27+
2801315382036359271580184551867838805765997071063520052931583554992307693827563040347593044852696020880400403800183)
28+
29+
(Fp2 770284704932965497202598239706215866847979347767071358071158374227966578813392253003771174891535118568391181236317
30+
1139019368208251015845183620656622771874508938093356438887657395609394230231468860652936479057193953006987748576783)
31+
32+
eAlphBeta :: Fp12
33+
eAlphBeta = pairing vkAlpha vkBeta
34+
35+
vkI0 :: G1
36+
vkI0 = EC (Fp1 1543158387756368305682640577732972437006142138783149846616634502202298429897559731463273773655375040974203537466722)
37+
(Fp1 2088673663149159531424996367136503441740704070304009602411162415476128434508623983231292593704123869519078025433851)
38+
39+
vkI1 :: G1
40+
vkI1 = EC (Fp1 3379779854616555326463337240069717300537103481222871647422326726751131356695553710288272264490199347961045579814992)
41+
(Fp1 3148331474212877925196015078803050368886350560299501354135811263836671051022075420732464407909524101161401693824468)
42+
43+
vkI :: G1
44+
vkI = vkI0 <> ecExp vkI1 168932
45+
46+
vkGamma :: G2
47+
vkGamma = EC (Fp2 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758
48+
352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160)
49+
50+
(Fp2 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582
51+
1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905)
52+
53+
eIGamma :: Fp12
54+
eIGamma = pairing vkI vkGamma
55+
56+
57+
piC :: G1
58+
piC = EC (Fp1 2760002180549978667072186956156037192766725652969953377981440820425053248045665685727157004083291821437533086232223)
59+
(Fp1 1418798878631376940395924303249345283900683995745178488269207401399355667366482245751366473765081910834806927478837)
60+
61+
vkDelta :: G2
62+
vkDelta = EC (Fp2 1141849674709460885091515179048158257162912866718788931520718365807686518957690229971427646803968066456032635732114
63+
3653817707682780481400988959837792884813139044060691250486309066732559611975172107961595508869522546031232689129662)
64+
65+
(Fp2 426945487787332816931873177136288041913449245111552392246454628501530427951336241004199984406283998396003691442915
66+
2540492032915892247569545602749267035529833466265680663689342492623743591035104699497312141136821058026929128894073)
67+
68+
eCDelta :: Fp12
69+
eCDelta = pairing piC vkDelta
70+
71+
72+
lhs :: Fp12
73+
lhs = eAlphBeta * eIGamma * eCDelta
74+
75+
proof :: Bool
76+
proof = lhs == eAB

‎src/Groth16/proof.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"pi_a": [
3+
"3984352275393513407707458752223381552625938981874722736014424587477519416324786265219287577738019481427124666148577",
4+
"3934357811246215342496484974341718744307142950543561986855369767107187586719026787540296884547368402577497158247886",
5+
"1"
6+
],
7+
"pi_b": [
8+
[
9+
"3372051825839361802267191902926554912410385994757553252424676676340216183130863424210420817445471978026226922337833",
10+
"1383768228561621316627203185691386271068632930515025058311040033286484194936249393773572848513907248314714565823954"
11+
],
12+
[
13+
"1221155903482790553508449256524896113531260560029665446099564785219231367859438371011146458551163658702696619239964",
14+
"173769527298906309724813645384929913748747002524984682791528623242175734184686578339273192650865422687981596071356"
15+
],
16+
[
17+
"1",
18+
"0"
19+
]
20+
],
21+
"pi_c": [
22+
"2760002180549978667072186956156037192766725652969953377981440820425053248045665685727157004083291821437533086232223",
23+
"1418798878631376940395924303249345283900683995745178488269207401399355667366482245751366473765081910834806927478837",
24+
"1"
25+
],
26+
"protocol": "groth16",
27+
"curve": "bls12381"
28+
}

‎src/Groth16/verification_key.json

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"protocol": "groth16",
3+
"curve": "bls12381",
4+
"nPublic": 1,
5+
"vk_alpha_1": [
6+
"884254335835973708623649726843225902515012882730292989362595689678679572079921231771317068170806996078338505579806",
7+
"3768977299080966250688020815019979226470712404975382082543343112954422303817680439779613820354767573782934373316440",
8+
"1"
9+
],
10+
"vk_beta_2": [
11+
[
12+
"2801315382036359271580184551867838805765997071063520052931583554992307693827563040347593044852696020880400403800183",
13+
"2720547088220552322101421658501053569361804801106447169991638985241299183616270020289525175877218022943839744678186"
14+
],
15+
[
16+
"1139019368208251015845183620656622771874508938093356438887657395609394230231468860652936479057193953006987748576783",
17+
"770284704932965497202598239706215866847979347767071358071158374227966578813392253003771174891535118568391181236317"
18+
],
19+
[
20+
"1",
21+
"0"
22+
]
23+
],
24+
"vk_gamma_2": [
25+
[
26+
"352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160",
27+
"3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758"
28+
],
29+
[
30+
"1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905",
31+
"927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582"
32+
],
33+
[
34+
"1",
35+
"0"
36+
]
37+
],
38+
"vk_delta_2": [
39+
[
40+
"3653817707682780481400988959837792884813139044060691250486309066732559611975172107961595508869522546031232689129662",
41+
"1141849674709460885091515179048158257162912866718788931520718365807686518957690229971427646803968066456032635732114"
42+
],
43+
[
44+
"2540492032915892247569545602749267035529833466265680663689342492623743591035104699497312141136821058026929128894073",
45+
"426945487787332816931873177136288041913449245111552392246454628501530427951336241004199984406283998396003691442915"
46+
],
47+
[
48+
"1",
49+
"0"
50+
]
51+
],
52+
"vk_alphabeta_12": [
53+
[
54+
[
55+
"2537157174758535239693887740369820268060806319913514466421451213792336528690711787806246616105877796005556197045237",
56+
"883378670067415217798045985778103534888650261678820370794039697198204061032982518787590732837490792265896961210936"
57+
],
58+
[
59+
"940833566247149475592932896090684843399451614601365116211428746346859022944441098839686347029312043134621249946820",
60+
"752105595486331341406807746645401371655632697445633012750799115305427219875936412685034425161125505540557146841329"
61+
],
62+
[
63+
"902294703114244060933220743503504820389129726504260173187711817029860908659919662455641437771424551793483524647972",
64+
"250471782684582064614893516199777234846494055030401339738865210308536984559840241975157303374353240246073887943832"
65+
]
66+
],
67+
[
68+
[
69+
"1574575288642293366261504254453625953119720036728568897880245263509254818812371424838473250909880199535868328316185",
70+
"1173301574920314051361980042948006405466067210894027378181282872111012956412191109529067748549913783368439395693674"
71+
],
72+
[
73+
"2944216868096403493012574028955084022605365319967421529101315214044552284092817475153229507466504929697959359978453",
74+
"3125513049273860695775929839977281060275575070445046576353167792735193670388367123732191353056001728886742365693518"
75+
],
76+
[
77+
"1587577397770624194143398909090243026714839353667474438476576520625273192428442825134758160583667205565257436592077",
78+
"1604652939710957270663679780930562112760366381499407288427693783493107987989044301388377966230353002914987867970499"
79+
]
80+
]
81+
],
82+
"IC": [
83+
[
84+
"1543158387756368305682640577732972437006142138783149846616634502202298429897559731463273773655375040974203537466722",
85+
"2088673663149159531424996367136503441740704070304009602411162415476128434508623983231292593704123869519078025433851",
86+
"1"
87+
],
88+
[
89+
"3379779854616555326463337240069717300537103481222871647422326726751131356695553710288272264490199347961045579814992",
90+
"3148331474212877925196015078803050368886350560299501354135811263836671051022075420732464407909524101161401693824468",
91+
"1"
92+
]
93+
]
94+
}

0 commit comments

Comments
 (0)
Please sign in to comment.