mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 22:36:01 +00:00
fix BlsValue inits
This commit is contained in:
parent
c23b011c77
commit
b7f9d9e4be
@ -414,8 +414,9 @@ proc proposeBlock(node: BeaconNode,
|
|||||||
slot: slot,
|
slot: slot,
|
||||||
parent_root: head.root,
|
parent_root: head.root,
|
||||||
body: blockBody,
|
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
|
var
|
||||||
tmpState = hashedState
|
tmpState = hashedState
|
||||||
|
@ -232,7 +232,9 @@ func initialize_beacon_state_from_eth1*(
|
|||||||
Eth1Data(block_hash: eth1_block_hash, deposit_count: uint64(len(deposits))),
|
Eth1Data(block_hash: eth1_block_hash, deposit_count: uint64(len(deposits))),
|
||||||
latest_block_header:
|
latest_block_header:
|
||||||
BeaconBlockHeader(
|
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
|
# TODO - Pure BLSSig cannot be zero: https://github.com/status-im/nim-beacon-chain/issues/374
|
||||||
signature: BlsValue[Signature](kind: OpaqueBlob)
|
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 =
|
func get_initial_beacon_block*(state: BeaconState): BeaconBlock =
|
||||||
BeaconBlock(
|
BeaconBlock(
|
||||||
slot: GENESIS_SLOT,
|
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
|
# parent_root, randao_reveal, eth1_data, signature, and body automatically
|
||||||
# initialized to default values.
|
# 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
|
# 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,
|
func get_attestation_data_slot*(state: BeaconState,
|
||||||
|
@ -39,9 +39,8 @@ proc signBlockProposal*(v: AttachedValidator, state: BeaconState, slot: Slot,
|
|||||||
get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_of_slot(slot))
|
get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_of_slot(slot))
|
||||||
result = bls_sign(v.privKey, blockRoot.data, domain)
|
result = bls_sign(v.privKey, blockRoot.data, domain)
|
||||||
else:
|
else:
|
||||||
# TODO:
|
error "Unimplemented"
|
||||||
# send RPC
|
quit 1
|
||||||
discard
|
|
||||||
|
|
||||||
proc signAttestation*(v: AttachedValidator,
|
proc signAttestation*(v: AttachedValidator,
|
||||||
attestation: AttestationData,
|
attestation: AttestationData,
|
||||||
@ -59,9 +58,8 @@ proc signAttestation*(v: AttachedValidator,
|
|||||||
|
|
||||||
result = bls_sign(v.privKey, attestationRoot.data, domain)
|
result = bls_sign(v.privKey, attestationRoot.data, domain)
|
||||||
else:
|
else:
|
||||||
# TODO:
|
error "Unimplemented"
|
||||||
# send RPC
|
quit 1
|
||||||
discard
|
|
||||||
|
|
||||||
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
|
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
|
||||||
ValidatorSig =
|
ValidatorSig =
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import
|
import
|
||||||
unittest, stint, blscurve, stew/byteutils,
|
unittest, stint, blscurve, stew/byteutils,
|
||||||
../beacon_chain/interop,
|
../beacon_chain/[extras, interop, ssz],
|
||||||
../beacon_chain/spec/[digest, crypto, helpers, datatypes]
|
../beacon_chain/spec/[beaconstate, digest, crypto, helpers, datatypes]
|
||||||
|
|
||||||
# Interop test yaml, found here:
|
# Interop test yaml, found here:
|
||||||
# https://github.com/ethereum/eth2.0-pm/blob/a0b9d22fad424574b1307828f867b30237758468/interop/mocked_start/keygen_10_validators.yaml
|
# https://github.com/ethereum/eth2.0-pm/blob/a0b9d22fad424574b1307828f867b30237758468/interop/mocked_start/keygen_10_validators.yaml
|
||||||
@ -134,3 +134,31 @@ suite "Interop":
|
|||||||
|
|
||||||
check:
|
check:
|
||||||
dep.sig == computed_sig
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user