package nizk import ( "testing" . "kesim.org/seal/common" ) func TestStage2Simple1(t *testing.T) { id := Curve.RandomScalar() for _, lost := range []bool{true, false} { b1, _, _ := NewBit(id, !lost) c1 := b1.StageCommit() r1, _ := b1.RevealStage1() // Because the first index is a junction, any subsequent // combination of Bits must verify with 'lost' set to true // in the RevealStage2 calls. for _, s := range [][2]bool{ {false, false}, {true, false}, {false, true}, {true, true}, } { b2, bc2, _ := NewBit(id, s[0]) b3, bc3, _ := NewBit(id, s[1]) b4, bc4, _ := NewBit(id, s[1]) // same as b3 c2 := b2.StageCommit() c3 := b3.StageCommit() c4 := b4.StageCommit() r2, p2 := b2.RevealStage2(lost, b1) if !bc2.VerifyStage2(c1, c2, r1, r2, p2) { t.Fatalf("failed to verify b2: %t b3: %t bc2/b1", s[0], s[1]) } r3, p3 := b3.RevealStage2(lost, b1) if !bc3.VerifyStage2(c1, c3, r1, r3, p3) { t.Fatalf("failed to verify b1: %t b3: %t bc3/b1", s[0], s[1]) } r4, p4 := b4.RevealStage2(lost, b1) if !bc4.VerifyStage2(c1, c4, r1, r4, p4) { t.Fatalf("failed to verify b1: %t b4: %t bc4/b1", s[0], s[1]) } } } }