From 0b98e24552610b916e48db20d66f19efb4730684 Mon Sep 17 00:00:00 2001 From: "Roland C. Dowdeswell" Date: Thu, 10 Feb 2022 20:21:49 +0000 Subject: [PATCH] utils/faucet.py: fix determinism issue w/ PRNG Fixes #363 --- utils/faucet-gen.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/faucet-gen.py b/utils/faucet-gen.py index 38d7729a8..82ac3c18c 100755 --- a/utils/faucet-gen.py +++ b/utils/faucet-gen.py @@ -77,6 +77,12 @@ def make_dummy_wallets(n, blind): amounts = [ i / sum(amounts) * 700e6 for i in amounts ] wallets = {} secrets = {} + # initialize random functions so that we generate a determistic + # set of keys based on the seed passed in. We wait until after + # we have set the balances for compatibility with older code. + # This is also the reason that we consume an int to start. + random.seed(a=blind, version=2) + random.randint(0,2**32) for i in range(0, n): entropy = blake2b(str(i).encode('utf-8'), 20, key=blind).digest() mnemonic = m.to_mnemonic(entropy).split(' ') @@ -103,8 +109,6 @@ def make_dummy_wallets(n, blind): if __name__ == '__main__': print(f"Seed is {args.seed}") blind = args.seed.encode('utf-8') - # initialize random functions for determinism - random.seed(a=blind, version=2) wallets, secrets = make_dummy_wallets(args.number_of_accounts, blind) commitments = genesis_commitments(wallets, blind)