mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-07 19:36:42 +01:00
Add witness parser from binary file
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -496,3 +499,31 @@ func ProofToJson(p *types.Proof) ([]byte, error) {
|
||||
|
||||
return json.Marshal(ps)
|
||||
}
|
||||
|
||||
// ParseWitness parses binary file representation of the Witness into the Witness struct
|
||||
func ParseWitnessBin(f *os.File) (types.Witness, error) {
|
||||
var w types.Witness
|
||||
r := bufio.NewReader(f)
|
||||
for {
|
||||
b := make([]byte, 32)
|
||||
n, err := r.Read(b)
|
||||
if err == io.EOF {
|
||||
return w, nil
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n != 32 {
|
||||
return nil, fmt.Errorf("error on value format, expected 32 bytes, got %v", n)
|
||||
}
|
||||
w = append(w, new(big.Int).SetBytes(swapEndianness(b[0:32])))
|
||||
}
|
||||
}
|
||||
|
||||
// swapEndianness swaps the order of the bytes in the slice.
|
||||
func swapEndianness(b []byte) []byte {
|
||||
o := make([]byte, len(b))
|
||||
for i := range b {
|
||||
o[len(b)-1-i] = b[i]
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user