aboutsummaryrefslogtreecommitdiff
path: root/nizk/stage1_test.go
blob: 3a1fac33f1359375b2e4b0651fd1dd92216cc868 (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
45
46
47
48
49
50
51
52
package nizk

import (
	"testing"

	. "kesim.org/seal/common"
)

func TestStage1(t *testing.T) {
	b1 := NewBit(true)
	b2 := NewBit(false)
	st1 := b1.Stage1()
	st2 := b2.Stage1()

	c1, pr1 := st1.Commit()
	c2, pr2 := st2.Commit()
	if !c1.Verify(pr1) {
		t.Fatal("Could not verify st1 with c1 and pr1, plus=true case")
	}
	if !c2.Verify(pr2) {
		t.Fatal("Could not verify st2 with c2 and pr2, plus=false case")
	}
	// Wrong proof test
	if c1.Verify(pr2) {
		t.Fatal("Shouldn't be able to verify c1 with pr2")
	}
}

func TestStage1FromScalars(t *testing.T) {
	var x, y, r, α, β *Scalar
	for _, s := range []**Scalar{&x, &y, &r, &α, &β} {
		*s = Curve.RandomScalar()
	}

	b1 := NewBitFromScalars(true, α, β)
	b2 := NewBitFromScalars(false, α, β)
	st1 := b1.Stage1FromScalars(x, y, r)
	st2 := b2.Stage1FromScalars(x, y, r)

	c1, pr1 := st1.Commit()
	c2, pr2 := st2.Commit()
	if !c1.Verify(pr1) {
		t.Fatal("Could not verify st1 with c1 and pr1, plus=true case")
	}
	if !c2.Verify(pr2) {
		t.Fatal("Could not verify st2 with c2 and pr2, plus=false case")
	}
	// Wrong proof test
	if c1.Verify(pr2) {
		t.Fatal("Shouldn't be able to verify c1 with pr2")
	}
}