Skip to content

Commit

Permalink
New StmInitializer setup
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta authored and jpraynaud committed Sep 23, 2022
1 parent d9d10bd commit a6467c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions mithril-core/Cargo.toml
Expand Up @@ -6,15 +6,16 @@ edition = "2018"
[dependencies]
blake2 = "0.10.4"
blst = { version = "0.3.10" }
num-bigint = { version = "0.4.0", optional = true }
num-rational = { version = "0.4.0", optional = true }
num-traits = { version = "0.2.14", optional = true }
digest = { version = "0.9.0", features = ["alloc"] }
ed25519-dalek = "1.0.1"
kes-summed-ed25519 = { git = "https://github.com/input-output-hk/kes" }
num-bigint = {version = "0.4.0", optional = true }
num-rational = {version = "0.4.0", optional = true }
num-traits = {version = "0.2.14", optional = true }
rand_core = "0.6.3"
rug = { version = "1.14", optional = true }
serde = { version = "1", features = ["rc", "derive"] }
thiserror = "1.0"
ed25519-dalek = "1.0.1"
kes-summed-ed25519 = { git = "https://github.com/input-output-hk/kes" }

[dev-dependencies]
bincode = "1.3.3"
Expand Down
24 changes: 24 additions & 0 deletions mithril-core/src/stm.rs
Expand Up @@ -117,6 +117,8 @@ use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::{From, TryFrom, TryInto};
use std::hash::{Hash, Hasher};
use kes_summed_ed25519::kes::{Sum6Kes, Sum6KesSig};
use kes_summed_ed25519::traits::KesSk;

/// The quantity of stake held by a party, represented as a `u64`.
pub type Stake = u64;
Expand Down Expand Up @@ -161,6 +163,8 @@ pub struct StmInitializer {
pub(crate) sk: SigningKey,
/// Verification (public) key + proof of possession.
pub(crate) pk: StmVerificationKeyPoP,
/// KES signature of `pk`
pub(crate) kes_sig: Option<Sum6KesSig>,
}

/// Participant in the protocol can sign messages.
Expand Down Expand Up @@ -261,6 +265,23 @@ impl StmParameters {
}

impl StmInitializer {
/// Builds an `StmInitializer` that is ready to register with the key registration service.
/// This function generates the signing and verification key with a PoP, signs the verification
/// key with a provided KES signing key, and initialises the structure.
pub fn setup_new<R: RngCore + CryptoRng>(params: StmParameters, kes_sk: &[u8], kes_period: usize, stake: Stake, rng: &mut R) -> Self {
let sk = SigningKey::gen(rng);
let pk = StmVerificationKeyPoP::from(&sk);
let kes_sk = Sum6Kes::from_bytes(kes_sk).expect("Invalid KES key provided"); // todo: handle this
let kes_sig = Some(kes_sk.sign(kes_period, &pk.to_bytes()));

Self {
stake,
params,
sk,
pk,
kes_sig
}
}
/// Builds an `StmInitializer` that is ready to register with the key registration service.
/// This function generates the signing and verification key with a PoP, and initialises the structure.
pub fn setup<R: RngCore + CryptoRng>(params: StmParameters, stake: Stake, rng: &mut R) -> Self {
Expand All @@ -271,6 +292,7 @@ impl StmInitializer {
params,
sk,
pk,
kes_sig: None
}
}

Expand Down Expand Up @@ -347,6 +369,7 @@ impl StmInitializer {
params,
sk,
pk,
kes_sig: None
})
}
}
Expand Down Expand Up @@ -523,6 +546,7 @@ impl<D: Clone + Digest> StmSigner<D> {
params: self.params,
pk: StmVerificationKeyPoP::from(&self.sk),
sk: self.sk,
kes_sig: None
}
}

Expand Down

0 comments on commit a6467c7

Please sign in to comment.