# beacon_chain # Copyright (c) 2018 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. import options, sequtils, ../beacon_chain/[extras, ssz, state_transition, validator_pool], ../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator] func makeValidatorPrivKey(i: int): ValidatorPrivKey = var i = i + 1 # 0 does not work, as private key... copyMem(result.x[0].addr, i.addr, min(sizeof(result.x), sizeof(i))) func makeFakeHash*(i: int): Eth2Digest = copyMem(result.data[0].addr, i.unsafeAddr, min(sizeof(result.data), sizeof(i))) func hackPrivKey(v: Validator): ValidatorPrivKey = ## Extract private key, per above hack var i: int copyMem( i.addr, v.withdrawal_credentials.data[0].unsafeAddr, min(sizeof(v.withdrawal_credentials.data), sizeof(i))) makeValidatorPrivKey(i) func makeDeposit(i: int, flags: UpdateFlags): Deposit = ## Ugly hack for now: we stick the private key in withdrawal_credentials ## which means we can repro private key and randao reveal from this data, ## for testing :) let privkey = makeValidatorPrivKey(i) pubkey = privkey.pubKey() withdrawal_credentials = makeFakeHash(i) let pop = if skipValidation in flags: ValidatorSig() else: let proof_of_possession_data = DepositInput( pubkey: pubkey, withdrawal_credentials: withdrawal_credentials, ) let domain = 0'u64 bls_sign(privkey, hash_tree_root_final(proof_of_possession_data).data, domain) Deposit( deposit_data: DepositData( deposit_input: DepositInput( pubkey: pubkey, proof_of_possession: pop, withdrawal_credentials: withdrawal_credentials, ), amount: MAX_DEPOSIT_AMOUNT, ) ) func makeInitialDeposits*( n = EPOCH_LENGTH, flags: UpdateFlags = {}): seq[Deposit] = for i in 0..