Skip to content

Commit

Permalink
Merge pull request #33 from JohnLCaron/mathsFinal
Browse files Browse the repository at this point in the history
"Final" mixnet-maths
  • Loading branch information
JohnLCaron committed Jun 4, 2024
2 parents fd2fb43 + 0d5b57f commit 9a9d534
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Egk Elliptic Curves Mixnet

_last update 05/22/2024_
_last update 06/03/2024_

Implementation of a mixnet using the [ElectionGuard Kotlin Elliptical Curve library](https://github.com/JohnLCaron/egk-ec),
and the [Verificatum library](https://www.verificatum.org/). The mixnet uses the Terelius / Wikström (TW) mixnet
Expand Down
Binary file added docs/mixnet-maths-withnotes.zip
Binary file not shown.
Binary file modified docs/mixnet-maths.zip
Binary file not shown.
Binary file added docs/mixnet_maths-withnotes.pdf
Binary file not shown.
Binary file modified docs/mixnet_maths.pdf
Binary file not shown.
Binary file modified libs/egk-ec-2.1-SNAPSHOT.jar
Binary file not shown.
89 changes: 45 additions & 44 deletions src/test/kotlin/org/cryptobiotic/mixnet/ShuffleProofTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class ShuffleProofTest {
}

// values are millisecs
class Result(val nthreads: Int, val shuffle: Long, val proof: Long, val verify : Long) {
class Result(val nrows: Int, val nthreads: Int, val shuffle: Long, val proof: Long, val verify : Long) {
val total = (shuffle+proof+verify)
val scale = 1.0e-3

override fun toString() =
"${nthreads}, ${shuffle*scale}, ${proof*scale}, ${verify*scale}, ${total*scale}"
"${nrows}, ${nthreads}, ${shuffle*scale}, ${proof*scale}, ${verify*scale}, ${total*scale}"

fun toString3() =
"${nthreads}, ${shuffle + proof}, $verify"
Expand Down Expand Up @@ -122,7 +122,7 @@ class ShuffleProofTest {

val shuffleTime = getSystemTimeInMillis() - starting
println(" runShuffle nthreads = $nthreads time = $shuffleTime")
return Result(nthreads, shuffleTime, 0, 0)
return Result(ballots.size, nthreads, shuffleTime, 0, 0)
}

@Test
Expand All @@ -144,23 +144,6 @@ class ShuffleProofTest {
runShuffleProof(6, 9, showTiming = false)
}

@Test
fun testShuffleProofThreads() {
val nrows = 100
val width = 100
println("nrows=$nrows, width= $width per row, N=${nrows*width}, nthreads=16/14/12/10/8/6/4/2/1/0")
runShuffleProof(nrows, width, nthreads = 16)
runShuffleProof(nrows, width, nthreads = 14)
runShuffleProof(nrows, width, nthreads = 12)
runShuffleProof(nrows, width, nthreads = 10)
runShuffleProof(nrows, width, nthreads = 8)
runShuffleProof(nrows, width, nthreads = 6)
runShuffleProof(nrows, width, nthreads = 4)
runShuffleProof(nrows, width, nthreads = 2)
runShuffleProof(nrows, width, nthreads = 1)
runShuffleProof(nrows, width, nthreads = 0)
}

fun runShuffleProof(nrows: Int, width: Int, nthreads : Int = 10, showExps: Boolean = true, showTiming: Boolean = true) {
val stats = Stats()
val keypair = elGamalKeyPairFromRandom(group)
Expand Down Expand Up @@ -247,38 +230,56 @@ class ShuffleProofTest {

@Test
fun testSPVMatrix() {
runShuffleProofVerifyWithThreads(10, 34)
runShuffleProofVerifyWithThreads(100, 34)
// runShuffleProofVerifyWithThreads(1000, 34)
//runShuffleProofVerifyWithThreads(2000, 34)
val nthreads = listOf(1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 48)
val nrows = listOf(100, 500, 1000, 2000, 4000)
val results = mutableListOf<Result>()

for (nrow in nrows) {
runShuffleProofVerifyWithThreads(nrow, 34, nthreads, results)
}

print("\negk-ec-mixnet shuffle+proof X nrows (HP880) msecs per row\nnthreads, ")
nrows.forEach { print("$it, ") }
println()
nthreads.forEach { nt ->
print("$nt, ")
var count = 0
results.filter { it.nthreads == nt }.forEach {
require( it.nrows == nrows[count])
print("${(it.shuffle + it.proof).toDouble()/it.nrows}, ")
count++
}
println()
}
println()

print("\negk-ec-mixnet verify X nrows (HP880) msecs per row\nnthreads, ")
nrows.forEach { print("$it, ") }
println()
nthreads.forEach { n ->
print("$n, ")
var count = 0
results.filter { it.nthreads == n }.forEach {
require( it.nrows == nrows[count])
print("${it.verify.toDouble()/it.nrows}, ")
count++
}
println()
}
println()
}

fun runShuffleProofVerifyWithThreads(nrows: Int, width: Int) {
fun runShuffleProofVerifyWithThreads(nrows: Int, width: Int, nthreads: List<Int>, results: MutableList<Result>) {
println("=========================================")
println("testThreads nrows=$nrows, width= $width per row, N=${nrows*width}")
// println("nthreads, shuffle, proof, verify, total")

val keypair = elGamalKeyPairFromRandom(group)
val ballots = makeBallots(keypair, nrows, width)

val results = mutableListOf<Result>()
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 1))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 2))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 4))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 6))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 8))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 12))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 16))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 20))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 24))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 28))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 32))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 36))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 40))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 44))
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = 48))
println("\nnthreads, shuffle+proof, verify")
results.forEach{ println("${ it.toString3() }") }
for (n in nthreads) {
results.add(runShuffleProofAndVerify(nrows, width, keypair, ballots, nthreads = n))
}
}

fun runShuffleProofAndVerify(nrows: Int, width: Int, keypair: ElGamalKeypair, ballots: List<VectorCiphertext>,
Expand Down Expand Up @@ -330,7 +331,7 @@ class ShuffleProofTest {
assertTrue(valid)
if (showTiming) stats.show()

val r = Result(nthreads, shuffleTime, proofTime, verifyTime)
val r = Result(nrows, nthreads, shuffleTime, proofTime, verifyTime)
if (showTiming) println(r)
return r
}
Expand Down

0 comments on commit 9a9d534

Please sign in to comment.