2020-04-22 05:53:02 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
import
|
|
|
|
stew/endians2, stint,
|
2020-06-03 13:52:02 +00:00
|
|
|
./extras, ./ssz/merkleization,
|
2020-06-16 05:45:04 +00:00
|
|
|
spec/[crypto, datatypes, digest, keystore, signatures]
|
2019-09-01 15:02:49 +00:00
|
|
|
|
|
|
|
func get_eth1data_stub*(deposit_count: uint64, current_epoch: Epoch): Eth1Data =
|
|
|
|
# https://github.com/ethereum/eth2.0-pm/blob/e596c70a19e22c7def4fd3519e20ae4022349390/interop/mocked_eth1data/README.md
|
|
|
|
let
|
2020-03-14 21:54:45 +00:00
|
|
|
voting_period = current_epoch.uint64 div EPOCHS_PER_ETH1_VOTING_PERIOD
|
2019-09-01 15:02:49 +00:00
|
|
|
|
|
|
|
Eth1Data(
|
|
|
|
deposit_root: hash_tree_root(voting_period),
|
|
|
|
deposit_count: deposit_count,
|
|
|
|
block_hash: hash_tree_root(hash_tree_root(voting_period).data),
|
|
|
|
)
|
|
|
|
|
2020-06-01 19:48:20 +00:00
|
|
|
func makeInteropPrivKey*(i: int): ValidatorPrivKey =
|
2020-03-04 21:27:11 +00:00
|
|
|
var bytes: array[32, byte]
|
|
|
|
bytes[0..7] = uint64(i).toBytesLE()
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2020-03-04 21:27:11 +00:00
|
|
|
let
|
|
|
|
# BLS381-12 curve order - same as milagro but formatted different
|
|
|
|
curveOrder =
|
|
|
|
"52435875175126190479447740508185965837690552500527637822603658699938581184513".parse(UInt256)
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2020-06-16 12:16:43 +00:00
|
|
|
privkeyBytes = eth2digest(bytes)
|
2020-03-04 21:27:11 +00:00
|
|
|
key = (UInt256.fromBytesLE(privkeyBytes.data) mod curveOrder).toBytesBE()
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2020-06-01 19:48:20 +00:00
|
|
|
ValidatorPrivKey.fromRaw(key).get
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2019-09-02 10:31:14 +00:00
|
|
|
const eth1BlockHash* = block:
|
|
|
|
var x: Eth2Digest
|
|
|
|
for v in x.data.mitems: v = 0x42
|
|
|
|
x
|
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
func makeDeposit*(
|
2020-07-07 23:02:14 +00:00
|
|
|
preset: RuntimePreset,
|
2019-09-01 15:02:49 +00:00
|
|
|
pubkey: ValidatorPubKey, privkey: ValidatorPrivKey, epoch = 0.Epoch,
|
|
|
|
amount: Gwei = MAX_EFFECTIVE_BALANCE.Gwei,
|
2020-11-14 21:43:27 +00:00
|
|
|
flags: UpdateFlags = {}): DepositData =
|
|
|
|
result = DepositData(
|
|
|
|
amount: amount,
|
|
|
|
pubkey: pubkey,
|
|
|
|
withdrawal_credentials: makeWithdrawalCredentials(pubkey))
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2020-03-04 21:27:11 +00:00
|
|
|
if skipBLSValidation notin flags:
|
2020-11-14 21:43:27 +00:00
|
|
|
result.signature = preset.get_deposit_signature(result, privkey)
|
2019-09-01 15:02:49 +00:00
|
|
|
|