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
|
package nizk
import (
"testing"
. "kesim.org/seal/common"
)
func TestStage2Simple1(t *testing.T) {
id := Curve.RandomScalar()
for _, lost := range []bool{true, false} {
b1, _, _ := NewBit(id, !lost)
c1 := b1.StageCommit()
r1, _ := b1.RevealStage1()
// Because the first index is a junction, any subsequent
// combination of Bits must verify with 'lost' set to true
// in the RevealStage2 calls.
for _, s := range [][2]bool{
{false, false},
{true, false},
{false, true},
{true, true},
} {
b2, bc2, _ := NewBit(id, s[0])
b3, bc3, _ := NewBit(id, s[1])
b4, bc4, _ := NewBit(id, s[1]) // same as b3
c2 := b2.StageCommit()
c3 := b3.StageCommit()
c4 := b4.StageCommit()
r2, p2 := b2.RevealStage2(lost, b1)
if !bc2.VerifyStage2(c1, c2, r1, r2, p2) {
t.Fatalf("failed to verify b2: %t b3: %t bc2/b1", s[0], s[1])
}
r3, p3 := b3.RevealStage2(lost, b1)
if !bc3.VerifyStage2(c1, c3, r1, r3, p3) {
t.Fatalf("failed to verify b1: %t b3: %t bc3/b1", s[0], s[1])
}
r4, p4 := b4.RevealStage2(lost, b1)
if !bc4.VerifyStage2(c1, c4, r1, r4, p4) {
t.Fatalf("failed to verify b1: %t b4: %t bc4/b1", s[0], s[1])
}
}
}
}
|