Skip to content

Commit

Permalink
Merge pull request taurushq-io#111 from adr1anh/zkmod-fix
Browse files Browse the repository at this point in the history
Fix challenge generation for zkmod
  • Loading branch information
veorq authored Oct 30, 2023
2 parents 5d4dc77 + 13391a2 commit 4d84aaf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/zk/mod/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ func (p *Proof) Verify(public Public, hash *hash.Hash, pl *pool.Pool) bool {
func challenge(hash *hash.Hash, n *saferith.Modulus, w *big.Int) (es []*saferith.Nat, err error) {
err = hash.WriteAny(n, w)
es = make([]*saferith.Nat, params.StatParam)
var digest = hash.Digest()
for i := range es {
es[i] = sample.ModN(hash.Digest(), n)
es[i] = sample.ModN(digest, n)
}
return
}
17 changes: 17 additions & 0 deletions pkg/zk/mod/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ func Test_set4thRoot(t *testing.T) {
assert.True(t, root.Eq(y) == 1, "root^4 should be equal to y")
}

func Test_hashFix(t *testing.T) {
N := zk.ProverPaillierSecret.N()
w := sample.QNR(rand.Reader, N).Big()
h := hash.New()
es, err := challenge(h, N, w)
assert.NoError(t, err, "failed to compute challenge")

allEqual := true
for _, e := range es {
if !(e.Eq(es[0]) == 1) {
allEqual = false
}
}

assert.False(t, allEqual, "all challenges should be different")
}

var proof *Proof

func BenchmarkCRT(b *testing.B) {
Expand Down

0 comments on commit 4d84aaf

Please sign in to comment.