Skip to content

Commit

Permalink
Make groth16 VK/Proof parsers more genric
Browse files Browse the repository at this point in the history
  • Loading branch information
feltroidprime committed Aug 13, 2024
1 parent 1267943 commit 5917666
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 77 deletions.
6 changes: 4 additions & 2 deletions hydra/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ def find_value_in_string(s: str) -> int | None:
"""
Find the value of the curve ID in the string.
"""
if s.lower() == "bn128":
return CurveID.BN254
for member in CurveID:
if member.name.lower() in s.lower():
if s.lower() in member.name.lower():
return member.value
return None
raise ValueError(f"No curve found for {s}")

@staticmethod
def get_proving_system_curve(
Expand Down
37 changes: 37 additions & 0 deletions tests/starknet/test_vk_pk_parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

from tools.starknet.groth16_contract_generator.parsing_utils import (
Groth16Proof,
Groth16VerifyingKey,
)

PATH = "tools/starknet/groth16_contract_generator/examples"


@pytest.mark.parametrize(
"vk_path",
[
f"{PATH}/snarkjs_vk_bn254.json",
f"{PATH}/vk_bn254.json",
f"{PATH}/vk_bls.json",
],
)
def test_vk_parsing(vk_path: str):
vk = Groth16VerifyingKey.from_json(vk_path)
print(vk)


@pytest.mark.parametrize(
"proof_path",
[f"{PATH}/proof_bn254.json", f"{PATH}/proof_bls.json"],
)
def test_proof_parsing(proof_path: str):
proof = Groth16Proof.from_json(proof_path)
print(proof)


def test_proof_parsing_with_public_input():
proof = Groth16Proof.from_json(
f"{PATH}/proof_bn254.json", f"{PATH}/snarkjs_public_bn254.json"
)
print(proof)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"pi_a": [
"16867095230114469303111269582801754677348924111782514818746093562477643731718",
"20212722335582718902672982589607764312189339603046913281774669180256203100136",
"1"
],
"pi_b": [
[
"12758685536372388449510929615906811839459760160946896050208195496890210504448",
"17855758041968043219081456864094552349379559551194469443938085607012057050413"
],
[
"13955825016276204826390255402887489684619114124020822491524581785493735884723",
"4753473547991654414764256423822769241872233406220219643335981552335370273842"
],
[
"1",
"0"
]
],
"pi_c": [
"671762906748438705619751301153263621349258242033442893897067744180576955019",
"15774728702167052591009228304182510598553322825902260825229935303814649441886",
"1"
],
"protocol": "groth16",
"curve": "bn128"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"4949495449574848545353525153565755490000"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"protocol": "groth16",
"curve": "bn128",
"nPublic": 1,
"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": [
[
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
],
[
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
],
[
"1",
"0"
]
],
"vk_alphabeta_12": [
[
[
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
],
[
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
],
[
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
]
],
[
[
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
],
[
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
],
[
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
]
]
],
"IC": [
[
"3230230166848506278169341429844025995277520944155248223069557471517720414099",
"13103770257244981396389858672913686503786254567452595604017418062281627967708",
"1"
],
[
"19371697418061315618343891460787183627139127309393053314424436252400705071207",
"9445383417235588302514232777371752216736256846043789115945856987874292878586",
"1"
]
]
}
Loading

0 comments on commit 5917666

Please sign in to comment.