Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-deploy-network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
{
"1" = {
type = "unverified-cardano-passive-norelay",
pool_id = "pool1y0uxkqyplyx6ld25e976t0s35va3ysqcscatwvy2sd2cwcareq7",
pool_id = "pool13zafxlpfgymf474uv52qt557z5k5frn9p83yr55zp267wj5mpu4",
},
}
mithril_leader_aggregator_endpoint: https://aggregator.dev-preview.api.mithril.network/aggregator
Expand Down
4 changes: 2 additions & 2 deletions internal/mithril-dmq/src/model/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl DmqNetwork {
/// Preprod magic ID
pub const PREPROD_MAGIC_ID: MagicId = 1; // TODO: Update magic ids for networks
/// Preview magic ID
pub const PREVIEW_MAGIC_ID: MagicId = 2; // TODO: Update magic ids for networks
pub const PREVIEW_MAGIC_ID: MagicId = 3141592; // TODO: Update magic ids for networks
/// Devnet magic ID
pub(crate) const DEVNET_MAGIC_ID: MagicId = 3141592; // TODO: Update magic ids for networks
pub(crate) const DEVNET_MAGIC_ID: MagicId = 0; // TODO: Update magic ids for networks

/// Instantiates a DmqNetwork from its code and magic id
pub fn from_code(
Expand Down
12 changes: 10 additions & 2 deletions mithril-aggregator/src/services/signature_processor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{sync::Arc, time::Duration};

use slog::{Logger, error, trace, warn};

Expand Down Expand Up @@ -34,6 +34,8 @@ pub struct SequentialSignatureProcessor {
}

impl SequentialSignatureProcessor {
const ERROR_DELAY_IN_SECONDS: Duration = Duration::from_secs(1);

/// Creates a new `SignatureProcessor` instance.
pub fn new(
consumer: Arc<dyn SignatureConsumer>,
Expand Down Expand Up @@ -111,7 +113,13 @@ impl SignatureProcessor for SequentialSignatureProcessor {

return Ok(());
}
_ = self.process_signatures() => {}
res = self.process_signatures() => {
if let Err(e) = res {
error!(self.logger, "Error processing signatures"; "error" => ?e);
error!(self.logger, "Sleep for {} seconds", Self::ERROR_DELAY_IN_SECONDS.as_secs());
tokio::time::sleep(Self::ERROR_DELAY_IN_SECONDS).await;
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]
ignored = ["serde_bytes"]

[features]
default = ["rug-backend"]
default = ["rug-backend", "allow_skip_signer_certification"]

# Enables `rug-backend` features for `mithril-stm` dependency
rug-backend = ["mithril-stm/rug-backend"]
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/crypto_helper/cardano/kes/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum KesVerifyError {
#[derive(Error, Debug)]
pub enum KesSignError {
/// Error raised when a KES update error occurs
#[error("KES key cannot be updated for period {0}")]
#[error("KES key cannot be updated for evolution {0}")]
UpdateKey(KesPeriod),

/// Period of key file does not match with period provided by user
Expand Down
8 changes: 7 additions & 1 deletion mithril-common/src/crypto_helper/cardano/kes/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ use crate::{
#[cfg_attr(test, mockall::automock)]
pub trait KesSigner: Send + Sync {
/// Return signed bytes with the KES secret key and the associated Operational Certificate
fn sign(&self, message: &[u8], kes_period: KesPeriod) -> StdResult<(Sum6KesSig, OpCert)>;
///
/// current_kes_period: The KES period used to sign the message (absolute period computed from the chain at the moment of signature)
fn sign(
&self,
message: &[u8],
current_kes_period: KesPeriod,
) -> StdResult<(Sum6KesSig, OpCert)>;
}

/// Trait for KES (Key Evolving Signature) verification operation.
Expand Down
30 changes: 16 additions & 14 deletions mithril-common/src/crypto_helper/cardano/kes/signer_with_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,32 @@ impl KesSignerStandard {
}

impl KesSigner for KesSignerStandard {
fn sign(&self, message: &[u8], kes_period: KesPeriod) -> StdResult<(Sum6KesSig, OpCert)> {
fn sign(
&self,
message: &[u8],
current_kes_period: KesPeriod,
) -> StdResult<(Sum6KesSig, OpCert)> {
let mut kes_sk_bytes = Sum6KesBytes::from_file(&self.kes_sk_path)
.with_context(|| "StandardKesSigner can not read KES secret key from file")?;
let mut kes_sk = Sum6Kes::try_from(&mut kes_sk_bytes)
.with_context(|| "StandardKesSigner can not use KES secret key")?;
let operational_certificate = OpCert::from_file(&self.operational_certificate_path)
.with_context(|| "StandardKesSigner can not read operational certificate from file")?;
let kes_period_start = operational_certificate.get_start_kes_period() as u32;
let kes_sk_period = kes_sk.get_period();
if kes_sk_period > kes_period {
let kes_evolutions = current_kes_period.saturating_sub(kes_period_start);
if kes_sk_period > kes_evolutions {
return Err(anyhow!(KesSignError::PeriodMismatch(
kes_sk_period,
kes_period
kes_evolutions
)));
}

// We need to perform the evolutions
for period in kes_sk_period..kes_period {
kes_sk.update().map_err(|_| KesSignError::UpdateKey(period))?;
for evolution in kes_sk_period..kes_evolutions {
kes_sk.update().map_err(|_| KesSignError::UpdateKey(evolution))?;
}

let operational_certificate = OpCert::from_file(&self.operational_certificate_path)
.with_context(|| "StandardKesSigner can not read operational certificate from file")?;

Ok((kes_sk.sign(message), operational_certificate))
}
}
Expand Down Expand Up @@ -119,7 +124,8 @@ mod tests {
}

#[test]
fn create_invalid_signature_for_invalid_kes_period() {
fn create_invalid_signature_for_invalid_kes_evolution() {
const MAX_KES_EVOLUTIONS: KesPeriod = 63;
let kes_period_start = 5 as KesPeriod;
let KesCryptographicMaterialForTest {
party_id: _,
Expand All @@ -132,11 +138,7 @@ mod tests {
);
let message = b"Test message for KES signing";
let kes_signer = KesSignerStandard::new(kes_secret_key_file, operational_certificate_file);
let kes_signing_period = 2;
assert!(
kes_signing_period < kes_period_start,
"KES signing period should be less than the KES period of the key"
);
let kes_signing_period = kes_period_start + MAX_KES_EVOLUTIONS + 1;

kes_signer
.sign(message, kes_signing_period)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub enum ProtocolInitializerErrorWrapper {
ProtocolInitializer(#[source] StdError),

/// Error raised when a KES update error occurs
#[error("KES key cannot be updated for period {0}")]
#[error("KES key cannot be updated for evolution {0}")]
KesUpdate(KesPeriod),

/// Period of key file does not match with period provided by user
Expand Down
12 changes: 4 additions & 8 deletions mithril-common/src/test/crypto_helper/cardano/kes/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) struct KesCryptographicMaterialForTest {
/// Create KES cryptographic material for testing purposes.
pub fn create_kes_cryptographic_material(
party_idx: KesPartyIndexForTest,
kes_period: KesPeriod,
start_kes_period: KesPeriod,
test_directory: &str,
) -> KesCryptographicMaterialForTest {
let temp_dir = std::env::temp_dir()
Expand All @@ -31,16 +31,12 @@ pub fn create_kes_cryptographic_material(
let keypair = ColdKeyGenerator::create_deterministic_keypair([party_idx as u8; 32]);
let mut dummy_buffer = [0u8; Sum6Kes::SIZE + 4];
let mut dummy_seed = [party_idx as u8; 32];
let (mut kes_secret_key, kes_verification_key) =
let (kes_secret_key, kes_verification_key) =
Sum6Kes::keygen(&mut dummy_buffer, &mut dummy_seed);
for _ in 0..kes_period {
kes_secret_key
.update()
.expect("KES secret key update should not fail");
}
let mut kes_bytes = Sum6KesBytes([0u8; Sum6Kes::SIZE + 4]);
kes_bytes.0.copy_from_slice(&kes_secret_key.clone_sk());
let operational_certificate = OpCert::new(kes_verification_key, 0, 0, keypair);
let operational_certificate =
OpCert::new(kes_verification_key, 0, start_kes_period as u64, keypair);
let kes_secret_key_file = temp_dir.join(format!("kes{party_idx}.skey"));
kes_bytes
.to_file(&kes_secret_key_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl KesSignerFake {
}

impl KesSigner for KesSignerFake {
fn sign(&self, message: &[u8], _kes_period: KesPeriod) -> KesSignatureResult {
fn sign(&self, message: &[u8], _current_kes_period: KesPeriod) -> KesSignatureResult {
let mut messages = self.signed_messages.lock().unwrap();
messages.push_back(message.to_vec());

Expand Down
17 changes: 3 additions & 14 deletions mithril-signer/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use thiserror::Error;
use tokio::sync::RwLockReadGuard;

use mithril_common::StdResult;
use mithril_common::crypto_helper::{KesPeriod, OpCert, ProtocolOpCert, SerDeShelleyFileFormat};
use mithril_common::crypto_helper::{OpCert, ProtocolOpCert, SerDeShelleyFileFormat};
use mithril_common::entities::{
Epoch, PartyId, ProtocolMessage, SignedEntityType, Signer, TimePoint,
};
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Runner for SignerRunner {
let stake = stake_distribution
.get(&self.services.single_signer.get_party_id())
.ok_or_else(RunnerError::NoStakeForSelf)?;
let (operational_certificate, protocol_operational_certificate) = match &self
let (_operational_certificate, protocol_operational_certificate) = match &self
.config
.operational_certificate_path
{
Expand All @@ -198,18 +198,7 @@ impl Runner for SignerRunner {
}
_ => (None, None),
};

let kes_period = match operational_certificate {
Some(operational_certificate) => Some(
self.services
.chain_observer
.get_current_kes_period()
.await?
.unwrap_or_default()
- operational_certificate.get_start_kes_period() as KesPeriod,
),
None => None,
};
let kes_period = self.services.chain_observer.get_current_kes_period().await?;

let protocol_initializer = self
.services
Expand Down
Loading