Skip to content

Commit 4456966

Browse files
authored
Merge pull request #569 from input-output-hk/ensemble/548-fix-kes-period-issue
Fix KES key update
2 parents b352101 + 458ad73 commit 4456966

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

mithril-aggregator/src/multi_signer.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use slog_scope::{debug, trace, warn};
99
use thiserror::Error;
1010

1111
use mithril_common::crypto_helper::{
12-
key_decode_hex, key_encode_hex, ProtocolAggregateVerificationKey, ProtocolAggregationError,
13-
ProtocolClerk, ProtocolKeyRegistration, ProtocolMultiSignature, ProtocolParameters,
14-
ProtocolPartyId, ProtocolRegistrationError, ProtocolSignerVerificationKey,
12+
key_decode_hex, key_encode_hex, KESPeriod, ProtocolAggregateVerificationKey,
13+
ProtocolAggregationError, ProtocolClerk, ProtocolKeyRegistration, ProtocolMultiSignature,
14+
ProtocolParameters, ProtocolPartyId, ProtocolRegistrationError, ProtocolSignerVerificationKey,
1515
ProtocolSingleSignature, ProtocolStakeDistribution, PROTOCOL_VERSION,
1616
};
1717
use mithril_common::entities::{self, PartyId, Signer, SignerWithStake};
@@ -562,11 +562,14 @@ impl MultiSigner for MultiSignerImpl {
562562
_ => None,
563563
};
564564
let kes_period = match &operational_certificate {
565-
Some(operational_certificate) => self
566-
.chain_observer
567-
.get_current_kes_period(operational_certificate)
568-
.await
569-
.map_err(|e| ProtocolError::ChainObserver(e.to_string()))?,
565+
Some(operational_certificate) => Some(
566+
self.chain_observer
567+
.get_current_kes_period(operational_certificate)
568+
.await
569+
.map_err(|e| ProtocolError::ChainObserver(e.to_string()))?
570+
.unwrap_or_default()
571+
- operational_certificate.start_kes_period as KESPeriod,
572+
),
570573
None => None,
571574
};
572575
let party_id_save = key_registration.register(

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ pub enum ProtocolRegistrationErrorWrapper {
6565
CoreRegister(#[from] RegisterError),
6666
}
6767

68+
/// New initializer error
69+
#[derive(Error, Debug)]
70+
pub enum ProtocolInitializerErrorWrapper {
71+
/// Error raised when a codec parse error occurs
72+
#[error("codec parse error: '{0}'")]
73+
Codec(#[from] ParseError),
74+
75+
/// Error raised when a KES update error occurs
76+
#[error("KES key cannot be updated for period {0}")]
77+
KesUpdate(KESPeriod),
78+
}
6879
/// Wrapper structure for [MithrilCore:StmInitializer](https://mithril.network/mithril-core/doc/mithril/stm/struct.StmInitializer.html).
6980
/// It now obtains a KES signature over the Mithril key. This allows the signers prove
7081
/// their correct identity with respect to a Cardano PoolID.
@@ -96,10 +107,18 @@ impl StmInitializerWrapper {
96107
kes_period: Option<KESPeriod>,
97108
stake: Stake,
98109
rng: &mut R,
99-
) -> Result<Self, ParseError> {
110+
) -> Result<Self, ProtocolInitializerErrorWrapper> {
100111
let stm_initializer = StmInitializer::setup(params, stake, rng);
101112
let kes_signature = if let Some(kes_sk_path) = kes_sk_path {
102-
let kes_sk: Sum6Kes = Sum6Kes::from_file(kes_sk_path)?;
113+
let mut kes_sk: Sum6Kes = Sum6Kes::from_file(kes_sk_path)?;
114+
115+
// We need to perform the evolutions, as the key is stored in evolution 0 in `kes.skey`
116+
for period in 0..kes_period.unwrap_or_default() {
117+
kes_sk
118+
.update(period)
119+
.map_err(|_| ProtocolInitializerErrorWrapper::KesUpdate(period))?;
120+
}
121+
103122
Some(kes_sk.sign(
104123
kes_period.unwrap_or_default(),
105124
&stm_initializer.verification_key().to_bytes(),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ struct RawOpCert(RawFields, EdPublicKey);
4141
pub struct OpCert {
4242
pub(crate) kes_vk: KesPublicKey,
4343
pub(crate) issue_number: u64,
44-
pub(crate) start_kes_period: u64, // this is not the kes period used in signing/verifying
44+
/// KES period at which KES key is initalized
45+
pub start_kes_period: u64,
4546
pub(crate) cert_sig: EdSignature,
4647
pub(crate) cold_vk: EdPublicKey,
4748
}

mithril-signer/src/runtime/runner.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use thiserror::Error;
77
use mockall::automock;
88

99
use mithril_common::crypto_helper::{
10-
key_decode_hex, OpCert, ProtocolSignerVerificationKey, SerDeShelleyFileFormat,
10+
key_decode_hex, KESPeriod, OpCert, ProtocolSignerVerificationKey, SerDeShelleyFileFormat,
1111
};
1212
use mithril_common::entities::{PartyId, ProtocolParameters};
1313
use mithril_common::{
@@ -192,7 +192,8 @@ impl Runner for SignerRunner {
192192
.chain_observer
193193
.get_current_kes_period(&operational_certificate)
194194
.await?
195-
.unwrap_or_default(),
195+
.unwrap_or_default()
196+
- operational_certificate.start_kes_period as KESPeriod,
196197
),
197198
None => None,
198199
};

openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ components:
353353
type: string
354354
format: byte
355355
kes_period:
356-
description: The KES Period at which the verification key has been signed by the KES secret key
356+
description: The number of updates of the KES secret key that signed the verification key
357357
type: integer
358358
format: int64
359359
example:

0 commit comments

Comments
 (0)