fix BlsValue inits

This commit is contained in:
Jacek Sieka 2019-09-08 14:27:09 -04:00 committed by zah
parent c23b011c77
commit b7f9d9e4be
4 changed files with 47 additions and 13 deletions

View File

@ -414,8 +414,9 @@ proc proposeBlock(node: BeaconNode,
slot: slot,
parent_root: head.root,
body: blockBody,
signature: ValidatorSig(), # we need the rest of the block first!
)
# TODO: This shouldn't be necessary if OpaqueBlob is the default
signature: ValidatorSig(kind: OpaqueBlob))
var
tmpState = hashedState

View File

@ -232,7 +232,9 @@ func initialize_beacon_state_from_eth1*(
Eth1Data(block_hash: eth1_block_hash, deposit_count: uint64(len(deposits))),
latest_block_header:
BeaconBlockHeader(
body_root: hash_tree_root(BeaconBlockBody()),
body_root: hash_tree_root(BeaconBlockBody(
randao_reveal: BlsValue[Signature](kind: OpaqueBlob)
)),
# TODO - Pure BLSSig cannot be zero: https://github.com/status-im/nim-beacon-chain/issues/374
signature: BlsValue[Signature](kind: OpaqueBlob)
)
@ -284,10 +286,15 @@ proc is_valid_genesis_state*(state: BeaconState): bool =
func get_initial_beacon_block*(state: BeaconState): BeaconBlock =
BeaconBlock(
slot: GENESIS_SLOT,
state_root: hash_tree_root(state)
state_root: hash_tree_root(state),
body: BeaconBlockBody(
# TODO: This shouldn't be necessary if OpaqueBlob is the default
randao_reveal: BlsValue[Signature](kind: OpaqueBlob)),
# TODO: This shouldn't be necessary if OpaqueBlob is the default
signature: BlsValue[Signature](kind: OpaqueBlob))
# parent_root, randao_reveal, eth1_data, signature, and body automatically
# initialized to default values.
)
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#get_attestation_data_slot
func get_attestation_data_slot*(state: BeaconState,

View File

@ -39,9 +39,8 @@ proc signBlockProposal*(v: AttachedValidator, state: BeaconState, slot: Slot,
get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_of_slot(slot))
result = bls_sign(v.privKey, blockRoot.data, domain)
else:
# TODO:
# send RPC
discard
error "Unimplemented"
quit 1
proc signAttestation*(v: AttachedValidator,
attestation: AttestationData,
@ -59,9 +58,8 @@ proc signAttestation*(v: AttachedValidator,
result = bls_sign(v.privKey, attestationRoot.data, domain)
else:
# TODO:
# send RPC
discard
error "Unimplemented"
quit 1
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
ValidatorSig =

View File

@ -1,7 +1,7 @@
import
unittest, stint, blscurve, stew/byteutils,
../beacon_chain/interop,
../beacon_chain/spec/[digest, crypto, helpers, datatypes]
../beacon_chain/[extras, interop, ssz],
../beacon_chain/spec/[beaconstate, digest, crypto, helpers, datatypes]
# Interop test yaml, found here:
# https://github.com/ethereum/eth2.0-pm/blob/a0b9d22fad424574b1307828f867b30237758468/interop/mocked_start/keygen_10_validators.yaml
@ -134,3 +134,31 @@ suite "Interop":
check:
dep.sig == computed_sig
test "Interop genesis":
# Check against https://github.com/protolambda/zcli:
# zcli keys generate --to 64 | zcli genesis mock --genesis-time 1570500000 > /tmp/state.ssz
# zcli hash-tree-root /tmp.state.ssz
var deposits: seq[Deposit]
for i in 0..<64:
let
privKey = makeInteropPrivKey(i)
deposits.add(makeDeposit(privKey.pubKey(), privKey))
var
initialState = initialize_beacon_state_from_eth1(
eth1BlockHash, 1570500000, deposits, {skipValidation})
# https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state
initialState.genesis_time = 1570500000
let expected =
when const_preset == "minimal":
"029836dbceb95c20b101f8f44470604c0912e96949aaf1dd9ad41effd92abcbf"
elif const_preset == "mainnet":
"9cd22b0ea2ec836fef591d259f0d4273669cba4c82df32cf0aa55c388ff7e432"
else:
"unimplemented"
check:
hash_tree_root(initialState).data.toHex() == expected