draft test and benchmark code for BLS PoS

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2021-09-19 18:54:28 +02:00 committed by Dmitriy Ryajov
parent 5ee331ac75
commit c52b3ac30a
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,8 @@
import times, strutils
template benchmark*(benchmarkName: string, code: untyped) =
let t0 = epochTime()
code
let elapsed = epochTime() - t0
let elapsedStr = elapsed.formatFloat(format = ffDecimal, precision = 3)
echo "CPU Time [", benchmarkName, "] ", elapsedStr, "s"

View File

@ -0,0 +1,36 @@
## Nim-POS
## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
## at your option.
## This file may not be copied, modified, or distributed except according to
## those terms.
import bls
import random
import benchmark
import strutils
proc testbls() : bool =
benchmark "Key generation":
let (spk, ssk) = bls.keygen()
benchmark "Auth generation":
let (tau, authenticators) = bls.st(ssk, "example.txt")
#echo "Auth: ", authenticators
benchmark "Generating challenge...":
let q = bls.generateQuery(tau, spk)
#echo "Generated!" #, " q:", q
benchmark "Issuing proof...":
let (mu, sigma) = bls.generateProof(q, authenticators, spk, "example.txt")
#echo "Issued!" #, " mu:", mu, " sigma:", sigma
benchmark "Verifying proof...":
result = bls.verifyProof(tau, q, mu, sigma, spk)
echo "Result: ", result
randomize()
let r = testbls()