improved CPU profiling and added cli utility to calc rounds for given seconds
This commit is contained in:
parent
fe06c759cb
commit
26bad82e06
@ -2,9 +2,15 @@
|
||||
|
||||
<p align="center"><i>Simple <a href="https://eprint.iacr.org/2018/601.pdf">Verifiable Delay Function<a> using <a href="https://eprint.iacr.org/2016/492.pdf">MiMC</a></i></p>
|
||||
|
||||
## Applications
|
||||
|
||||
This module was created for use in reducing spam in a similar manner to [HashCash](https://en.wikipedia.org/wiki/Hashcash). However, some potential uses for VDFs include blockchains and verifiable lotteries.
|
||||
|
||||
|
||||
## Security
|
||||
|
||||
|
||||
This code has not been audited for security. It is not currently recommended for protecting against anything but denial of service, even though MiMC is able to do much more.
|
||||
This code has not been audited for security. It is not currently recommended for protecting against anything but denial of service, even though MiMC is able to do much more. If used, make sure it is not protecting anything critical.
|
||||
|
||||
In addition, since this is a Python implementation, attackers can be faster than typical users of an application by using faster language implementations or even FPGAs.
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
"""High level Verifiable Delay Function using keccak (sha3)."""
|
||||
from hashlib import sha3_256
|
||||
from typing import Union
|
||||
import timeit
|
||||
import time
|
||||
from statistics import mean
|
||||
from math import ceil
|
||||
|
||||
from .mimc import forward_mimc, reverse_mimc
|
||||
"""
|
||||
@ -45,5 +47,17 @@ def vdf_verify(
|
||||
hex(reverse_mimc(int(test_hash, 16), rounds)).replace('0x', '')
|
||||
|
||||
|
||||
def profile_cpu_speed(rounds=1000) -> float:
|
||||
return timeit.timeit(lambda: vdf_create(b"test", rounds), number=100)
|
||||
def profile_cpu_speed(rounds=1000, seconds=1) -> float:
|
||||
time_results = []
|
||||
for _ in range(10000):
|
||||
start = time.time()
|
||||
vdf_create(b"t", rounds)
|
||||
end = time.time()
|
||||
time_results.append(end - start)
|
||||
return (seconds / mean(time_results) * 1000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Calculate how may rounds are needed for X seconds (influenced by system processes): ")
|
||||
seconds = int(input("Seconds: "))
|
||||
print("Rounds:", ceil(profile_cpu_speed()))
|
||||
|
Loading…
Reference in New Issue
Block a user