aboutsummaryrefslogtreecommitdiff
path: root/nizk/commit_test.go
blob: a09ae702a3a92ec90753e9a39bc3b05fc07790f4 (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
53
54
55
56
57
package nizk

import (
	"testing"

	. "kesim.org/seal/common"
)

func TestStatement(t *testing.T) {
	id := Curve.RandomScalar()

	_, c1, p1 := NewBit(id, true)
	_, c2, p2 := NewBit(id, false)

	if !c1.Verify(id, p1) {
		t.Fatal("Could not verify st1 with c1, plus=true case")
	}
	if !c2.Verify(id, p2) {
		t.Fatal("Could not verify st2 with c2, plus=false case")
	}

	// Use the wrong proof
	if c2.Verify(id, p1) {
		t.Fatal("Verify with wrong proof should have failed!")
	}

	// Use wrong id
	x := Curve.RandomScalar()
	if c1.Verify(x, p1) || c2.Verify(x, p2) {
		t.Fatal("Verify with wrong id should have failed!")
	}
}

func TestStatementFromScalar(t *testing.T) {
	var α, β, id = Curve.RandomScalar(), Curve.RandomScalar(), Curve.RandomScalar()

	_, c1, p1 := NewBitFromScalars(id, true, α, β)
	_, c2, p2 := NewBitFromScalars(id, false, α, β)

	if !c1.Verify(id, p1) {
		t.Fatal("Could not verify st1 with c1, plus=true case")
	}
	if !c2.Verify(id, p2) {
		t.Fatal("Could not verify st2 with c2, plus=false case")
	}

	// Use the wrong proof
	if c2.Verify(id, p1) {
		t.Fatal("Verify with wrong proof should have failed!")
	}

	// Use the wrong Id
	x := Curve.RandomScalar()
	if c1.Verify(x, p1) || c2.Verify(x, p2) {
		t.Fatal("Verify with wrong id should have failed!")
	}
}