-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch-verifier.go
157 lines (138 loc) · 4.72 KB
/
batch-verifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package batch
import (
"github.com/alinush/go-mcl"
"github.com/hyperproofs/gipa-go/cm"
"github.com/hyperproofs/gipa-go/gipakzg"
"github.com/hyperproofs/gipa-go/utils"
"github.com/hyperproofs/kzg-go/kzg"
"golang.org/x/crypto/blake2b"
)
type Verifier struct {
Verifier gipakzg.Verifier
W []mcl.G1
N uint32 // Be sure to do ceil when padding
M uint32
MN uint64 // In hyperproofs we may have to pad vector A and B. Thus self.N * self.M may not be equal to self.MN
B []mcl.G2
P []mcl.G1
Q []mcl.G2
}
func (self *Verifier) FiatShamir(Transcript []byte, T mcl.GT) mcl.Fr {
var x mcl.Fr
// x = VerifierChallenges
data := make([]byte, 0)
data = append(data, Transcript...)
data = append(data, T.Serialize()...)
hash := blake2b.Sum256(data)
copy(self.Verifier.Transcript[:], hash[:])
x.SetHashOf(hash[:])
return x
}
// // Just verify the AGGGIPA proofs
// func (self *Verifier) Verify_(proof Proof, P []mcl.G1, Q []mcl.G2, B []mcl.G2) bool {
// // self.P = make([]mcl.G1, len(P))
// // self.Q = make([]mcl.G2, len(Q))
// // self.B = make([]mcl.G2, len(B))
// // copy(self.P, P)
// // copy(self.Q, Q)
// // copy(self.B, B)
// self.P = make([]mcl.G1, self.N)
// self.Q = make([]mcl.G2, self.N)
// self.B = make([]mcl.G2, self.MN)
// copy(self.P, P)
// copy(self.Q, Q)
// copy(self.B, B)
// status := self.Verify(proof)
// return status
// }
func (self *Verifier) Verify(proof Proof) bool {
m := int(self.M)
r := self.FiatShamir(self.Verifier.Transcript[:], proof.T) // Transcript is initially empty
self.B = utils.G2VecRandExpo(self.B, r, m) // For P vector, M == 1 there is only one pairing on the lhs
self.P = utils.G1VecRandExpo(self.P, r, 1) // For P vector, M == 1 there is only one pairing on the lhs
U := utils.InnerProd(self.W, self.B)
Z := utils.InnerProd(self.P, self.Q) // In Edrax we can get away with just one pairing
com := cm.Com{}
com.Com[0] = proof.T
com.Com[1] = U
com.Com[2] = Z
self.Verifier.Com = com
status := self.Verifier.Verify(proof.GipaKzgProof)
return status
}
// func (self *Verifier) VerifyEdrax_(proof Proof, P []mcl.G1, Q []mcl.G2, B []mcl.G2) bool {
// // self.P = make([]mcl.G1, len(P))
// // self.Q = make([]mcl.G2, len(Q))
// // self.B = make([]mcl.G2, len(B))
// // copy(self.P, P)
// // copy(self.Q, Q)
// // copy(self.B, B)
// self.P = make([]mcl.G1, self.N)
// self.Q = make([]mcl.G2, self.N)
// self.B = make([]mcl.G2, self.MN)
// copy(self.P, P)
// copy(self.Q, Q)
// copy(self.B, B)
// status := self.VerifyEdrax(proof)
// return status
// }
// GIPA + Edrax. Check the overleaf BMMV19 notes.
func (self *Verifier) VerifyEdrax(proof Proof) bool {
m := int(self.M)
r := self.FiatShamir(self.Verifier.Transcript[:], proof.T)
self.B = utils.G2VecRandExpo(self.B, r, m) // For P vector, M == 1 there is only one pairing on the lhs
self.P = utils.G1VecRandExpo(self.P, r, 1) // For P vector, M == 1 there is only one pairing on the lhs
U := utils.InnerProd(self.W, self.B)
var Psum mcl.G1
for i := range self.P {
mcl.G1Add(&Psum, &Psum, &self.P[i])
}
pTemp := []mcl.G1{Psum}
qTemp := []mcl.G2{self.Q[0]}
Z := utils.InnerProd(pTemp, qTemp) // In Edrax we can get away with just one pairing
com := cm.Com{}
com.Com[0] = proof.T
com.Com[1] = U
com.Com[2] = Z
self.Verifier.Com = com
status := self.Verifier.Verify(proof.GipaKzgProof)
return status
}
func (self *Verifier) Init(M uint32, N uint32, MN uint64,
W []mcl.G1, kzg1 *kzg.KZG1Settings, kzg2 *kzg.KZG2Settings,
P []mcl.G1, Q []mcl.G2, B []mcl.G2) {
utils.InstanceSizeChecker(MN, "Batch Verifier Init: M is not a power of 2")
utils.SizeMismatchCheck(MN, uint64(len(W)), "Batch Verifier Init: W Size:")
utils.SizeMismatchCheck(2*MN-1, uint64(len(kzg1.PK)), "Batch Verifier Init: KZG1 PK Size:")
utils.SizeMismatchCheck(2*MN-1, uint64(len(kzg2.PK)), "Batch Verifier Init: KZG2 PK Size:")
utils.SizeMismatchCheck(uint64(N), uint64(len(P)), "Batch Verifier Init: P Size:")
utils.SizeMismatchCheck(uint64(N), uint64(len(Q)), "Batch Verifier Init: Q Size:")
utils.SizeMismatchCheck(MN, uint64(len(B)), "Batch Verifier Init: B Size:")
*self = Verifier{}
self.N = N
self.M = M
self.MN = MN
com := cm.Com{} //No need to set proper com, as it will rewritten in Verify() or EdraxVerify()
self.Verifier.Init(MN, kzg1, kzg2, com)
self.W = make([]mcl.G1, MN)
copy(self.W, W)
self.P = make([]mcl.G1, N)
self.Q = make([]mcl.G2, N)
self.B = make([]mcl.G2, MN)
copy(self.P, P)
copy(self.Q, Q)
copy(self.B, B)
}
// Use this only if you need to deepcopy
func (self *Verifier) Clone(verifier *Verifier) {
self.Init(
verifier.M,
verifier.N,
verifier.MN,
verifier.W,
&verifier.Verifier.KZG1,
&verifier.Verifier.KZG2,
verifier.P,
verifier.Q,
verifier.B)
}