mirror of
https://github.com/logos-storage/gnark-plonky2-verifier.git
synced 2026-01-07 07:33:12 +00:00
commit
e5f455f771
@ -17,6 +17,10 @@ func NewFieldElement(x uint64) F {
|
||||
return emulated.NewElement[EmulatedField](x)
|
||||
}
|
||||
|
||||
func NewFieldElementFromString(x string) F {
|
||||
return emulated.NewElement[EmulatedField](x)
|
||||
}
|
||||
|
||||
func NewFieldAPI(api frontend.API) frontend.API {
|
||||
field, err := emulated.NewField[EmulatedField](api)
|
||||
if err != nil {
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
package plonky2_verifier
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gnark-ed25519/field"
|
||||
. "gnark-ed25519/field"
|
||||
. "gnark-ed25519/poseidon"
|
||||
"gnark-ed25519/utils"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/consensys/gnark/frontend"
|
||||
@ -52,39 +48,35 @@ func (circuit *TestChallengerCircuit) Define(api frontend.API) error {
|
||||
plonkBetas := challengerChip.GetNChallenges(numChallenges)
|
||||
plonkGammas := challengerChip.GetNChallenges(numChallenges)
|
||||
|
||||
expectedPlonkBetas := [2]frontend.Variable{
|
||||
frontend.Variable("4678728155650926271"),
|
||||
frontend.Variable("13611962404289024887"),
|
||||
expectedPublicInputHash := [4]F{
|
||||
NewFieldElementFromString("8416658900775745054"),
|
||||
NewFieldElementFromString("12574228347150446423"),
|
||||
NewFieldElementFromString("9629056739760131473"),
|
||||
NewFieldElementFromString("3119289788404190010"),
|
||||
}
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
field.AssertIsEqual(publicInputHash[i], expectedPublicInputHash[i])
|
||||
}
|
||||
|
||||
expectedPlonkBetas := [2]F{
|
||||
NewFieldElementFromString("4678728155650926271"),
|
||||
NewFieldElementFromString("13611962404289024887"),
|
||||
}
|
||||
|
||||
expectedPlonkGammas := [2]frontend.Variable{
|
||||
frontend.Variable("13237663823305715949"),
|
||||
frontend.Variable("15389314098328235145"),
|
||||
NewFieldElementFromString("13237663823305715949"),
|
||||
NewFieldElementFromString("15389314098328235145"),
|
||||
}
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
field.AssertIsEqual(plonkBetas[i], field.FromBinary(api.ToBinary(expectedPlonkBetas[i])).(F))
|
||||
field.AssertIsEqual(plonkGammas[i], field.FromBinary(api.ToBinary(expectedPlonkGammas[i])).(F))
|
||||
field.AssertIsEqual(plonkBetas[i], expectedPlonkBetas[i])
|
||||
field.AssertIsEqual(plonkGammas[i], expectedPlonkGammas[i])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestDeserializationOfPlonky2Proof(t *testing.T) {
|
||||
fibonacciProofPath := "./fibonacci_proof.json"
|
||||
jsonFile, err := os.Open(fibonacciProofPath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
var result Proof
|
||||
json.Unmarshal(byteValue, &result)
|
||||
|
||||
fmt.Println(result.WiresCap)
|
||||
}
|
||||
|
||||
func TestChallengerWitness(t *testing.T) {
|
||||
assert := test.NewAssert(t)
|
||||
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
{
|
||||
"config": {
|
||||
"num_wires": 135,
|
||||
"num_routed_wires": 80,
|
||||
"num_constants": 2,
|
||||
"use_base_arithmetic_gate": true,
|
||||
"security_bits": 100,
|
||||
"num_challenges": 2,
|
||||
"zero_knowledge": false,
|
||||
"max_quotient_degree_factor": 8,
|
||||
"fri_config": {
|
||||
"rate_bits": 3,
|
||||
"cap_height": 4,
|
||||
"proof_of_work_bits": 16,
|
||||
"reduction_strategy": { "ConstantArityBits": [4, 5] },
|
||||
"num_query_rounds": 28
|
||||
}
|
||||
},
|
||||
"fri_params": {
|
||||
"config": {
|
||||
"rate_bits": 3,
|
||||
"cap_height": 4,
|
||||
"proof_of_work_bits": 16,
|
||||
"reduction_strategy": { "ConstantArityBits": [4, 5] },
|
||||
"num_query_rounds": 28
|
||||
},
|
||||
"hiding": false,
|
||||
"degree_bits": 3,
|
||||
"reduction_arity_bits": []
|
||||
},
|
||||
"degree_bits": 3,
|
||||
"selectors_info": {
|
||||
"selector_indices": [0, 0, 0, 1],
|
||||
"groups": [
|
||||
{ "start": 0, "end": 3 },
|
||||
{ "start": 3, "end": 4 }
|
||||
]
|
||||
},
|
||||
"quotient_degree_factor": 8,
|
||||
"num_gate_constraints": 123,
|
||||
"num_constants": 4,
|
||||
"num_public_inputs": 3,
|
||||
"k_is": [
|
||||
1, 7, 49, 343, 2401, 16807, 117649, 823543, 5764801, 40353607, 282475249,
|
||||
1977326743, 13841287201, 96889010407, 678223072849, 4747561509943,
|
||||
33232930569601, 232630513987207, 1628413597910449, 11398895185373143,
|
||||
79792266297612001, 558545864083284007, 3909821048582988049,
|
||||
8922003270666332022, 7113790686420571191, 12903046666114829695,
|
||||
16534350385145470581, 5059988279530788141, 16973173887300932666,
|
||||
8131752794619022736, 1582037354089406189, 11074261478625843323,
|
||||
3732854072722565977, 7683234439643377518, 16889152938674473984,
|
||||
7543606154233811962, 15911754940807515092, 701820169165099718,
|
||||
4912741184155698026, 15942444219675301861, 916645121239607101,
|
||||
6416515848677249707, 8022122801911579307, 814627405137302186,
|
||||
5702391835961115302, 3023254712898638472, 2716038920875884983,
|
||||
565528376716610560, 3958698637016273920, 9264146389699333119,
|
||||
9508792519651578870, 11221315429317299127, 4762231727562756605,
|
||||
14888878023524711914, 11988425817600061793, 10132004445542095267,
|
||||
15583798910550913906, 16852872026783475737, 7289639770996824233,
|
||||
14133990258148600989, 6704211459967285318, 10035992080941828584,
|
||||
14911712358349047125, 12148266161370408270, 11250886851934520606,
|
||||
4969231685883306958, 16337877731768564385, 3684679705892444769,
|
||||
7346013871832529062, 14528608963998534792, 9466542400916821939,
|
||||
10925564598174000610, 2691975909559666986, 397087297503084581,
|
||||
2779611082521592067, 1010533508236560148, 7073734557655921036,
|
||||
12622653764762278610, 14571600075677612986, 9767480182670369297
|
||||
],
|
||||
"num_partial_products": 9,
|
||||
"circuit_digest": {
|
||||
"elements": [
|
||||
7754113318730736048, 18436136620016916513, 18054530212389526288,
|
||||
5893739326632906028
|
||||
]
|
||||
}
|
||||
}
|
||||
1
plonky2_verifier/data/fibonacci/common_circuit_data.json
Normal file
1
plonky2_verifier/data/fibonacci/common_circuit_data.json
Normal file
@ -0,0 +1 @@
|
||||
{"config":{"num_wires":135,"num_routed_wires":80,"num_constants":2,"use_base_arithmetic_gate":true,"security_bits":100,"num_challenges":2,"zero_knowledge":false,"max_quotient_degree_factor":8,"fri_config":{"rate_bits":3,"cap_height":4,"proof_of_work_bits":16,"reduction_strategy":{"ConstantArityBits":[4,5]},"num_query_rounds":28}},"fri_params":{"config":{"rate_bits":3,"cap_height":4,"proof_of_work_bits":16,"reduction_strategy":{"ConstantArityBits":[4,5]},"num_query_rounds":28},"hiding":false,"degree_bits":3,"reduction_arity_bits":[]},"degree_bits":3,"selectors_info":{"selector_indices":[0,0,0,1],"groups":[{"start":0,"end":3},{"start":3,"end":4}]},"quotient_degree_factor":8,"num_gate_constraints":123,"num_constants":4,"num_public_inputs":3,"k_is":[1,7,49,343,2401,16807,117649,823543,5764801,40353607,282475249,1977326743,13841287201,96889010407,678223072849,4747561509943,33232930569601,232630513987207,1628413597910449,11398895185373143,79792266297612001,558545864083284007,3909821048582988049,8922003270666332022,7113790686420571191,12903046666114829695,16534350385145470581,5059988279530788141,16973173887300932666,8131752794619022736,1582037354089406189,11074261478625843323,3732854072722565977,7683234439643377518,16889152938674473984,7543606154233811962,15911754940807515092,701820169165099718,4912741184155698026,15942444219675301861,916645121239607101,6416515848677249707,8022122801911579307,814627405137302186,5702391835961115302,3023254712898638472,2716038920875884983,565528376716610560,3958698637016273920,9264146389699333119,9508792519651578870,11221315429317299127,4762231727562756605,14888878023524711914,11988425817600061793,10132004445542095267,15583798910550913906,16852872026783475737,7289639770996824233,14133990258148600989,6704211459967285318,10035992080941828584,14911712358349047125,12148266161370408270,11250886851934520606,4969231685883306958,16337877731768564385,3684679705892444769,7346013871832529062,14528608963998534792,9466542400916821939,10925564598174000610,2691975909559666986,397087297503084581,2779611082521592067,1010533508236560148,7073734557655921036,12622653764762278610,14571600075677612986,9767480182670369297],"num_partial_products":9,"circuit_digest":{"elements":[7754113318730736048,18436136620016916513,18054530212389526288,5893739326632906028]}}
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
{"constants_sigmas_cap":[{"elements":[2913805118787558759,15605217703384212484,9293436862297178555,10529947991695419448]},{"elements":[1937331278189251620,17537260089483183877,10458485670158100707,4116443229550247591]},{"elements":[8142760542024755709,3845244796524514577,16191049345326767258,7348433903875207214]},{"elements":[18274477257392359471,9341197367296335592,14314312946600883535,17431979896521737468]},{"elements":[12713790163422286570,9838614764658999419,3024549327814176904,6544549858431318793]},{"elements":[17461063081201329467,1929790214678747830,14738190695567211833,4502436664569676311]},{"elements":[17446087997043032816,17518692693064701003,4915378766449394412,10675325761198739044]},{"elements":[11349186227918507635,7105572536043210156,13296927306801261929,6138189381388819111]},{"elements":[17427080957162886576,4310228111529328877,16109317445338921222,11923676504992192083]},{"elements":[11292141569337462929,7213981967192374125,4837353949249389782,13157524938508720907]},{"elements":[17221477633935993097,7905315334616496868,2950048088611741910,16851660641249290423]},{"elements":[1918571898367258879,14473285549490778842,16456257732802770188,16611801325745795527]},{"elements":[7880989808200689690,16935107633380717766,8956194191973051375,1103945341495739535]},{"elements":[4501339912027744074,12142665268233044767,9270990890291324944,45374981263348191]},{"elements":[13657768796246999470,2899654677720502418,7228867285602519410,3363587770111123806]},{"elements":[18227101298896629706,12986849723013952028,16815808278639394978,16460725848109409638]}]}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,100 +0,0 @@
|
||||
{
|
||||
"constants_sigmas_cap": [
|
||||
{
|
||||
"elements": [
|
||||
2913805118787558759, 15605217703384212484, 9293436862297178555,
|
||||
10529947991695419448
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
1937331278189251620, 17537260089483183877, 10458485670158100707,
|
||||
4116443229550247591
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
8142760542024755709, 3845244796524514577, 16191049345326767258,
|
||||
7348433903875207214
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
18274477257392359471, 9341197367296335592, 14314312946600883535,
|
||||
17431979896521737468
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
12713790163422286570, 9838614764658999419, 3024549327814176904,
|
||||
6544549858431318793
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
17461063081201329467, 1929790214678747830, 14738190695567211833,
|
||||
4502436664569676311
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
17446087997043032816, 17518692693064701003, 4915378766449394412,
|
||||
10675325761198739044
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
11349186227918507635, 7105572536043210156, 13296927306801261929,
|
||||
6138189381388819111
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
17427080957162886576, 4310228111529328877, 16109317445338921222,
|
||||
11923676504992192083
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
11292141569337462929, 7213981967192374125, 4837353949249389782,
|
||||
13157524938508720907
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
17221477633935993097, 7905315334616496868, 2950048088611741910,
|
||||
16851660641249290423
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
1918571898367258879, 14473285549490778842, 16456257732802770188,
|
||||
16611801325745795527
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
7880989808200689690, 16935107633380717766, 8956194191973051375,
|
||||
1103945341495739535
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
4501339912027744074, 12142665268233044767, 9270990890291324944,
|
||||
45374981263348191
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
13657768796246999470, 2899654677720502418, 7228867285602519410,
|
||||
3363587770111123806
|
||||
]
|
||||
},
|
||||
{
|
||||
"elements": [
|
||||
18227101298896629706, 12986849723013952028, 16815808278639394978,
|
||||
16460725848109409638
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -42,7 +42,7 @@ type ProofWithPublicInputsRaw struct {
|
||||
PowWitness uint64 `json:"pow_witness"`
|
||||
} `json:"opening_proof"`
|
||||
} `json:"proof"`
|
||||
PublicInputs []interface{} `json:"public_inputs"`
|
||||
PublicInputs []uint64 `json:"public_inputs"`
|
||||
}
|
||||
|
||||
type CommonCircuitDataRaw struct {
|
||||
@ -189,6 +189,7 @@ func DeserializeProofWithPublicInputs(path string) ProofWithPublicInputs {
|
||||
FinalPoly struct{ Coeffs [][]uint64 }
|
||||
PowWitness uint64
|
||||
}(raw.Proof.OpeningProof))
|
||||
proofWithPis.PublicInputs = utils.Uint64ArrayToFArray(raw.PublicInputs)
|
||||
|
||||
return proofWithPis
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ func (c *VerifierChip) GetChallenges(proofWithPis ProofWithPublicInputs, publicI
|
||||
|
||||
var circuitDigest Hash
|
||||
copy(circuitDigest[:], utils.Uint64ArrayToFArray(commonData.CircuitDigest.Elements))
|
||||
|
||||
challenger.ObserveHash(circuitDigest)
|
||||
challenger.ObserveHash(publicInputsHash)
|
||||
challenger.ObserveCap(proofWithPis.Proof.WiresCap)
|
||||
|
||||
@ -11,15 +11,79 @@ import (
|
||||
|
||||
type TestVerifierCircuit struct{}
|
||||
|
||||
func (c *VerifierChip) GetChallengesSanityCheck(proofWithPis ProofWithPublicInputs, verifierData VerifierOnlyCircuitData, commonData CommonCircuitDataRaw) {
|
||||
publicInputsHash := c.GetPublicInputsHash(proofWithPis.PublicInputs)
|
||||
proofChallenges := c.GetChallenges(proofWithPis, publicInputsHash, commonData)
|
||||
|
||||
expectedPublicInputsHash := [4]F{
|
||||
NewFieldElementFromString("8416658900775745054"),
|
||||
NewFieldElementFromString("12574228347150446423"),
|
||||
NewFieldElementFromString("9629056739760131473"),
|
||||
NewFieldElementFromString("3119289788404190010"),
|
||||
}
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
c.field.AssertIsEqual(publicInputsHash[i], expectedPublicInputsHash[i])
|
||||
}
|
||||
|
||||
expectedPlonkBetas := [2]F{
|
||||
NewFieldElementFromString("4678728155650926271"),
|
||||
NewFieldElementFromString("13611962404289024887"),
|
||||
}
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
c.field.AssertIsEqual(proofChallenges.PlonkBetas[i], expectedPlonkBetas[i])
|
||||
}
|
||||
|
||||
expectedPlonkGammas := [2]F{
|
||||
NewFieldElementFromString("13237663823305715949"),
|
||||
NewFieldElementFromString("15389314098328235145"),
|
||||
}
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
c.field.AssertIsEqual(proofChallenges.PlonkGammas[i], expectedPlonkGammas[i])
|
||||
}
|
||||
|
||||
expectedPlonkAlphas := [2]F{
|
||||
NewFieldElementFromString("14505919539124304197"),
|
||||
NewFieldElementFromString("1695455639263736117"),
|
||||
}
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
c.field.AssertIsEqual(proofChallenges.PlonkAlphas[i], expectedPlonkAlphas[i])
|
||||
}
|
||||
|
||||
expectedPlonkZetas := [2]F{
|
||||
NewFieldElementFromString("14887793628029982930"),
|
||||
NewFieldElementFromString("1136137158284059037"),
|
||||
}
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
c.field.AssertIsEqual(proofChallenges.PlonkZeta[i], expectedPlonkZetas[i])
|
||||
}
|
||||
|
||||
expectedFriAlpha := [2]F{
|
||||
NewFieldElementFromString("14641715242626918707"),
|
||||
NewFieldElementFromString("10574243340537902930"),
|
||||
}
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
c.field.AssertIsEqual(proofChallenges.FriChallenges.FriAlpha[i], expectedFriAlpha[i])
|
||||
}
|
||||
|
||||
// This test is commented out because pow_witness is randomized between runs of the prover.
|
||||
// expectedPowResponse := NewFieldElementFromString("92909863298412")
|
||||
// c.field.AssertIsEqual(proofChallenges.FriChallenges.FriPowResponse, expectedPowResponse)
|
||||
}
|
||||
|
||||
func (circuit *TestVerifierCircuit) Define(api frontend.API) error {
|
||||
field := NewFieldAPI(api)
|
||||
poseidonChip := NewPoseidonChip(api, field)
|
||||
verifierChip := VerifierChip{api: api, field: field, poseidonChip: *poseidonChip}
|
||||
proofWithPis := DeserializeProofWithPublicInputs("./data/proof_with_public_inputs.json")
|
||||
commonCircuitData := DeserializeCommonCircuitData("./data/common_circuit_data.json")
|
||||
verfierOnlyCircuitData := DeserializeVerifierOnlyCircuitData("./data/verifier_only_circuit_data.json")
|
||||
verifierChip.Verify(proofWithPis, verfierOnlyCircuitData, commonCircuitData)
|
||||
panic("look at stdout")
|
||||
proofWithPis := DeserializeProofWithPublicInputs("./data/fibonacci/proof_with_public_inputs.json")
|
||||
commonCircuitData := DeserializeCommonCircuitData("./data/fibonacci/common_circuit_data.json")
|
||||
verfierOnlyCircuitData := DeserializeVerifierOnlyCircuitData("./data/fibonacci/verifier_only_circuit_data.json")
|
||||
verifierChip.GetChallengesSanityCheck(proofWithPis, verfierOnlyCircuitData, commonCircuitData)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -70,9 +70,6 @@ func (c *PoseidonChip) fullRounds(state PoseidonState, roundCounter *int) Poseid
|
||||
state = c.constantLayer(state, roundCounter)
|
||||
state = c.sBoxLayer(state)
|
||||
state = c.mdsLayer(state)
|
||||
if *roundCounter >= 26 && i == 3 {
|
||||
break
|
||||
}
|
||||
*roundCounter += 1
|
||||
}
|
||||
return state
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user