Skip to content
Permalink
Browse files

Merge branch 'state' of github.com:input-output-hk/rust-cardano into …

…state
  • Loading branch information...
vincenthz committed Mar 12, 2019
2 parents fe0591d + 632f820 commit 05c9ce7a2f81d296deaa9fdaf6f83b2d1f774737
Showing with 27 additions and 6 deletions.
  1. +5 −5 chain-crypto/src/algorithms/fakemmm.rs
  2. +22 −1 chain-impl-mockchain/src/leadership/genesis.rs
@@ -8,7 +8,7 @@ use rand_core::{CryptoRng, RngCore};
pub struct FakeMMM;

#[derive(Clone)]
pub struct Priv([u8; ed25519::PRIVATE_KEY_LENGTH]);
pub struct Priv([u8; ed25519::SEED_LENGTH]);

#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Pub([u8; ed25519::PUBLIC_KEY_LENGTH]);
@@ -39,7 +39,7 @@ impl AsymmetricKey for FakeMMM {
type Public = Pub;

fn generate<T: RngCore + CryptoRng>(mut rng: T) -> Priv {
let mut priv_bytes = [0u8; ed25519::PRIVATE_KEY_LENGTH];
let mut priv_bytes = [0u8; ed25519::SEED_LENGTH];
rng.fill_bytes(&mut priv_bytes);
Priv(priv_bytes)
}
@@ -50,11 +50,11 @@ impl AsymmetricKey for FakeMMM {
}

fn secret_from_binary(data: &[u8]) -> Result<Priv, SecretKeyError> {
if data.len() != ed25519::PRIVATE_KEY_LENGTH {
if data.len() != ed25519::SEED_LENGTH {
return Err(SecretKeyError::SizeInvalid);
}
let mut buf = [0; ed25519::PRIVATE_KEY_LENGTH];
buf[0..ed25519::PRIVATE_KEY_LENGTH].clone_from_slice(data);
let mut buf = [0; ed25519::SEED_LENGTH];
buf[0..ed25519::SEED_LENGTH].clone_from_slice(data);
Ok(Priv(buf))
}
fn public_from_binary(data: &[u8]) -> Result<Pub, PublicKeyError> {
@@ -346,7 +346,25 @@ impl LeaderSelection for GenesisLeaderSelection {
match &input.header.proof() {
Proof::None => unimplemented!(),
Proof::GenesisPraos(genesis_praos_proof) => {
// TODO: check the proof is valid
if let PublicLeader::GenesisPraos(genesis_praos_leader) = &leader {
if &genesis_praos_proof.vrf_public_key != &genesis_praos_leader.vrf_public_key
|| &genesis_praos_proof.kes_public_key
!= &genesis_praos_leader.kes_public_key
{
return Err(Error {
kind: ErrorKind::InvalidLeader,
cause: Some(Box::new(GenesisPraosError::BlockHasInvalidLeader(
leader.clone(),
PublicLeader::GenesisPraos(GenesisPraosLeader {
kes_public_key: genesis_praos_proof.kes_public_key.clone(),
vrf_public_key: genesis_praos_proof.vrf_public_key.clone(),
}),
))),
});
}
} else {
// TODO: error, we would expect a GENESIS leader in the case of a GenesisPraos proof
}
}
Proof::Bft(bft_proof) => {
if let PublicLeader::Bft(bft_leader) = &leader {
@@ -359,6 +377,9 @@ impl LeaderSelection for GenesisLeaderSelection {
))),
});
}
} else {
// TODO: this is an error, we need to only accept BFT leader in the
// case of a BFT proof
}
}
}

0 comments on commit 05c9ce7

Please sign in to comment.
You can’t perform that action at this time.