nimbus-eth2/beacon_chain/validator_keygen.nim
Dustin Brody e9180c490e
more 0.7.0 updates (#287)
* update Deposit and BeaconBlockHeader to 0.7.0

* update get_total_balance(...) and get_base_reward(...) to 0.7.0

* rename initial value constant BLS_WITHDRAWAL_PREFIX_BYTE to BLS_WITHDRAWAL_PREFIX

* mark minimal presets as entirely migrated to 0.7.0; update process_rewards_and_penalties(...) to 0.7.0

* specify that targeting 0.7.0; adopt 0.7.0 refactoring of bls_domain/get_domain to update get_domain(...) to 0.7.0; mark that mainnet constant presets and block header processing are 0.7.0-consistent; update process_justification_and_finalization to 0.7.0 to fix potential underflow errors

* address mratsim's comment to copy whole spec comment
2019-06-14 16:21:04 +00:00

53 lines
1.4 KiB
Nim

import
os, ospaths, strutils, strformat,
chronos, blscurve, nimcrypto, json_serialization, confutils,
spec/[datatypes, digest, crypto], conf, time, ssz,
../tests/testutil
proc writeTextFile(filename: string, contents: string) =
writeFile(filename, contents)
echo "Wrote ", filename
proc writeFile(filename: string, value: auto) =
Json.saveFile(filename, value, pretty = true)
echo "Wrote ", filename
cli do (totalValidators: int = 125000,
outputDir: string = "validators",
generateFakeKeys = false):
for i in 0 ..< totalValidators:
let
v = validatorFileBaseName(i)
depositFn = outputDir / v & ".deposit.json"
privKeyFn = outputDir / v & ".privkey"
if existsFile(depositFn) and existsFile(privKeyFn):
continue
let
privKey = if generateFakeKeys: makeFakeValidatorPrivKey(i)
else: ValidatorPrivKey.random
pubKey = privKey.pubKey()
let
withdrawalCredentials = makeFakeHash(i)
domain = 3'u64
var
deposit = Deposit(
data: DepositData(
amount: MAX_EFFECTIVE_BALANCE,
pubkey: pubKey,
withdrawal_credentials: withdrawalCredentials))
deposit.data.signature =
bls_sign(privkey, signing_root(deposit.data).data,
domain)
writeTextFile(privKeyFn, $privKey)
writeFile(depositFn, deposit)
if generateFakeKeys:
echo "Keys generated by this tool are only for testing!"