2018-12-19 12:58:53 +00:00
|
|
|
import
|
2019-07-31 09:39:46 +00:00
|
|
|
os, ospaths, strutils, strformat, json,
|
2019-07-12 14:24:11 +00:00
|
|
|
chronos, blscurve, nimcrypto, json_serialization, confutils, web3, stint,
|
2019-02-14 22:03:45 +00:00
|
|
|
spec/[datatypes, digest, crypto], conf, time, ssz,
|
2018-12-19 12:58:53 +00:00
|
|
|
../tests/testutil
|
|
|
|
|
2019-07-12 14:24:11 +00:00
|
|
|
contract(DepositContract):
|
|
|
|
proc deposit(pubkey: Bytes48, withdrawalCredentials: Bytes32, signature: Bytes96)
|
|
|
|
|
2019-03-18 03:54:08 +00:00
|
|
|
proc writeTextFile(filename: string, contents: string) =
|
|
|
|
writeFile(filename, contents)
|
|
|
|
echo "Wrote ", filename
|
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
proc writeFile(filename: string, value: auto) =
|
|
|
|
Json.saveFile(filename, value, pretty = true)
|
2018-12-28 16:51:40 +00:00
|
|
|
echo "Wrote ", filename
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-07-12 14:24:11 +00:00
|
|
|
|
|
|
|
proc ethToWei(eth: UInt256): UInt256 =
|
|
|
|
eth * 1000000000000000000.u256
|
|
|
|
|
|
|
|
proc main(totalValidators: int, outputDir: string, generateFakeKeys: bool, depositWeb3Url, depositContractAddress: string) {.async.} =
|
|
|
|
var web3: Web3
|
|
|
|
var contractAddress: Address
|
|
|
|
var eth1Addresses: seq[Address]
|
|
|
|
|
|
|
|
if depositWeb3Url.len > 0:
|
2019-07-31 09:39:46 +00:00
|
|
|
web3 = await newWeb3(depositWeb3Url)
|
2019-07-12 14:24:11 +00:00
|
|
|
contractAddress = Address.fromHex(depositContractAddress)
|
|
|
|
eth1Addresses = await web3.provider.eth_accounts()
|
2019-02-15 16:33:32 +00:00
|
|
|
|
2019-03-27 12:06:06 +00:00
|
|
|
for i in 0 ..< totalValidators:
|
2019-03-07 13:59:28 +00:00
|
|
|
let
|
2019-03-18 03:54:08 +00:00
|
|
|
v = validatorFileBaseName(i)
|
|
|
|
depositFn = outputDir / v & ".deposit.json"
|
|
|
|
privKeyFn = outputDir / v & ".privkey"
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-03-07 13:59:28 +00:00
|
|
|
if existsFile(depositFn) and existsFile(privKeyFn):
|
|
|
|
continue
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-03-07 13:59:28 +00:00
|
|
|
let
|
2019-03-18 03:54:08 +00:00
|
|
|
privKey = if generateFakeKeys: makeFakeValidatorPrivKey(i)
|
|
|
|
else: ValidatorPrivKey.random
|
2019-03-07 13:59:28 +00:00
|
|
|
pubKey = privKey.pubKey()
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2018-12-28 16:51:40 +00:00
|
|
|
let
|
|
|
|
withdrawalCredentials = makeFakeHash(i)
|
2019-05-09 12:27:37 +00:00
|
|
|
domain = 3'u64
|
2018-12-28 16:51:40 +00:00
|
|
|
|
2019-05-09 12:27:37 +00:00
|
|
|
var
|
2019-07-12 14:24:11 +00:00
|
|
|
dp = Deposit(
|
2019-05-09 12:27:37 +00:00
|
|
|
data: DepositData(
|
2019-04-29 16:48:30 +00:00
|
|
|
amount: MAX_EFFECTIVE_BALANCE,
|
2019-05-09 12:27:37 +00:00
|
|
|
pubkey: pubKey,
|
2019-06-14 16:21:04 +00:00
|
|
|
withdrawal_credentials: withdrawalCredentials))
|
2019-05-09 12:27:37 +00:00
|
|
|
|
2019-07-12 14:24:11 +00:00
|
|
|
dp.data.signature =
|
|
|
|
bls_sign(privkey, signing_root(dp.data).data,
|
2019-05-09 12:27:37 +00:00
|
|
|
domain)
|
2019-03-07 13:59:28 +00:00
|
|
|
|
2019-03-18 03:54:08 +00:00
|
|
|
writeTextFile(privKeyFn, $privKey)
|
2019-07-12 14:24:11 +00:00
|
|
|
writeFile(depositFn, dp)
|
|
|
|
|
|
|
|
if not web3.isNil:
|
2019-08-06 08:57:45 +00:00
|
|
|
web3.defaultAccount = eth1Addresses[i]
|
|
|
|
let depositContract = web3.contractSender(DepositContract, contractAddress)
|
|
|
|
let tx = await depositContract.deposit(Bytes48(pubKey.getBytes()), Bytes32(withdrawalCredentials.data), Bytes96(dp.data.signature.getBytes())).send(value = 32.u256.ethToWei)
|
2019-03-07 13:59:28 +00:00
|
|
|
|
2019-03-18 03:54:08 +00:00
|
|
|
if generateFakeKeys:
|
|
|
|
echo "Keys generated by this tool are only for testing!"
|
2019-07-12 14:24:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
cli do (totalValidators: int = 125000,
|
|
|
|
outputDir: string = "validators",
|
|
|
|
generateFakeKeys = false,
|
|
|
|
depositWeb3Url: string = "",
|
|
|
|
depositContractAddress: string = ""):
|
|
|
|
|
|
|
|
waitFor main(totalValidators, outputDir, generateFakeKeys, depositWeb3Url, depositContractAddress)
|