Skip to content

Commit 19c4674

Browse files
committed
Update KES key to current period
Use 'kes_period = current_kes_period - start_kes_period'
1 parent 9e9e23b commit 19c4674

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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(),

0 commit comments

Comments
 (0)