Implement genesis signature

This commit is contained in:
Paul Hauner 2018-12-26 11:15:51 +11:00
parent 79093f6ad1
commit d79d0182a6
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 14 additions and 2 deletions

View File

@ -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" }

View File

@ -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::*;