|
@ -1,6 +1,8 @@ |
|
|
package types |
|
|
package types |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"encoding/hex" |
|
|
|
|
|
"encoding/json" |
|
|
"math/big" |
|
|
"math/big" |
|
|
|
|
|
|
|
|
bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" |
|
|
bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" |
|
@ -16,6 +18,52 @@ type Proof struct { |
|
|
C *bn256.G1 |
|
|
C *bn256.G1 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type proofAux struct { |
|
|
|
|
|
A string `json:"pi_a"` |
|
|
|
|
|
B string `json:"pi_b"` |
|
|
|
|
|
C string `json:"pi_c"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p Proof) MarshalJSON() ([]byte, error) { |
|
|
|
|
|
var pa proofAux |
|
|
|
|
|
pa.A = hex.EncodeToString(p.A.Marshal()) |
|
|
|
|
|
pa.B = hex.EncodeToString(p.B.Marshal()) |
|
|
|
|
|
pa.C = hex.EncodeToString(p.C.Marshal()) |
|
|
|
|
|
return json.Marshal(pa) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p *Proof) UnmarshalJSON(data []byte) error { |
|
|
|
|
|
var pa proofAux |
|
|
|
|
|
if err := json.Unmarshal(data, &pa); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
aBytes, err := hex.DecodeString(pa.A) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
p.A = new(bn256.G1) |
|
|
|
|
|
if _, err := p.A.Unmarshal(aBytes); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
bBytes, err := hex.DecodeString(pa.B) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
p.B = new(bn256.G2) |
|
|
|
|
|
if _, err := p.B.Unmarshal(bBytes); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
cBytes, err := hex.DecodeString(pa.C) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
p.C = new(bn256.G1) |
|
|
|
|
|
if _, err := p.C.Unmarshal(cBytes); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Pk holds the data structure of the ProvingKey
|
|
|
// Pk holds the data structure of the ProvingKey
|
|
|
type Pk struct { |
|
|
type Pk struct { |
|
|
A []*bn256.G1 |
|
|
A []*bn256.G1 |
|
|