Skip to content

Commit

Permalink
Benchmark RLN proof generation/verification (#2410)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Feb 9, 2024
1 parent 2d46c35 commit e600203
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ wakunode2: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims

benchmarks: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim benchmarks $(NIM_PARAMS) waku.nims

testwakunode2: | build deps librln
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim testwakunode2 $(NIM_PARAMS) waku.nims
Expand Down
47 changes: 47 additions & 0 deletions apps/benchmarks/benchmarks.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import
math,
std/sequtils,
stew/results,
options,
../../waku/waku_rln_relay/protocol_types,
../../waku/waku_rln_relay/rln,
../../waku/waku_rln_relay,
../../waku/waku_rln_relay/conversion_utils,
../../waku/waku_rln_relay/group_manager/static/group_manager

import std/[times, os]

proc main(): Future[string] {.async, gcsafe.} =
let rlnIns = createRLNInstance(20).get()
let credentials = toSeq(0 .. 1000).mapIt(membershipKeyGen(rlnIns).get())

let manager = StaticGroupManager(
rlnInstance: rlnIns,
groupSize: 1000,
membershipIndex: some(MembershipIndex(900)),
groupKeys: credentials,
)

await manager.init()

let data: seq[byte] = newSeq[byte](1024)

var proofGenTimes: seq[times.Duration] = @[]
var proofVerTimes: seq[times.Duration] = @[]
for i in 0 .. 50:
var time = getTime()
let proof = manager.generateProof(data, getCurrentEpoch()).get()
proofGenTimes.add(getTime() - time)

time = getTime()
let res = manager.verifyProof(data, proof).get()
proofVerTimes.add(getTime() - time)

echo "Proof generation times: ", sum(proofGenTimes) div len(proofGenTimes)
echo "Proof verification times: ", sum(proofVerTimes) div len(proofVerTimes)

when isMainModule:
try:
waitFor(main())
except CatchableError as e:
raise e
4 changes: 4 additions & 0 deletions waku.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ task wakunode2, "Build Waku v2 cli node":
let name = "wakunode2"
buildBinary name, "apps/wakunode2/"

task benchmarks, "Some benchmarks":
let name = "benchmarks"
buildBinary name, "apps/benchmarks/"

task wakucanary, "Build waku-canary tool":
let name = "wakucanary"
buildBinary name, "apps/wakucanary/"
Expand Down

0 comments on commit e600203

Please sign in to comment.