Skip to content

Commit

Permalink
save witness in binary
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirhemo committed Aug 30, 2023
1 parent e86cb12 commit 7131796
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
8 changes: 2 additions & 6 deletions plonky2x-verifier/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,12 @@ func Prove(circuitPath string, r1cs constraint.ConstraintSystem, pk groth16.Prov
return nil, nil, fmt.Errorf("failed to get public witness: %w", err)
}

jsonPublicWitness, err := json.Marshal(publicWitness)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal public witness: %w", err)
}
log.Info().Msg("Saving public witness to " + circuitPath + "/public_witness.json")
log.Info().Msg("Saving public witness to " + circuitPath + "/public_witness.bin")
witnessFile, err := os.Create(circuitPath + "/public_witness.json")
if err != nil {
return nil, nil, fmt.Errorf("failed to create public witness file: %w", err)
}
_, err = witnessFile.Write(jsonPublicWitness)
_, err = publicWitness.WriteTo(witnessFile)
if err != nil {
return nil, nil, fmt.Errorf("failed to write public witness file: %w", err)
}
Expand Down
11 changes: 2 additions & 9 deletions plonky2x-verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,15 @@ func LoadVerifierKey(path string) (groth16.VerifyingKey, error) {

func LoadPublicWitness(circuitPath string) (witness.Witness, error) {
log := logger.Logger()
witnessFile, err := os.Open(circuitPath + "/public_witness.json")
witnessFile, err := os.Open(circuitPath + "/public_witness.bin")
if err != nil {
return nil, fmt.Errorf("failed to open public witness file: %w", err)
}
publicWitness, err := witness.New(ecc.BN254.ScalarField())
if err != nil {
return nil, fmt.Errorf("failed to create public witness: %w", err)
}
jsonPublicWitness, err := io.ReadAll(witnessFile)
if err != nil {
return nil, fmt.Errorf("failed to read public witness file: %w", err)
}
err = json.Unmarshal(jsonPublicWitness, publicWitness)
if err != nil {
return nil, fmt.Errorf("failed to read public witness file: %w", err)
}
publicWitness.ReadFrom(witnessFile)
witnessFile.Close()
log.Debug().Msg("Successfully loaded public witness")

Expand Down

0 comments on commit 7131796

Please sign in to comment.