diff options
Diffstat (limited to 'nizk/stage2_test.go')
-rw-r--r-- | nizk/stage2_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nizk/stage2_test.go b/nizk/stage2_test.go new file mode 100644 index 0000000..9d3ebec --- /dev/null +++ b/nizk/stage2_test.go @@ -0,0 +1,51 @@ +package nizk + +import ( + "testing" + + . "kesim.org/seal/common" +) + +func TestVerification(t *testing.T) { + var st [3]*Stage2 + for i, typ := range []Type{None, Unset, Set} { + st[i] = NewStage2(typ) + c, p := st[i].Commit() + if !c.Verify(p) { + t.Fatalf("Couldn't verify proof for %v, case %d\n", typ, i) + } + } + + for _, ind := range [][2]int{{0, 1}, {1, 2}, {2, 0}} { + c1, p1 := st[ind[0]].Commit() + c2, p2 := st[ind[1]].Commit() + if c1.Verify(p2) || c2.Verify(p1) { + t.Fatalf("Shouldn't be able to verify %d with proof %d", ind[0], ind[1]) + } + } +} + +func TestVerificationFromScalar(t *testing.T) { + var s [8]*Scalar + var st [3]*Stage2 + + for i := range s { + s[i] = Curve.RandomScalar() + } + + for i, typ := range []Type{None, Unset, Set} { + st[i] = NewStage2FromScalars(typ, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7]) + c, p := st[i].Commit() + if !c.Verify(p) { + t.Fatalf("Couldn't verify proof for %v, case %d\n", typ, i) + } + } + + for _, ind := range [][2]int{{0, 1}, {1, 2}, {2, 1}, {2, 0}} { + c1, p1 := st[ind[0]].Commit() + c2, p2 := st[ind[1]].Commit() + if c1.Verify(p2) || c2.Verify(p1) { + t.Fatalf("Shouldn't be able to verify %d with proof %d", ind[0], ind[1]) + } + } +} |