parent
f2545318db
commit
072c1607fd
|
@ -210,7 +210,7 @@ proc proposeBlock(node: BeaconNode,
|
|||
var newBlock = BeaconBlock(
|
||||
slot: slot,
|
||||
parent_root: node.headBlockRoot,
|
||||
randao_reveal: ValidatorSig(), # TODO probably wrong
|
||||
randao_reveal: validator.genRandaoReveal(state),
|
||||
eth1_data: node.mainchainMonitor.getBeaconBlockRef(),
|
||||
signature: ValidatorSig(), # we need the rest of the block first!
|
||||
body: blockBody)
|
||||
|
|
|
@ -47,8 +47,7 @@ func process_deposit(state: var BeaconState,
|
|||
pubkey: ValidatorPubKey,
|
||||
amount: uint64,
|
||||
proof_of_possession: ValidatorSig,
|
||||
withdrawal_credentials: Eth2Digest,
|
||||
randao_commitment: Eth2Digest) =
|
||||
withdrawal_credentials: Eth2Digest) =
|
||||
## Process a deposit from Ethereum 1.0.
|
||||
|
||||
if false:
|
||||
|
@ -206,7 +205,6 @@ func get_initial_beacon_state*(
|
|||
deposit.deposit_data.amount,
|
||||
deposit.deposit_data.deposit_input.proof_of_possession,
|
||||
deposit.deposit_data.deposit_input.withdrawal_credentials,
|
||||
deposit.deposit_data.deposit_input.randao_commitment,
|
||||
)
|
||||
|
||||
# Process initial activations
|
||||
|
|
|
@ -252,7 +252,6 @@ type
|
|||
DepositInput* = object
|
||||
pubkey*: ValidatorPubKey
|
||||
withdrawal_credentials*: Eth2Digest
|
||||
randao_commitment*: Eth2Digest # Initial RANDAO commitment
|
||||
proof_of_possession*: ValidatorSig ##\
|
||||
## BLS proof of possession (a BLS signature)
|
||||
|
||||
|
|
|
@ -49,8 +49,7 @@ cli do (validators: int,
|
|||
|
||||
proofOfPossessionData = DepositInput(
|
||||
pubkey: pubKey,
|
||||
withdrawal_credentials: withdrawalCredentials,
|
||||
randao_commitment: randaoCommitment)
|
||||
withdrawal_credentials: withdrawalCredentials)
|
||||
|
||||
proofOfPossession = bls_sign(
|
||||
privkey, hash_tree_root_final(proofOfPossessionData).data,
|
||||
|
@ -64,8 +63,7 @@ cli do (validators: int,
|
|||
deposit_input: DepositInput(
|
||||
pubkey: pubKey,
|
||||
proof_of_possession: proofOfPossession,
|
||||
withdrawal_credentials: withdrawalCredentials,
|
||||
randao_commitment: randaoCommitment)))
|
||||
withdrawal_credentials: withdrawalCredentials)))
|
||||
|
||||
startupData.genesisTime = uint64(int(now() div 1000) + startupDelay)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import
|
||||
tables, random,
|
||||
chronos,
|
||||
spec/[datatypes, crypto, digest], randao, ssz
|
||||
spec/[datatypes, crypto, digest, helpers], randao, ssz
|
||||
|
||||
type
|
||||
ValidatorKind = enum
|
||||
|
@ -83,3 +83,17 @@ proc randaoReveal*(v: AttachedValidator, commitment: Eth2Digest): Future[Eth2Dig
|
|||
# send RPC
|
||||
discard
|
||||
|
||||
# TODO move elsewhere when something else wants this utility function
|
||||
func int_to_bytes32(x: uint64) : array[32, byte] =
|
||||
for i in 0 ..< 8:
|
||||
result[31 - i] = byte((x shr i*8) and 0xff)
|
||||
|
||||
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState):
|
||||
ValidatorSig =
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#randao
|
||||
bls_sign(k, int_to_bytes32(get_current_epoch(state)),
|
||||
get_domain(state.fork, get_current_epoch(state), DOMAIN_RANDAO))
|
||||
|
||||
func genRandaoReveal*(v: AttachedValidator, state: BeaconState):
|
||||
ValidatorSig =
|
||||
genRandaoReveal(v.privKey, state)
|
||||
|
|
|
@ -7,12 +7,9 @@
|
|||
|
||||
import
|
||||
options, sequtils,
|
||||
../beacon_chain/[extras, ssz, state_transition],
|
||||
../beacon_chain/[extras, ssz, state_transition, validator_pool],
|
||||
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator]
|
||||
|
||||
const
|
||||
randaoRounds = 100
|
||||
|
||||
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)))
|
||||
|
@ -36,7 +33,6 @@ func makeDeposit(i: int, flags: UpdateFlags): Deposit =
|
|||
privkey = makeValidatorPrivKey(i)
|
||||
pubkey = privkey.pubKey()
|
||||
withdrawal_credentials = makeFakeHash(i)
|
||||
randao_commitment = repeat_hash(withdrawal_credentials, randaoRounds)
|
||||
|
||||
let pop =
|
||||
if skipValidation in flags:
|
||||
|
@ -45,7 +41,6 @@ func makeDeposit(i: int, flags: UpdateFlags): Deposit =
|
|||
let proof_of_possession_data = DepositInput(
|
||||
pubkey: pubkey,
|
||||
withdrawal_credentials: withdrawal_credentials,
|
||||
randao_commitment: randao_commitment
|
||||
)
|
||||
let domain = 0'u64
|
||||
bls_sign(privkey, hash_tree_root_final(proof_of_possession_data).data, domain)
|
||||
|
@ -56,7 +51,6 @@ func makeDeposit(i: int, flags: UpdateFlags): Deposit =
|
|||
pubkey: pubkey,
|
||||
proof_of_possession: pop,
|
||||
withdrawal_credentials: withdrawal_credentials,
|
||||
randao_commitment: randao_commitment
|
||||
),
|
||||
amount: MAX_DEPOSIT_AMOUNT,
|
||||
)
|
||||
|
@ -96,6 +90,7 @@ proc addBlock*(
|
|||
let
|
||||
# Index from the new state, but registry from the old state.. hmm...
|
||||
proposer = state.validator_registry[proposer_index]
|
||||
privKey = hackPrivKey(proposer)
|
||||
|
||||
var
|
||||
# In order to reuse the state transition function, we first create a dummy
|
||||
|
@ -105,7 +100,7 @@ proc addBlock*(
|
|||
slot: state.slot + 1,
|
||||
parent_root: previous_block_root,
|
||||
state_root: Eth2Digest(), # we need the new state first
|
||||
randao_reveal: ValidatorSig(), # TODO
|
||||
randao_reveal: privKey.genRandaoReveal(state),
|
||||
eth1_data: Eth1Data(), # TODO
|
||||
signature: ValidatorSig(), # we need the rest of the block first!
|
||||
body: body
|
||||
|
|
Loading…
Reference in New Issue