aboutsummaryrefslogtreecommitdiff
path: root/nizk/stage2_test.go
blob: cfd6e1374636e8ec119f3e8dc66d6237e4f45cc3 (plain)
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
package nizk

import (
	"fmt"
	"testing"

	. "kesim.org/seal/common"
)

func TestStage2Simple(t *testing.T) {
	id := Curve.RandomScalar()
	b1, _, _ := NewBit(id, false) // This is also the junction
	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])

		c2 := b2.StageCommit()
		c3 := b3.StageCommit()
		t.Run(fmt.Sprintf("variant %t %t b2.b1", s[0], s[1]), func(t *testing.T) {
			r2, p2 := b2.RevealStage2(true, b1) // We had lost previously
			if !bc2.VerifyStage2(c1, c2, r1, r2, p2) {
				t.Fatalf("failed to verify bc2")
			}
		})
		t.Run(fmt.Sprintf("variant %t %t, b3.b1", s[0], s[1]), func(t *testing.T) {
			r3, p3 := b3.RevealStage2(true, b1) // We had lost previously
			if !bc3.VerifyStage2(c1, c3, r1, r3, p3) {
				t.Fatalf("failed to verify bc3")
			}
		})
	}

}