# beacon_chain # Copyright (c) 2018-2019 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, stew/endians2, chronicles, eth/trie/[db], ../beacon_chain/[beacon_chain_db, block_pool, extras, ssz, state_transition, validator_pool, beacon_node_types], ../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator] func preset*(): string = " [Preset: " & const_preset & ']' when ValidatorPrivKey is BlsValue: func makeFakeValidatorPrivKey*(i: int): ValidatorPrivKey = # 0 is not a valid BLS private key - 1000 helps interop with rust BLS library, # lighthouse. # TODO: switch to https://github.com/ethereum/eth2.0-pm/issues/60 result.kind = BlsValueType.Real var bytes = uint64(i + 1000).toBytesLE() copyMem(addr result.blsValue.x[0], addr bytes[0], sizeof(bytes)) else: func makeFakeValidatorPrivKey*(i: int): ValidatorPrivKey = # 0 is not a valid BLS private key - 1000 helps interop with rust BLS library, # lighthouse. # TODO: switch to https://github.com/ethereum/eth2.0-pm/issues/60 var bytes = uint64(i + 1000).toBytesLE() copyMem(addr result.x[0], addr bytes[0], sizeof(bytes)) func makeFakeHash*(i: int): Eth2Digest = var bytes = uint64(i).toBytesLE() static: doAssert sizeof(bytes) <= sizeof(result.data) copyMem(addr result.data[0], addr bytes[0], sizeof(bytes)) func hackPrivKey(v: Validator): ValidatorPrivKey = ## Extract private key, per above hack var bytes: array[8, byte] static: doAssert sizeof(bytes) <= sizeof(v.withdrawal_credentials.data) copyMem( addr bytes, unsafeAddr v.withdrawal_credentials.data[0], sizeof(bytes)) let i = int(uint64.fromBytesLE(bytes)) makeFakeValidatorPrivKey(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 = makeFakeValidatorPrivKey(i) pubkey = privkey.pubKey() withdrawal_credentials = makeFakeHash(i) domain = compute_domain(DOMAIN_DEPOSIT) result = Deposit( data: DepositData( pubkey: pubkey, withdrawal_credentials: withdrawal_credentials, amount: MAX_EFFECTIVE_BALANCE, ) ) if skipValidation notin flags: result.data.signature = bls_sign(privkey, signing_root(result.data).data, domain) func makeInitialDeposits*( n = SLOTS_PER_EPOCH, flags: UpdateFlags = {}): seq[Deposit] = for i in 0..