aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@kesim.org>2024-11-17 22:51:07 +0100
committerÖzgür Kesim <oec@kesim.org>2024-11-17 22:51:07 +0100
commita8e67420a980421c45b070d3d0aa8d848c3ffaca (patch)
tree365643b1acd04c3c1f0a41c94b274bf9411df3e6
parent1d1fc6f325ee72efc7dd8b0e0198b361d45ba5f1 (diff)
wip: vickrey variant test, fails
-rw-r--r--nizk/vickrey_test.go81
1 files changed, 67 insertions, 14 deletions
diff --git a/nizk/vickrey_test.go b/nizk/vickrey_test.go
index 99fb00c..69df365 100644
--- a/nizk/vickrey_test.go
+++ b/nizk/vickrey_test.go
@@ -20,7 +20,8 @@ func runVickrey(n int, bitlength int, tb testing.TB) {
}
max := slices.Max(vals)
max_idx := slices.Index(vals, max)
- if max_idx < len(vals)-1 && max == slices.Max(vals[max_idx+1:]) {
+ max2 := slices.Max(slices.Delete(vals, max_idx, max_idx+1))
+ if max == max2 {
max_idx = -1
}
@@ -48,6 +49,9 @@ func runVickrey(n int, bitlength int, tb testing.TB) {
xl := Curve.Identity()
for k := range n {
+ if k == winner {
+ continue
+ }
if k < i {
xu = xu.Mul(Xs[k])
} else if k > i {
@@ -79,15 +83,26 @@ func runVickrey(n int, bitlength int, tb testing.TB) {
for idx := range bitlength {
for i := range n {
+ if i == winner {
+ Xs[i] = Id
+ Zs[i] = Id
+ continue
+ }
c[i] = bits[i][idx].StageCommit()
Xs[i] = c[i].X
}
if instage1 {
var wg sync.WaitGroup
- wg.Add(n)
-
+ m := n
+ if winner >= 0 {
+ m -= 1
+ }
+ wg.Add(m)
for i := range n {
+ if i == winner {
+ continue
+ }
go func() {
r[i], p1[i] = bits[i][idx].RevealStage1(Xs...)
if !bits[i][idx].Commitment.VerifyStage1(c[i], r[i], p1[i]) {
@@ -100,33 +115,57 @@ func runVickrey(n int, bitlength int, tb testing.TB) {
wg.Wait()
Z := Curve.Product(Zs...)
+ reset := false
if !Id.Equal(Z) {
- junction = idx
- instage1 = false
- for i := range bits {
+ for i := range n {
+ if i == winner {
+ continue
+ }
if !lost[i] && !bits[i][idx].IsSet() {
lost[i] = true
}
// Winner test
if !lost[i] {
- isWinner(Z, i, idx)
+ reset = isWinner(Z, i, idx)
+ if reset {
+ Xs[i] = Id
+ Zs[i] = Id
+ }
}
}
- result |= 1 << (bitlength - 1 - idx)
+ if !reset {
+ result |= 1 << (bitlength - 1 - idx)
+ }
+ }
+ if !reset {
+ junction = idx
+ instage1 = false
}
continue
}
// Stage 2
- for i := range bits {
+ for i := range n {
+ if i == winner {
+ Xs[i] = Id
+ Zs[i] = Id
+ continue
+ }
bj[i] = bits[i][junction]
}
var wg sync.WaitGroup
- wg.Add(n)
+ m := n
+ if winner >= 0 {
+ m -= 1
+ }
+ wg.Add(m)
for i := range n {
+ if i == winner {
+ continue
+ }
go func() {
r[i], p2[i] = bits[i][idx].RevealStage2(lost[i], bj[i], Xs...)
if !bits[i][idx].Commitment.VerifyStage2(bj[i].StageCommitment, c[i], bj[i].StageReveal, r[i], p2[i]) {
@@ -139,19 +178,33 @@ func runVickrey(n int, bitlength int, tb testing.TB) {
wg.Wait()
Z := Curve.Product(Zs...)
+ reset := false
+
if !Id.Equal(Z) {
- junction = idx
for i := range n {
+ if i == winner {
+ continue
+ }
if !lost[i] && !bits[i][idx].IsSet() {
lost[i] = true
}
// Winner test
if !lost[i] && winner < 0 {
- isWinner(Z, i, idx)
+ reset = isWinner(Z, i, idx)
+ if reset {
+ Xs[i] = Id
+ Zs[i] = Id
+ }
}
}
- result |= 1 << (bitlength - 1 - idx)
+ if !reset {
+ result |= 1 << (bitlength - 1 - idx)
+ }
+
+ }
+ if !reset {
+ junction = idx
}
}
if result != max {
@@ -162,4 +215,4 @@ func runVickrey(n int, bitlength int, tb testing.TB) {
}
}
-func TestVickrey100on16bit(t *testing.T) { runVickrey(100, 16, t) }
+func TestVickrey100on16bit(t *testing.T) { runVickrey(3, 5, t) }