diff options
author | Özgür Kesim <oec@codeblau.de> | 2024-11-12 13:24:51 +0100 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2024-11-12 13:24:51 +0100 |
commit | e71b7a107b5441e7fa05366bf866cf223c649e7a (patch) | |
tree | a85301a4f22c8834e8d7892c92b0603565df840b /nizk/commit_test.go | |
parent | 023e460a8729e28bb398948f3279c58e38712cb8 (diff) |
refactor: make Bit and Stage1 more composable
Diffstat (limited to 'nizk/commit_test.go')
-rw-r--r-- | nizk/commit_test.go | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/nizk/commit_test.go b/nizk/commit_test.go index 061a772..3d65aa4 100644 --- a/nizk/commit_test.go +++ b/nizk/commit_test.go @@ -8,41 +8,50 @@ import ( func TestStatement(t *testing.T) { id := Curve.RandomScalar() - Id := G.Exp(id) - st1, st2 := NewBit(true), NewBit(false) - c1, p1 := st1.Commit(Id) - c2, p2 := st2.Commit(Id) - if !c1.Verify(p1) { + 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(p2) { + if !c2.Verify(id, p2) { t.Fatal("Could not verify st2 with c2, plus=false case") } // Use the wrong proof - if c2.Verify(p1) { + 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() - Id := G.Exp(id) - - st1, st2 := NewBitFromScalars(true, α, β), NewBitFromScalars(false, α, β) - c1, p1 := st1.Commit(Id) - c2, p2 := st2.Commit(Id) - if !c1.Verify(p1) { + 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(p2) { + if !c2.Verify(id, p2) { t.Fatal("Could not verify st2 with c2, plus=false case") } // Use the wrong proof - if c2.Verify(p1) { + 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!") + } } |