mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-09 05:52:45 +00:00
parent
f2545318db
commit
072c1607fd
@ -210,7 +210,7 @@ proc proposeBlock(node: BeaconNode,
|
|||||||
var newBlock = BeaconBlock(
|
var newBlock = BeaconBlock(
|
||||||
slot: slot,
|
slot: slot,
|
||||||
parent_root: node.headBlockRoot,
|
parent_root: node.headBlockRoot,
|
||||||
randao_reveal: ValidatorSig(), # TODO probably wrong
|
randao_reveal: validator.genRandaoReveal(state),
|
||||||
eth1_data: node.mainchainMonitor.getBeaconBlockRef(),
|
eth1_data: node.mainchainMonitor.getBeaconBlockRef(),
|
||||||
signature: ValidatorSig(), # we need the rest of the block first!
|
signature: ValidatorSig(), # we need the rest of the block first!
|
||||||
body: blockBody)
|
body: blockBody)
|
||||||
|
@ -47,8 +47,7 @@ func process_deposit(state: var BeaconState,
|
|||||||
pubkey: ValidatorPubKey,
|
pubkey: ValidatorPubKey,
|
||||||
amount: uint64,
|
amount: uint64,
|
||||||
proof_of_possession: ValidatorSig,
|
proof_of_possession: ValidatorSig,
|
||||||
withdrawal_credentials: Eth2Digest,
|
withdrawal_credentials: Eth2Digest) =
|
||||||
randao_commitment: Eth2Digest) =
|
|
||||||
## Process a deposit from Ethereum 1.0.
|
## Process a deposit from Ethereum 1.0.
|
||||||
|
|
||||||
if false:
|
if false:
|
||||||
@ -206,7 +205,6 @@ func get_initial_beacon_state*(
|
|||||||
deposit.deposit_data.amount,
|
deposit.deposit_data.amount,
|
||||||
deposit.deposit_data.deposit_input.proof_of_possession,
|
deposit.deposit_data.deposit_input.proof_of_possession,
|
||||||
deposit.deposit_data.deposit_input.withdrawal_credentials,
|
deposit.deposit_data.deposit_input.withdrawal_credentials,
|
||||||
deposit.deposit_data.deposit_input.randao_commitment,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Process initial activations
|
# Process initial activations
|
||||||
|
@ -252,7 +252,6 @@ type
|
|||||||
DepositInput* = object
|
DepositInput* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
randao_commitment*: Eth2Digest # Initial RANDAO commitment
|
|
||||||
proof_of_possession*: ValidatorSig ##\
|
proof_of_possession*: ValidatorSig ##\
|
||||||
## BLS proof of possession (a BLS signature)
|
## BLS proof of possession (a BLS signature)
|
||||||
|
|
||||||
|
@ -49,8 +49,7 @@ cli do (validators: int,
|
|||||||
|
|
||||||
proofOfPossessionData = DepositInput(
|
proofOfPossessionData = DepositInput(
|
||||||
pubkey: pubKey,
|
pubkey: pubKey,
|
||||||
withdrawal_credentials: withdrawalCredentials,
|
withdrawal_credentials: withdrawalCredentials)
|
||||||
randao_commitment: randaoCommitment)
|
|
||||||
|
|
||||||
proofOfPossession = bls_sign(
|
proofOfPossession = bls_sign(
|
||||||
privkey, hash_tree_root_final(proofOfPossessionData).data,
|
privkey, hash_tree_root_final(proofOfPossessionData).data,
|
||||||
@ -64,8 +63,7 @@ cli do (validators: int,
|
|||||||
deposit_input: DepositInput(
|
deposit_input: DepositInput(
|
||||||
pubkey: pubKey,
|
pubkey: pubKey,
|
||||||
proof_of_possession: proofOfPossession,
|
proof_of_possession: proofOfPossession,
|
||||||
withdrawal_credentials: withdrawalCredentials,
|
withdrawal_credentials: withdrawalCredentials)))
|
||||||
randao_commitment: randaoCommitment)))
|
|
||||||
|
|
||||||
startupData.genesisTime = uint64(int(now() div 1000) + startupDelay)
|
startupData.genesisTime = uint64(int(now() div 1000) + startupDelay)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import
|
import
|
||||||
tables, random,
|
tables, random,
|
||||||
chronos,
|
chronos,
|
||||||
spec/[datatypes, crypto, digest], randao, ssz
|
spec/[datatypes, crypto, digest, helpers], randao, ssz
|
||||||
|
|
||||||
type
|
type
|
||||||
ValidatorKind = enum
|
ValidatorKind = enum
|
||||||
@ -83,3 +83,17 @@ proc randaoReveal*(v: AttachedValidator, commitment: Eth2Digest): Future[Eth2Dig
|
|||||||
# send RPC
|
# send RPC
|
||||||
discard
|
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
|
import
|
||||||
options, sequtils,
|
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]
|
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator]
|
||||||
|
|
||||||
const
|
|
||||||
randaoRounds = 100
|
|
||||||
|
|
||||||
func makeValidatorPrivKey(i: int): ValidatorPrivKey =
|
func makeValidatorPrivKey(i: int): ValidatorPrivKey =
|
||||||
var i = i + 1 # 0 does not work, as private key...
|
var i = i + 1 # 0 does not work, as private key...
|
||||||
copyMem(result.x[0].addr, i.addr, min(sizeof(result.x), sizeof(i)))
|
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)
|
privkey = makeValidatorPrivKey(i)
|
||||||
pubkey = privkey.pubKey()
|
pubkey = privkey.pubKey()
|
||||||
withdrawal_credentials = makeFakeHash(i)
|
withdrawal_credentials = makeFakeHash(i)
|
||||||
randao_commitment = repeat_hash(withdrawal_credentials, randaoRounds)
|
|
||||||
|
|
||||||
let pop =
|
let pop =
|
||||||
if skipValidation in flags:
|
if skipValidation in flags:
|
||||||
@ -45,7 +41,6 @@ func makeDeposit(i: int, flags: UpdateFlags): Deposit =
|
|||||||
let proof_of_possession_data = DepositInput(
|
let proof_of_possession_data = DepositInput(
|
||||||
pubkey: pubkey,
|
pubkey: pubkey,
|
||||||
withdrawal_credentials: withdrawal_credentials,
|
withdrawal_credentials: withdrawal_credentials,
|
||||||
randao_commitment: randao_commitment
|
|
||||||
)
|
)
|
||||||
let domain = 0'u64
|
let domain = 0'u64
|
||||||
bls_sign(privkey, hash_tree_root_final(proof_of_possession_data).data, domain)
|
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,
|
pubkey: pubkey,
|
||||||
proof_of_possession: pop,
|
proof_of_possession: pop,
|
||||||
withdrawal_credentials: withdrawal_credentials,
|
withdrawal_credentials: withdrawal_credentials,
|
||||||
randao_commitment: randao_commitment
|
|
||||||
),
|
),
|
||||||
amount: MAX_DEPOSIT_AMOUNT,
|
amount: MAX_DEPOSIT_AMOUNT,
|
||||||
)
|
)
|
||||||
@ -96,6 +90,7 @@ proc addBlock*(
|
|||||||
let
|
let
|
||||||
# Index from the new state, but registry from the old state.. hmm...
|
# Index from the new state, but registry from the old state.. hmm...
|
||||||
proposer = state.validator_registry[proposer_index]
|
proposer = state.validator_registry[proposer_index]
|
||||||
|
privKey = hackPrivKey(proposer)
|
||||||
|
|
||||||
var
|
var
|
||||||
# In order to reuse the state transition function, we first create a dummy
|
# In order to reuse the state transition function, we first create a dummy
|
||||||
@ -105,7 +100,7 @@ proc addBlock*(
|
|||||||
slot: state.slot + 1,
|
slot: state.slot + 1,
|
||||||
parent_root: previous_block_root,
|
parent_root: previous_block_root,
|
||||||
state_root: Eth2Digest(), # we need the new state first
|
state_root: Eth2Digest(), # we need the new state first
|
||||||
randao_reveal: ValidatorSig(), # TODO
|
randao_reveal: privKey.genRandaoReveal(state),
|
||||||
eth1_data: Eth1Data(), # TODO
|
eth1_data: Eth1Data(), # TODO
|
||||||
signature: ValidatorSig(), # we need the rest of the block first!
|
signature: ValidatorSig(), # we need the rest of the block first!
|
||||||
body: body
|
body: body
|
||||||
|
Loading…
x
Reference in New Issue
Block a user