aboutsummaryrefslogtreecommitdiff
path: root/nizk/commit_test.go
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@kesim.org>2024-11-11 21:28:12 +0100
committerÖzgür Kesim <oec@kesim.org>2024-11-11 21:28:12 +0100
commit4adec77feea7e9ec45ca43084383d85de450518b (patch)
tree446ecf80204c6a1b755547e121f1f8450c99f6ae /nizk/commit_test.go
parent7813100e5429ca486d6310f8a04d7a0d11325f2e (diff)
refactoring in progress
Diffstat (limited to 'nizk/commit_test.go')
-rw-r--r--nizk/commit_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/nizk/commit_test.go b/nizk/commit_test.go
new file mode 100644
index 0000000..32d337b
--- /dev/null
+++ b/nizk/commit_test.go
@@ -0,0 +1,48 @@
+package nizk
+
+import (
+ "testing"
+
+ . "kesim.org/seal/common"
+)
+
+func TestStatement(t *testing.T) {
+ id := Curve.RandomScalar()
+ Id := G.Exp(id)
+
+ st1, st2 := NewBid(true), NewBid(false)
+ c1, p1 := st1.Commit(Id)
+ c2, p2 := st2.Commit(Id)
+ if !c1.Verify(p1) {
+ t.Fatal("Could not verify st1 with c1, plus=true case")
+ }
+ if !c2.Verify(p2) {
+ t.Fatal("Could not verify st2 with c2, plus=false case")
+ }
+
+ // Use the wrong proof
+ if c2.Verify(p1) {
+ 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 := NewBidFromScalars(true, α, β), NewBidFromScalars(false, α, β)
+ c1, p1 := st1.Commit(Id)
+ c2, p2 := st2.Commit(Id)
+ if !c1.Verify(p1) {
+ t.Fatal("Could not verify st1 with c1, plus=true case")
+ }
+ if !c2.Verify(p2) {
+ t.Fatal("Could not verify st2 with c2, plus=false case")
+ }
+
+ // Use the wrong proof
+ if c2.Verify(p1) {
+ t.Fatal("Verify with wrong proof should have failed!")
+ }
+}