Browse Source

Add Witness parser from json

ed255-patch-1
arnaucube 4 years ago
parent
commit
f942c8c157
3 changed files with 245 additions and 0 deletions
  1. +18
    -0
      parsers.go
  2. +221
    -0
      testdata/provingkey.json
  3. +6
    -0
      testdata/witness.json

+ 18
- 0
parsers.go

@ -33,6 +33,24 @@ type ProvingKeyString struct {
type WitnessString []string type WitnessString []string
func ParseWitness(wJson []byte) (Witness, error) {
var ws WitnessString
err := json.Unmarshal(wJson, &ws)
if err != nil {
return nil, err
}
var w Witness
for i := 0; i < len(ws); i++ {
bi, err := stringToBigInt(ws[i])
if err != nil {
return nil, err
}
w = append(w, bi)
}
return w, nil
}
func ParseProvingKey(pkJson []byte) (*ProvingKey, error) { func ParseProvingKey(pkJson []byte) (*ProvingKey, error) {
var pkStr ProvingKeyString var pkStr ProvingKeyString
err := json.Unmarshal(pkJson, &pkStr) err := json.Unmarshal(pkJson, &pkStr)

+ 221
- 0
testdata/provingkey.json

@ -0,0 +1,221 @@
{
"protocol": "groth",
"nVars": 4,
"nPublic": 1,
"domainBits": 2,
"domainSize": 4,
"polsA": [
{
"1": "1"
},
{
"2": "1"
},
{
"0": "21888242871839275222246405745257275088548364400416034343698204186575808495616"
},
{}
],
"polsB": [
{},
{},
{},
{
"0": "1"
}
],
"polsC": [
{},
{
"0": "21888242871839275222246405745257275088548364400416034343698204186575808495616"
},
{},
{}
],
"A": [
[
"16145916318196730299582072104388453231952213805668281741813587224450782397538",
"4434505318477484327659527264104806919103674231447634885054368605283938696207",
"1"
],
[
"10618406967550056457559358662746625591602641004174976323307214433994084907915",
"1843236360452735081347085412539192450068665510574800388201121698908391533923",
"1"
],
[
"1208972877970123411566574123860641832032384890981476033353526096830198333194",
"777503551507025252294438107100944741641946695980350712141258191590862204805",
"1"
],
[
"0",
"1",
"0"
]
],
"B1": [
[
"0",
"1",
"0"
],
[
"0",
"1",
"0"
],
[
"0",
"1",
"0"
],
[
"1208972877970123411566574123860641832032384890981476033353526096830198333194",
"21110739320332249969951967638156330347054364461317472950547779703054364003778",
"1"
]
],
"B2": [
[
[
"0",
"0"
],
[
"1",
"0"
],
[
"0",
"0"
]
],
[
[
"0",
"0"
],
[
"1",
"0"
],
[
"0",
"0"
]
],
[
[
"0",
"0"
],
[
"1",
"0"
],
[
"0",
"0"
]
],
[
[
"9283666785342556550467669770956850930982548182701254051508520248901282197973",
"11369378229277445316894458966429873744779877313900506577160370623273013178252"
],
[
"10625777544326349817513295021482494426101347915428005055375725845993157551870",
"21401790227434807639472120486932615400751346915707967674912972446672152512583"
],
[
"1",
"0"
]
]
],
"C": [
["0", "0", "0"],
["0", "0", "0"],
[
"18545397130363256321926549041639729743141431075318462370025152832852939073307",
"2616861286119881509516846668252666108741377487742351180864484963773522850295",
"1"
],
[
"2525636894222523143142808451978966577881491159416335121257094078801746645235",
"16535861715720884910945782094658684127457731006848459401043529763859412916301",
"1"
]
],
"vk_alfa_1": [
"16068200068882411629410035093795608526771554471937479213726134794660780102550",
"20501676791339890155108177259376873296876233680064261776170683533526889207340",
"1"
],
"vk_beta_1": [
"5365573823291502335794132193185274277974617763863996013954364593194136465016",
"11644349101388223784378896360832586557929271772024496470708905460439243894584",
"1"
],
"vk_delta_1": [
"15680151079584844532489259722917096938769907841931133291928746685613811358733",
"16784279394546603697881462850128771845781623009095957214568117820968443242506",
"1"
],
"vk_beta_2": [
[
"13973091636763944887728510851169742544309374663995476311690518173988838518856",
"12903946180439304546475897520537621821375470264150438270817301786763517825250"
],
[
"370374369234123593044872519351942112043402224488849374153134091815693350697",
"17423079115073430837335625309232513526393852743032331213038909731579295753224"
],
[
"1",
"0"
]
],
"vk_delta_2": [
[
"1192908377564945353343974763532707545526009748811618581810344379529229172159",
"10373868200341234689659697947697825014338252335089936445608341428888724327154"
],
[
"6258644116885726740914814071115026921733331135830050167672544002787860516536",
"2784479362505735918824286514153638713518597314121639212447411360814573899319"
],
[
"1",
"0"
]
],
"hExps": [
[
"1137454402546542017796495169973321459788661791339116580816039119135416491226",
"10581992627412174102808274058339351114019966039682644500297077873241797449624",
"1"
],
[
"3253811140290017934039655168718326971539049766532829948316663892796117200680",
"3496418280903365070403555364992889823060908616232765866481366503085657668823",
"1"
],
[
"7426424892372059053157891943364774187577620238460342150964457392480230669997",
"14261604113665464620229095737623968407326243628348811684313201927885047569756",
"1"
],
[
"14706800931196014592083141709960980909656368788497354451613143286705158867076",
"8321358240716309588423491516494287064322707776658072083979021495463106099808",
"1"
],
[
"21560594640856118286219580794351895174554979903538723611152363886530011848778",
"15512645592267656573910252616175869133748229079507420222439452334013754939136",
"1"
]
]
}

+ 6
- 0
testdata/witness.json

@ -0,0 +1,6 @@
[
"1",
"33",
"3",
"11"
]

Loading…
Cancel
Save