package nizk import ( "testing" . "kesim.org/seal/common" ) func TestStatement(t *testing.T) { id := Curve.RandomScalar() st1, st2 := NewBit(id, true), NewBit(id, false) c1, p1 := st1.Commit() c2, p2 := st2.Commit() 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() st1, st2 := NewBitFromScalars(id, true, α, β), NewBitFromScalars(id, false, α, β) c1, p1 := st1.Commit() c2, p2 := st2.Commit() 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!") } }