Skip to content

Commit e6bde77

Browse files
committed
Update KES key until provided period
1 parent b81122b commit e6bde77

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ glob = "0.3"
2727
hex = "0.4.3"
2828
http = "0.2.6"
2929
jsonschema = "0.16.0"
30-
kes-summed-ed25519 = { version = "0.1.0", features = ["serde_enabled"] }
30+
kes-summed-ed25519 = { version = "0.1.1", features = ["serde_enabled"] }
3131
mockall = "0.11.0"
3232
nom = "7.1"
3333
rand-chacha-dalek-compat = { package = "rand_chacha", version = "0.2" }

mithril-common/src/crypto_helper/cardano/key_certification.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ pub enum ProtocolInitializerErrorWrapper {
8282
/// Error raised when a KES update error occurs
8383
#[error("KES key cannot be updated for period {0}")]
8484
KesUpdate(KESPeriod),
85+
86+
/// Period of key file does not match with period provided by user
87+
#[error("Period of key file, {0}, does not match with period provided by user, {1}")]
88+
KesMismatch(KESPeriod, KESPeriod),
8589
}
8690
/// Wrapper structure for [MithrilStm:StmInitializer](mithril_stm::stm::StmInitializer).
8791
/// It now obtains a KES signature over the Mithril key. This allows the signers prove
@@ -119,14 +123,23 @@ impl StmInitializerWrapper {
119123
let kes_signature = if let Some(kes_sk_path) = kes_sk_path {
120124
let mut kes_sk: Sum6Kes = Sum6Kes::from_file(kes_sk_path)?;
121125

122-
// We need to perform the evolutions, as the key is stored in evolution 0 in `kes.skey`
123-
for period in 0..kes_period.unwrap_or_default() {
124-
kes_sk
125-
.update()
126-
.map_err(|_| ProtocolInitializerErrorWrapper::KesUpdate(period))?;
127-
}
126+
let kes_sk_period = kes_sk.get_period();
127+
let provided_period = kes_period.unwrap_or_default();
128+
if kes_sk_period <= provided_period {
129+
// We need to perform the evolutions
130+
for period in kes_sk_period..provided_period {
131+
kes_sk
132+
.update()
133+
.map_err(|_| ProtocolInitializerErrorWrapper::KesUpdate(period))?;
134+
}
128135

129-
Some(kes_sk.sign(&stm_initializer.verification_key().to_bytes()))
136+
Some(kes_sk.sign(&stm_initializer.verification_key().to_bytes()))
137+
} else {
138+
return Err(ProtocolInitializerErrorWrapper::KesMismatch(
139+
kes_sk_period,
140+
provided_period,
141+
));
142+
}
130143
} else {
131144
println!("WARNING: Non certified signer registration by providing only a Pool Id is decommissionned and must be used for tests only!");
132145
None

0 commit comments

Comments
 (0)