-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdisjunctive_test.go
126 lines (107 loc) · 3.99 KB
/
disjunctive_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
123
124
125
126
package zksigma
import (
"crypto/rand"
"math/big"
"testing"
)
func TestDisjunctive(t *testing.T) {
x := big.NewInt(100)
y := big.NewInt(101)
Base1 := TestCurve.G
Result1 := TestCurve.Mult(TestCurve.G, x)
Base2 := TestCurve.H
Result2 := TestCurve.Mult(TestCurve.H, y)
djProofLEFT, status1 := NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, x, Left)
if status1 != nil {
proofStatus(status1.(*errorProof))
t.Fatalf("TestDisjunctive - incorrect error message for correct proof, case 1\n")
}
djProofRIGHT, status2 := NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, y, Right)
if status2 != nil {
proofStatus(status2.(*errorProof))
t.Fatalf("TestDisjunctive - incorrect error message for correct proof, case 2\n")
}
t.Logf("Testing DisjunctiveProof:\n")
t.Logf("First djProof : ")
check, err := djProofLEFT.Verify(TestCurve, Base1, Result1, Base2, Result2)
if !check || err != nil {
t.Fatalf("djProof failed to generate properly for left side\n")
}
t.Logf("Passed \n [testing] Second djProof : ")
check, err = djProofRIGHT.Verify(TestCurve, Base1, Result1, Base2, Result2)
if !check || err != nil {
t.Fatalf("djProof failed to generate properly for right side\n")
}
t.Logf("Passed \n [testing] Next djProof attempt should result in an error message\n")
_, status3 := NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, y, Left) // This should fail
if status3 == nil {
t.Fatalf("TestDisjunctive - incorrect error message for incorrect proof, case 3\n")
}
}
func TestDisjuncSerialization(t *testing.T) {
value, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
randVal, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
Base1 := TestCurve.G
Result1 := TestCurve.Mult(Base1, value)
Base2 := TestCurve.H
Result2 := TestCurve.Mult(Base2, randVal)
proof, _ := NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, value, Left)
proof, err := NewDisjunctiveProofFromBytes(proof.Bytes())
if err != nil {
t.Fatalf("TestDisjuncSerialization failed to deserialize\n")
}
ok, err := proof.Verify(TestCurve, Base1, Result1, Base2, Result2)
if !ok || err != nil {
t.Fatalf("TestDisjuncSerialization failed to verify\n")
}
}
func BenchmarkDisjuncProve_LEFT(b *testing.B) {
value, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
randVal, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
Base1 := TestCurve.G
Result1 := TestCurve.Mult(Base1, value)
Base2 := TestCurve.H
Result2 := TestCurve.Mult(Base2, randVal)
b.ResetTimer()
for ii := 0; ii < b.N; ii++ {
NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, value, Left)
}
}
func BenchmarkDisjuncProve_RIGHT(b *testing.B) {
value, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
randVal, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
Base1 := TestCurve.G
Result1 := TestCurve.Mult(Base1, value)
Base2 := TestCurve.H
Result2 := TestCurve.Mult(Base2, randVal)
b.ResetTimer()
for ii := 0; ii < b.N; ii++ {
NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, randVal, Right)
}
}
func BenchmarkDisjuncVerify_LEFT(b *testing.B) {
value, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
randVal, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
Base1 := TestCurve.G
Result1 := TestCurve.Mult(Base1, value)
Base2 := TestCurve.H
Result2 := TestCurve.Mult(Base2, randVal)
proof, _ := NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, value, Left)
b.ResetTimer()
for ii := 0; ii < b.N; ii++ {
proof.Verify(TestCurve, Base1, Result1, Base2, Result2)
}
}
func BenchmarkDisjuncVerify_RIGHT(b *testing.B) {
value, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
randVal, _ := rand.Int(rand.Reader, TestCurve.C.Params().N)
Base1 := TestCurve.G
Result1 := TestCurve.Mult(Base1, value)
Base2 := TestCurve.H
Result2 := TestCurve.Mult(Base2, randVal)
proof, _ := NewDisjunctiveProof(TestCurve, Base1, Result1, Base2, Result2, randVal, Right)
b.ResetTimer()
for ii := 0; ii < b.N; ii++ {
proof.Verify(TestCurve, Base1, Result1, Base2, Result2)
}
}