diff --git a/field/field.go b/field/field.go index bbd71a1..4116696 100644 --- a/field/field.go +++ b/field/field.go @@ -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 { diff --git a/plonky2_verifier/challenger_test.go b/plonky2_verifier/challenger_test.go index b6ba54a..e7fd8d5 100644 --- a/plonky2_verifier/challenger_test.go +++ b/plonky2_verifier/challenger_test.go @@ -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,37 +48,33 @@ 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"), - } - 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) { diff --git a/plonky2_verifier/data/proof_with_public_inputs.json b/plonky2_verifier/data/proof_with_public_inputs.json index ade013e..f2150b9 100644 --- a/plonky2_verifier/data/proof_with_public_inputs.json +++ b/plonky2_verifier/data/proof_with_public_inputs.json @@ -6279,7 +6279,7 @@ [3434884762331691063, 5574489659803587019] ] }, - "pow_witness": 3458764513015264899 + "pow_witness": 43623 } }, "public_inputs": [0, 1, 3736710860384812976] diff --git a/plonky2_verifier/deserialize.go b/plonky2_verifier/deserialize.go index 8beecb8..2035a14 100644 --- a/plonky2_verifier/deserialize.go +++ b/plonky2_verifier/deserialize.go @@ -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 } diff --git a/plonky2_verifier/verifier.go b/plonky2_verifier/verifier.go index 7506aab..0c52c5c 100644 --- a/plonky2_verifier/verifier.go +++ b/plonky2_verifier/verifier.go @@ -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) diff --git a/poseidon/poseidon.go b/poseidon/poseidon.go index b4eaf68..e86d534 100644 --- a/poseidon/poseidon.go +++ b/poseidon/poseidon.go @@ -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