mirror of
https://github.com/logos-storage/gnark-plonky2-verifier.git
synced 2026-01-08 08:03:12 +00:00
changes...
This commit is contained in:
parent
df3f8082ca
commit
51b98741b8
@ -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)
|
||||
|
||||
|
||||
@ -6279,7 +6279,7 @@
|
||||
[3434884762331691063, 5574489659803587019]
|
||||
]
|
||||
},
|
||||
"pow_witness": 3458764513015264899
|
||||
"pow_witness": 43623
|
||||
}
|
||||
},
|
||||
"public_inputs": [0, 1, 3736710860384812976]
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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