-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconsistency_test.go
122 lines (93 loc) · 2.88 KB
/
consistency_test.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
package zksigma
import (
"crypto/rand"
"testing"
)
func TestConsistency(t *testing.T) {
x, err := rand.Int(rand.Reader, TestCurve.C.Params().N)
if err != nil {
t.Fatalf("%v\n", err)
}
sk, err := rand.Int(rand.Reader, TestCurve.C.Params().N)
if err != nil {
t.Fatalf("%v\n", err)
}
pk := TestCurve.Mult(TestCurve.H, sk)
comm, u, err := PedCommit(TestCurve, x)
if err != nil {
t.Fatalf("%v\n", err)
}
y := TestCurve.Mult(pk, u)
conProof, status1 := NewConsistencyProof(TestCurve, comm, y, pk, x, u)
if status1 != nil {
t.Fatalf("TestConsistency - incorrect error message for correct proof, case 1\n")
}
t.Logf(" [testing] Testing correct consistency proof\n")
check, err := conProof.Verify(TestCurve, comm, y, pk)
if !check || err != nil {
t.Fatalf("Error -- Proof should be correct\n")
}
t.Logf(" [testing] Next proof should fail\n")
_, status2 := NewConsistencyProof(TestCurve, y, comm, pk, x, u)
if status2 == nil {
t.Fatalf("TestConsistency - incorrect error message for correct proof, case 2\n")
}
}
func TestConsistencySerialization(t *testing.T) {
x, err := rand.Int(rand.Reader, TestCurve.C.Params().N)
if err != nil {
t.Fatalf("%v\n", err)
}
sk, err := rand.Int(rand.Reader, TestCurve.C.Params().N)
if err != nil {
t.Fatalf("%v\n", err)
}
pk := TestCurve.Mult(TestCurve.H, sk)
comm, u, err := PedCommit(TestCurve, x)
if err != nil {
t.Fatalf("%v\n", err)
}
y := TestCurve.Mult(pk, u)
conProof, status1 := NewConsistencyProof(TestCurve, comm, y, pk, x, u)
if status1 != nil {
t.Fatalf("TestConsistency - incorrect error message for correct proof, case 1\n")
}
conProof, status1 = NewConsistencyProofFromBytes(conProof.Bytes())
if status1 != nil {
t.Fatalf("TestConsistency - failed to deserialize \n")
}
t.Logf(" [testing] Testing correct consistency proof\n")
check, err := conProof.Verify(TestCurve, comm, y, pk)
if !check || err != nil {
t.Fatalf("Error -- Proof should be correct\n")
}
}
func BenchmarkConsistencyProve(b *testing.B) {
value, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
sk, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
PK := TestCurve.Mult(TestCurve.H, sk)
CM, randVal, err := PedCommit(TestCurve, value)
if err != nil {
b.Fatalf("%v\n", err)
}
CMTok := TestCurve.Mult(PK, randVal)
b.ResetTimer()
for ii := 0; ii < b.N; ii++ {
NewConsistencyProof(TestCurve, CM, CMTok, PK, value, randVal)
}
}
func BenchmarkConsistencyVerify(b *testing.B) {
value, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
sk, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
PK := TestCurve.Mult(TestCurve.H, sk)
CM, randVal, err := PedCommit(TestCurve, value)
if err != nil {
b.Fatalf("%v\n", err)
}
CMTok := TestCurve.Mult(PK, randVal)
proof, _ := NewConsistencyProof(TestCurve, CM, CMTok, PK, value, randVal)
b.ResetTimer()
for ii := 0; ii < b.N; ii++ {
proof.Verify(TestCurve, CM, CMTok, PK)
}
}