Browse Source

changes...

main
jtguibas 3 years ago
parent
commit
51b98741b8
6 changed files with 27 additions and 32 deletions
  1. +4
    -0
      field/field.go
  2. +19
    -27
      plonky2_verifier/challenger_test.go
  3. +1
    -1
      plonky2_verifier/data/proof_with_public_inputs.json
  4. +2
    -1
      plonky2_verifier/deserialize.go
  5. +1
    -0
      plonky2_verifier/verifier.go
  6. +0
    -3
      poseidon/poseidon.go

+ 4
- 0
field/field.go

@ -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 {

+ 19
- 27
plonky2_verifier/challenger_test.go

@ -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,37 +48,33 @@ 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{
frontend.Variable("4678728155650926271"),
frontend.Variable("13611962404289024887"),
}
expectedPlonkGammas := [2]frontend.Variable{
frontend.Variable("13237663823305715949"),
frontend.Variable("15389314098328235145"),
expectedPublicInputHash := [4]F{
NewFieldElementFromString("8416658900775745054"),
NewFieldElementFromString("12574228347150446423"),
NewFieldElementFromString("9629056739760131473"),
NewFieldElementFromString("3119289788404190010"),
} }
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))
for i := 0; i < 4; i++ {
field.AssertIsEqual(publicInputHash[i], expectedPublicInputHash[i])
} }
return nil
}
func TestDeserializationOfPlonky2Proof(t *testing.T) {
fibonacciProofPath := "./fibonacci_proof.json"
jsonFile, err := os.Open(fibonacciProofPath)
if err != nil {
fmt.Println(err)
expectedPlonkBetas := [2]F{
NewFieldElementFromString("4678728155650926271"),
NewFieldElementFromString("13611962404289024887"),
} }
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
expectedPlonkGammas := [2]frontend.Variable{
NewFieldElementFromString("13237663823305715949"),
NewFieldElementFromString("15389314098328235145"),
}
var result Proof
json.Unmarshal(byteValue, &result)
for i := 0; i < 2; i++ {
field.AssertIsEqual(plonkBetas[i], expectedPlonkBetas[i])
field.AssertIsEqual(plonkGammas[i], expectedPlonkGammas[i])
}
fmt.Println(result.WiresCap)
return nil
} }
func TestChallengerWitness(t *testing.T) { func TestChallengerWitness(t *testing.T) {

+ 1
- 1
plonky2_verifier/data/proof_with_public_inputs.json

@ -6279,7 +6279,7 @@
[3434884762331691063, 5574489659803587019] [3434884762331691063, 5574489659803587019]
] ]
}, },
"pow_witness": 3458764513015264899
"pow_witness": 43623
} }
}, },
"public_inputs": [0, 1, 3736710860384812976] "public_inputs": [0, 1, 3736710860384812976]

+ 2
- 1
plonky2_verifier/deserialize.go

@ -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
} }

+ 1
- 0
plonky2_verifier/verifier.go

@ -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)

+ 0
- 3
poseidon/poseidon.go

@ -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

Loading…
Cancel
Save