From c4f349eedf5030643400e09cfc7bb339f1879fb1 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 20 Jan 2021 20:31:50 +0000 Subject: [PATCH] bump version with improved vdf metric --- CHANGELOG.md | 8 ++++++++ onionrblocks/__init__.py | 2 +- onionrblocks/generators/anonvdf.py | 29 ++++++++++++++++++++--------- onionrblocks/generators/signedby.py | 2 ++ setup.py | 4 ++-- tests/test_anonvdf.py | 17 +++++++++++++++-- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a79fdb..2d5ce60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ This project uses Semantic Versioning +## 1.0.0 + +* Bumped minimum VDF rounds to C implementation benchmark +* VDF ttl now uses metric based on disk+transfer prices +* Typo correction +* Enforce universalrules when checking either generators +* Added missing pynacl dependency + ## 0.0.0 Initial release diff --git a/onionrblocks/__init__.py b/onionrblocks/__init__.py index ff576a8..3983bd5 100644 --- a/onionrblocks/__init__.py +++ b/onionrblocks/__init__.py @@ -4,4 +4,4 @@ from binascii import hexlify import kasten - +from . import generators diff --git a/onionrblocks/generators/anonvdf.py b/onionrblocks/generators/anonvdf.py index 54bb0da..309a108 100644 --- a/onionrblocks/generators/anonvdf.py +++ b/onionrblocks/generators/anonvdf.py @@ -10,16 +10,25 @@ from onionrblocks.universalrules import check_block_sanity class AnonVDFGenerator(generator.KastenBaseGenerator): @classmethod - def get_ttl_seconds_per_rounds(cls, rounds: int): - # 8000 rounds = 1 second (2.8ghz python) = 1 hour storage - if rounds < 8000: + def get_ttl_seconds_per_rounds(cls, rounds: int, size_bytes: int): + # 90000 rounds = 1 second (2.8ghz C) = 1 hour storage of 1 MB storage + # jan 2021 disk price metric = 0.000017 USD per MB + # mobile MB transfer US/Canada = 0.0125 USD + # Max cost of block storage + American mobile data transfer = 0.0751 USD + + base = 90000 + per_byte = 1000 + minimum = base + (per_byte * size_bytes) + if rounds < minimum: raise ValueError( - "Rounds must be at least 8000") - return (rounds / 8000) * 60 + "Must be at least " + str(minimum) + " for " + str(size_bytes)) + + return (rounds / minimum) * 60 @classmethod def generate( - cls, packed_bytes: KastenPacked, rounds: int = 5000) -> Kasten: + cls, packed_bytes: KastenPacked, rounds: int = 90000) -> Kasten: + check_block_sanity(packed_bytes) return Kasten( vdf_create( packed_bytes, @@ -30,7 +39,9 @@ class AnonVDFGenerator(generator.KastenBaseGenerator): @staticmethod def validate_id( hash: KastenChecksum, - packed_bytes: KastenPacked, rounds=5000) -> None: + packed_bytes: KastenPacked, rounds=90000) -> None: + + check_block_sanity(packed_bytes) try: hash = int.from_bytes(hash, byteorder="big") @@ -42,9 +53,9 @@ class AnonVDFGenerator(generator.KastenBaseGenerator): test_obj = Kasten( None, packed_bytes, None, auto_check_generator=False) allowed_age_seconds = AnonVDFGenerator.get_ttl_seconds_per_rounds( - rounds) + rounds, len(packed_bytes)) if time.time() > test_obj.get_timestamp() + allowed_age_seconds: raise ValueError( - f"Block rounds only vaild through {allowed_age_seconds}") + f"Block rounds only valid through {allowed_age_seconds}") return None \ No newline at end of file diff --git a/onionrblocks/generators/signedby.py b/onionrblocks/generators/signedby.py index 7e21e35..ce83c00 100644 --- a/onionrblocks/generators/signedby.py +++ b/onionrblocks/generators/signedby.py @@ -8,6 +8,7 @@ from kasten.exceptions import InvalidID from kasten.types import KastenPacked, KastenChecksum from onionrblocks.customtypes import RawEd25519PrivateKey, RawEd25519PublicKey +from onionrblocks.universalrules import check_block_sanity class Signed(generator.KastenBaseGenerator): @@ -36,6 +37,7 @@ class Signed(generator.KastenBaseGenerator): hash: KastenChecksum, packed_bytes: KastenPacked, verify_key: Union[VerifyKey, RawEd25519PublicKey]) -> None: + check_block_sanity(packed_bytes) # Hash is 64 bytes message then 32 bytes of the hash of the packed_bytes if len(hash) != 86: raise InvalidID("Block not have proper signature length") diff --git a/setup.py b/setup.py index 1f33d6d..87dd9cd 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,13 @@ from setuptools import setup, find_packages setup(name='onionrblocks', - version='0.0.2', + version='1.0.0', description='Onionr message format', author='Kevin Froman', author_email='beardog@mailbox.org', url='', packages=find_packages(exclude=['contrib', 'docs', 'tests']), - install_requires=['kasten>=2.0.1'], + install_requires=['kasten>=2.0.1', 'pynacl>=1.4.0'], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", diff --git a/tests/test_anonvdf.py b/tests/test_anonvdf.py index 52379a4..358755c 100644 --- a/tests/test_anonvdf.py +++ b/tests/test_anonvdf.py @@ -19,17 +19,30 @@ class TestAnonVDF(unittest.TestCase): self.assertEqual(generated.id, int(test_vdf).to_bytes(64, byteorder="big")) def test_vdf_block_validate_ok_time(self): - rds = 8000 + rds = 90000 test_data = kasten.generator.pack.pack(b"test", "tst", 0) + rds += len(test_data) * 1000 test_id = mimcvdf.vdf_create(test_data, rds) anonvdf.AnonVDFGenerator.validate_id(test_id, test_data, rounds=rds) def test_vdf_block_validate_not_enough(self): - rds = 8000 + rds = 90000 t = floor(time()) - 60 test_data = kasten.generator.pack.pack(b"test", "tst", 0, timestamp=t) test_id = mimcvdf.vdf_create(test_data, rds) self.assertRaises(ValueError, anonvdf.AnonVDFGenerator.validate_id, test_id, test_data, rounds=rds) + def test_vdf_incermental(self): + last = 1 + for i in range(1, 20): + t = time() + rds = 90000 + test_data = kasten.generator.pack.pack(b"test" * i, "tst", 0) + rds += len(test_data) * 1000 + test_id = mimcvdf.vdf_create(test_data, rds) + anonvdf.AnonVDFGenerator.validate_id(test_id, test_data, rounds=rds) + newT = time() + self.assertGreater(newT - t, last) + unittest.main() \ No newline at end of file