From d79d0182a6e981dc6d561dcf87de09978a3be534 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 26 Dec 2018 11:15:51 +1100 Subject: [PATCH] Implement genesis signature --- beacon_chain/genesis/Cargo.toml | 1 + beacon_chain/genesis/src/beacon_block.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/beacon_chain/genesis/Cargo.toml b/beacon_chain/genesis/Cargo.toml index f1958eaa7..499333979 100644 --- a/beacon_chain/genesis/Cargo.toml +++ b/beacon_chain/genesis/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] bls = { path = "../utils/bls" } spec = { path = "../spec" } +ssz = { path = "../utils/ssz" } types = { path = "../types" } validator_induction = { path = "../validator_induction" } validator_shuffling = { path = "../validator_shuffling" } diff --git a/beacon_chain/genesis/src/beacon_block.rs b/beacon_chain/genesis/src/beacon_block.rs index 9e2c75d24..120903564 100644 --- a/beacon_chain/genesis/src/beacon_block.rs +++ b/beacon_chain/genesis/src/beacon_block.rs @@ -1,5 +1,6 @@ -use bls::Signature; +use bls::{Signature, BLS_AGG_SIG_BYTE_SIZE}; use spec::ChainSpec; +use ssz::{encode::encode_length, Decodable, LENGTH_BYTES}; use types::{BeaconBlock, BeaconBlockBody}; /// Generate a genesis BeaconBlock. @@ -10,7 +11,7 @@ pub fn genesis_beacon_block(spec: &ChainSpec) -> BeaconBlock { state_root: spec.zero_hash, randao_reveal: spec.zero_hash, candidate_pow_receipt_root: spec.zero_hash, - signature: Signature::default(), + signature: genesis_signature(), body: BeaconBlockBody { proposer_slashings: vec![], casper_slashings: vec![], @@ -21,6 +22,16 @@ pub fn genesis_beacon_block(spec: &ChainSpec) -> BeaconBlock { } } +fn genesis_signature() -> Signature { + let mut bytes = encode_length(BLS_AGG_SIG_BYTE_SIZE, LENGTH_BYTES); + bytes.append(&mut vec![0; BLS_AGG_SIG_BYTE_SIZE]); + let (signature, _) = match Signature::ssz_decode(&bytes, 0) { + Ok(sig) => sig, + Err(_) => unreachable!(), + }; + signature +} + #[cfg(test)] mod tests { use super::*;