mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 09:01:32 +01:00
changes...
This commit is contained in:
@@ -17,6 +17,10 @@ func NewFieldElement(x uint64) F {
|
|||||||
return emulated.NewElement[EmulatedField](x)
|
return emulated.NewElement[EmulatedField](x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewFieldElementFromString(x string) F {
|
||||||
|
return emulated.NewElement[EmulatedField](x)
|
||||||
|
}
|
||||||
|
|
||||||
func NewFieldAPI(api frontend.API) frontend.API {
|
func NewFieldAPI(api frontend.API) frontend.API {
|
||||||
field, err := emulated.NewField[EmulatedField](api)
|
field, err := emulated.NewField[EmulatedField](api)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
package plonky2_verifier
|
package plonky2_verifier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"gnark-ed25519/field"
|
"gnark-ed25519/field"
|
||||||
. "gnark-ed25519/field"
|
. "gnark-ed25519/field"
|
||||||
. "gnark-ed25519/poseidon"
|
. "gnark-ed25519/poseidon"
|
||||||
"gnark-ed25519/utils"
|
"gnark-ed25519/utils"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/consensys/gnark/frontend"
|
"github.com/consensys/gnark/frontend"
|
||||||
@@ -52,39 +48,35 @@ func (circuit *TestChallengerCircuit) Define(api frontend.API) error {
|
|||||||
plonkBetas := challengerChip.GetNChallenges(numChallenges)
|
plonkBetas := challengerChip.GetNChallenges(numChallenges)
|
||||||
plonkGammas := challengerChip.GetNChallenges(numChallenges)
|
plonkGammas := challengerChip.GetNChallenges(numChallenges)
|
||||||
|
|
||||||
expectedPlonkBetas := [2]frontend.Variable{
|
expectedPublicInputHash := [4]F{
|
||||||
frontend.Variable("4678728155650926271"),
|
NewFieldElementFromString("8416658900775745054"),
|
||||||
frontend.Variable("13611962404289024887"),
|
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{
|
expectedPlonkGammas := [2]frontend.Variable{
|
||||||
frontend.Variable("13237663823305715949"),
|
NewFieldElementFromString("13237663823305715949"),
|
||||||
frontend.Variable("15389314098328235145"),
|
NewFieldElementFromString("15389314098328235145"),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
field.AssertIsEqual(plonkBetas[i], field.FromBinary(api.ToBinary(expectedPlonkBetas[i])).(F))
|
field.AssertIsEqual(plonkBetas[i], expectedPlonkBetas[i])
|
||||||
field.AssertIsEqual(plonkGammas[i], field.FromBinary(api.ToBinary(expectedPlonkGammas[i])).(F))
|
field.AssertIsEqual(plonkGammas[i], expectedPlonkGammas[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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) {
|
func TestChallengerWitness(t *testing.T) {
|
||||||
assert := test.NewAssert(t)
|
assert := test.NewAssert(t)
|
||||||
|
|
||||||
|
|||||||
@@ -6279,7 +6279,7 @@
|
|||||||
[3434884762331691063, 5574489659803587019]
|
[3434884762331691063, 5574489659803587019]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"pow_witness": 3458764513015264899
|
"pow_witness": 43623
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"public_inputs": [0, 1, 3736710860384812976]
|
"public_inputs": [0, 1, 3736710860384812976]
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type ProofWithPublicInputsRaw struct {
|
|||||||
PowWitness uint64 `json:"pow_witness"`
|
PowWitness uint64 `json:"pow_witness"`
|
||||||
} `json:"opening_proof"`
|
} `json:"opening_proof"`
|
||||||
} `json:"proof"`
|
} `json:"proof"`
|
||||||
PublicInputs []interface{} `json:"public_inputs"`
|
PublicInputs []uint64 `json:"public_inputs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommonCircuitDataRaw struct {
|
type CommonCircuitDataRaw struct {
|
||||||
@@ -189,6 +189,7 @@ func DeserializeProofWithPublicInputs(path string) ProofWithPublicInputs {
|
|||||||
FinalPoly struct{ Coeffs [][]uint64 }
|
FinalPoly struct{ Coeffs [][]uint64 }
|
||||||
PowWitness uint64
|
PowWitness uint64
|
||||||
}(raw.Proof.OpeningProof))
|
}(raw.Proof.OpeningProof))
|
||||||
|
proofWithPis.PublicInputs = utils.Uint64ArrayToFArray(raw.PublicInputs)
|
||||||
|
|
||||||
return proofWithPis
|
return proofWithPis
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ func (c *VerifierChip) GetChallenges(proofWithPis ProofWithPublicInputs, publicI
|
|||||||
|
|
||||||
var circuitDigest Hash
|
var circuitDigest Hash
|
||||||
copy(circuitDigest[:], utils.Uint64ArrayToFArray(commonData.CircuitDigest.Elements))
|
copy(circuitDigest[:], utils.Uint64ArrayToFArray(commonData.CircuitDigest.Elements))
|
||||||
|
|
||||||
challenger.ObserveHash(circuitDigest)
|
challenger.ObserveHash(circuitDigest)
|
||||||
challenger.ObserveHash(publicInputsHash)
|
challenger.ObserveHash(publicInputsHash)
|
||||||
challenger.ObserveCap(proofWithPis.Proof.WiresCap)
|
challenger.ObserveCap(proofWithPis.Proof.WiresCap)
|
||||||
|
|||||||
@@ -70,9 +70,6 @@ func (c *PoseidonChip) fullRounds(state PoseidonState, roundCounter *int) Poseid
|
|||||||
state = c.constantLayer(state, roundCounter)
|
state = c.constantLayer(state, roundCounter)
|
||||||
state = c.sBoxLayer(state)
|
state = c.sBoxLayer(state)
|
||||||
state = c.mdsLayer(state)
|
state = c.mdsLayer(state)
|
||||||
if *roundCounter >= 26 && i == 3 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
*roundCounter += 1
|
*roundCounter += 1
|
||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
|
|||||||
Reference in New Issue
Block a user