Skip to content

Commit

Permalink
groth16-only
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed Feb 7, 2024
1 parent 2ef425c commit 7fd7a41
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 115 deletions.
1 change: 0 additions & 1 deletion gnarkx/succinct/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (build *CircuitBuild) Export() {
fmt.Println("Failed to export solidity verifier:", err)
return
}

}

// ImportCircuitBuild imports the R1CS, proving key, and verifying key from files.
Expand Down
7 changes: 7 additions & 0 deletions plonky2x/verifier/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func main() {
systemFlag := flag.String("system", "groth16", "proving system to use (groth16, plonk)")
flag.Parse()

_ = systemFlag

log := logger.Logger()

if *circuitPath == "" {
Expand All @@ -35,6 +37,11 @@ func main() {
os.Exit(1)
}

// var system ProvingSystem
// if *systemFlag != "groth16" {
// system = NewGroth16System()
// }

log.Debug().Msg("Circuit path: " + *circuitPath)
log.Debug().Msg("Data path: " + *dataPath)

Expand Down
101 changes: 0 additions & 101 deletions plonky2x/verifier/system/groth16.go

This file was deleted.

13 changes: 0 additions & 13 deletions plonky2x/verifier/system/interface.go

This file was deleted.

Empty file removed plonky2x/verifier/system/shared.go
Empty file.
100 changes: 100 additions & 0 deletions plonky2x/verifier/verifier.go
Original file line number Diff line number Diff line change
@@ -1 +1,101 @@
package main

import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"time"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/groth16"
groth16Bn254 "github.com/consensys/gnark/backend/groth16/bn254"
"github.com/consensys/gnark/backend/witness"
"github.com/consensys/gnark/logger"
)

func LoadVerifierKey(path string) (groth16.VerifyingKey, error) {
log := logger.Logger()
vkFile, err := os.Open(path + "/vk.bin")
if err != nil {
return nil, fmt.Errorf("failed to open vk file: %w", err)
}
vk := groth16.NewVerifyingKey(ecc.BN254)
start := time.Now()
_, err = readV08VerifyingKey(vk.(*groth16Bn254.VerifyingKey), vkFile)
if err != nil {
return nil, fmt.Errorf("failed to read vk file: %w", err)
}
vkFile.Close()
elapsed := time.Since(start)
log.Debug().Msg("Successfully loaded verifying key, time: " + elapsed.String())

return vk, nil
}

func LoadPublicWitness(circuitPath string) (witness.Witness, error) {
log := logger.Logger()
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)
}
publicWitness.ReadFrom(witnessFile)
witnessFile.Close()
log.Debug().Msg("Successfully loaded public witness")

return publicWitness, nil
}

func LoadProof() (groth16.Proof, error) {
log := logger.Logger()
proofFile, err := os.Open("/proof.json")
if err != nil {
return nil, fmt.Errorf("failed to open proof file: %w", err)
}
proof := groth16.NewProof(ecc.BN254)
jsonProof, err := io.ReadAll(proofFile)
if err != nil {
return nil, fmt.Errorf("failed to read proof file: %w", err)
}
err = json.Unmarshal(jsonProof, proof)
if err != nil {
return nil, fmt.Errorf("failed to read proof file: %w", err)
}
proofFile.Close()
log.Debug().Msg("Successfully loaded proof")

return proof, nil
}

func ExportIFunctionVerifierSolidity(path string, vk groth16.VerifyingKey) error {
log := logger.Logger()
// Create a new buffer and export the VerifyingKey into it as a Solidity contract and
// convert the buffer content to a string for further manipulation.
buf := new(bytes.Buffer)
err := vk.ExportSolidity(buf)
if err != nil {
log.Err(err).Msg("failed to export verifying key to solidity")
return err
}
content := buf.String()

contractFile, err := os.Create(path + "/Verifier.sol")
if err != nil {
return err
}
w := bufio.NewWriter(contractFile)
// write the new content to the writer
_, err = w.Write([]byte(content))
if err != nil {
return err
}

contractFile.Close()
return err
}
File renamed without changes.

0 comments on commit 7fd7a41

Please sign in to comment.