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
|
package nizk
import (
"testing"
. "kesim.org/seal/common"
)
func TestVerification(t *testing.T) {
var st [3]*Stage2
for i, typ := range []Type{None, Unset, Set} {
st[i] = NewStage2(typ)
c, p := st[i].Commit()
if !c.Verify(p) {
t.Fatalf("Couldn't verify proof for %v, case %d\n", typ, i)
}
}
for _, ind := range [][2]int{{0, 1}, {1, 2}, {2, 0}} {
c1, p1 := st[ind[0]].Commit()
c2, p2 := st[ind[1]].Commit()
if c1.Verify(p2) || c2.Verify(p1) {
t.Fatalf("Shouldn't be able to verify %d with proof %d", ind[0], ind[1])
}
}
}
func TestVerificationFromScalar(t *testing.T) {
var s [8]*Scalar
var st [3]*Stage2
for i := range s {
s[i] = Curve.RandomScalar()
}
for i, typ := range []Type{None, Unset, Set} {
st[i] = NewStage2FromScalars(typ, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7])
c, p := st[i].Commit()
if !c.Verify(p) {
t.Fatalf("Couldn't verify proof for %v, case %d\n", typ, i)
}
}
for _, ind := range [][2]int{{0, 1}, {1, 2}, {2, 1}, {2, 0}} {
c1, p1 := st[ind[0]].Commit()
c2, p2 := st[ind[1]].Commit()
if c1.Verify(p2) || c2.Verify(p1) {
t.Fatalf("Shouldn't be able to verify %d with proof %d", ind[0], ind[1])
}
}
}
|