aboutsummaryrefslogtreecommitdiff
path: root/nizk/commit/commit_test.go
blob: 4ea5964e2b4d51a89d26048801f319eadcda390e (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
package commit

import (
	"testing"

	. "kesim.org/seal/nizk"
)

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

	st1, st2 := NewStatement(true), NewStatement(false)
	c1, c2 := st1.Commit(Id), st2.Commit(Id)
	if !c1.Verify() {
		t.Fatal("Could not verify st1 with c1, plus=true case")
	}
	if !c2.Verify() {
		t.Fatal("Could not verify st2 with c2, plus=false case")
	}

	// Use the wrong proof
	c2.Proof = c1.Proof
	if c2.Verify() {
		t.Fatal("Verify with wrong proof should have failed!")
	}
}

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

	Id := G.Exp(id)

	st1, st2 := NewStatementFromScalars(true, α, β), NewStatementFromScalars(false, α, β)
	c1, c2 := st1.Commit(Id), st2.Commit(Id)
	if !c1.Verify() {
		t.Fatal("Could not verify st1 with c1, plus=true case")
	}
	if !c2.Verify() {
		t.Fatal("Could not verify st2 with c2, plus=false case")
	}

	// Use the wrong proof
	c2.Proof = c1.Proof
	if c2.Verify() {
		t.Fatal("Verify with wrong proof should have failed!")
	}
}