Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
MauroToscano committed Jan 12, 2024
1 parent 80d1149 commit 27b6a63
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions examples/prove-gnark-plonk/go_exporter_example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"os"
"reflect"
"strconv"
"unsafe"

"encoding/json"
Expand Down Expand Up @@ -52,6 +53,38 @@ type SerializedCircuit struct {
Permutation []int64
}

func witness_to_json_array(fullWitness witness.Witness) string {

witnessVec := fullWitness.Vector()
witnessVecString := fmt.Sprint(witnessVec)
inputJSON := fmt.Sprint("{\"witness\": ", witnessVecString, "}\n")

fmt.Println("Witness json")
fmt.Println(inputJSON)

// Unmarshal JSON into a map
var data map[string]interface{}
json.Unmarshal([]byte(inputJSON), &data)

// Convert array values to strings
witnessArray, _ := data["witness"].([]interface{})

var witnessStrings []string
for _, value := range witnessArray {
// Convert the value to a string
strValue := strconv.Itoa(int(value.(float64)))
witnessStrings = append(witnessStrings, strValue)
}

// Update the map with the converted array
data["witness"] = witnessStrings

// Marshal the updated map back to JSON
outputJSON, _ := json.Marshal(data)

return string(outputJSON)
}

func ToJSON(_r1cs *cs.SparseR1CS, pk *plonk_bls12381.ProvingKey, fullWitness witness.Witness, witnessPublic fr_bls12381.Vector) { // n
nbConstraints := _r1cs.GetNbConstraints()
nbPublic := len(_r1cs.Public)
Expand Down Expand Up @@ -176,14 +209,12 @@ func ToJSON(_r1cs *cs.SparseR1CS, pk *plonk_bls12381.ProvingKey, fullWitness wit

witnessVec := fullWitness.Vector()
println()

witnessVecString := fmt.Sprint(witnessVec)

fmt.Println(witnessVecString)

jsonWitness := fmt.Sprint("{ \"witness\" : ", witnessVecString, " }\n")
f, _ := os.Create("witness.json")
fmt.Fprintf(f, jsonWitness)
fmt.Fprintf(f, witness_to_json_array(fullWitness))

// witnessFormatted := fmt.Sprintln(witnessVec)

Expand Down

0 comments on commit 27b6a63

Please sign in to comment.