From eba0aa649d7c383173a90b6f4c5210db3b03e6f6 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Sun, 30 Jan 2022 01:26:16 -0600 Subject: [PATCH] new ttl range checking --- CHANGELOG.md | 5 +++++ onionrblocks/generators/anonvdf.py | 12 ++++++++++++ setup.py | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3437f98..7f773ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ This project uses Semantic Versioning +## 7.0.0 + +- Have minimum and maximum TTL allowance to avoid overflow/nonsense + + ## 6.0.0 - Use TTL instead of rounds diff --git a/onionrblocks/generators/anonvdf.py b/onionrblocks/generators/anonvdf.py index b5f9c2c..512a653 100644 --- a/onionrblocks/generators/anonvdf.py +++ b/onionrblocks/generators/anonvdf.py @@ -16,6 +16,12 @@ class NotEnoughRounds(Exception): class NoTTLSet(Exception): pass +class RoundsOutOfBounds(Exception): + pass + +MAX_ROUNDS = 999_999_999 +MINIMUM_ROUNDS = 10_000 + class AnonVDFGenerator(generator.KastenBaseGenerator): @@ -50,6 +56,10 @@ class AnonVDFGenerator(generator.KastenBaseGenerator): raise NoTTLSet(e) rounds = AnonVDFGenerator.get_rounds_for_ttl_seconds(ttl, len(packed_bytes)) + + if rounds > MAX_ROUNDS or rounds < MINIMUM_ROUNDS: + raise RoundsOutOfBounds() + check_block_sanity(packed_bytes) vdf = vdf_create( packed_bytes, @@ -74,6 +84,8 @@ class AnonVDFGenerator(generator.KastenBaseGenerator): ttl = int(ttl) rounds = AnonVDFGenerator.get_rounds_for_ttl_seconds(ttl, len(packed_bytes)) + if rounds > MAX_ROUNDS or rounds < MINIMUM_ROUNDS: + raise RoundsOutOfBounds() #hash = hash.lstrip(b"0") diff --git a/setup.py b/setup.py index 2164667..cf3d1f0 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='onionrblocks', - version='6.0.0', + version='7.0.0', description='Onionr message format', author='Kevin Froman', author_email='beardog@mailbox.org',