From c6cd47a5dd27e972df5901cb8bdc8793f4832597 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 29 Apr 2021 12:57:40 +1200 Subject: [PATCH] Fix Rand.u8() to return unsigned integers Existing test vector generators are adjusted to use Rand.i8() so they generate the same test vectors. We should evaluate these later to determine whether they should actually use Rand.u8() (and update the test vectors across the ecosystem). --- transaction.py | 12 ++++++------ tv_rand.py | 5 ++++- zip_0143.py | 2 +- zip_0243.py | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/transaction.py b/transaction.py index 7a2582b..aa3ca64 100644 --- a/transaction.py +++ b/transaction.py @@ -155,7 +155,7 @@ RAND_OPCODES = [ class Script(object): def __init__(self, rand): self._script = bytes([ - rand.a(RAND_OPCODES) for i in range(rand.u8() % 10) + rand.a(RAND_OPCODES) for i in range(rand.i8() % 10) ]) def raw(self): @@ -212,11 +212,11 @@ class Transaction(object): self.nVersion = rand.u32() & ((1 << 31) - 1) self.vin = [] - for i in range(rand.u8() % 3): + for i in range(rand.i8() % 3): self.vin.append(TxIn(rand)) self.vout = [] - for i in range(rand.u8() % 3): + for i in range(rand.i8() % 3): self.vout.append(TxOut(rand)) self.nLockTime = rand.u32() @@ -227,14 +227,14 @@ class Transaction(object): self.vShieldedSpends = [] self.vShieldedOutputs = [] if self.nVersion >= SAPLING_TX_VERSION: - for _ in range(rand.u8() % 5): + for _ in range(rand.i8() % 5): self.vShieldedSpends.append(SpendDescription(rand)) - for _ in range(rand.u8() % 5): + for _ in range(rand.i8() % 5): self.vShieldedOutputs.append(OutputDescription(rand)) self.vJoinSplit = [] if self.nVersion >= 2: - for i in range(rand.u8() % 3): + for i in range(rand.i8() % 3): self.vJoinSplit.append(JoinSplit(rand, self.fOverwintered and self.nVersion >= SAPLING_TX_VERSION)) if len(self.vJoinSplit) > 0: self.joinSplitPubKey = rand.b(32) # Potentially invalid diff --git a/tv_rand.py b/tv_rand.py index 3035286..e064332 100644 --- a/tv_rand.py +++ b/tv_rand.py @@ -12,9 +12,12 @@ class Rand(object): def v(self, l, f): return struct.unpack(f, self.b(l))[0] - def u8(self): + def i8(self): return self.v(1, 'b') + def u8(self): + return self.v(1, 'B') + def u32(self): return self.v(4, '