Skip to content

Commit

Permalink
Rollback to non deterministic Verification Keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Aug 10, 2022
1 parent 27ad3d9 commit 5a26a16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
13 changes: 6 additions & 7 deletions mithril-signer/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ impl Runner for SignerRunner {
.get(&self.config.party_id)
.ok_or(RuntimeError::NoStakeForSelf())?;
let protocol_initializer =
MithrilProtocolInitializerBuilder::new(self.config.party_id.to_owned())
.build(stake, protocol_parameters)?;
MithrilProtocolInitializerBuilder::new().build(stake, protocol_parameters)?;
let verification_key = key_encode_hex(protocol_initializer.verification_key())?;
let signer = Signer::new(self.config.party_id.to_owned(), verification_key);
self.services
Expand Down Expand Up @@ -243,16 +242,16 @@ impl Runner for SignerRunner {
message.set_message_part(ProtocolMessagePartKey::SnapshotDigest, digest);

// 2 set the next signers keys and stakes in the message
let signer_retrieval_epoch = beacon.epoch.offset_to_signer_retrieval_epoch()?;
let next_signer_retrieval_epoch = beacon.epoch.offset_to_next_signer_retrieval_epoch()?;
let protocol_initializer = self
.services
.protocol_initializer_store
.get_protocol_initializer(signer_retrieval_epoch)
.get_protocol_initializer(next_signer_retrieval_epoch)
.await?
.ok_or_else(|| {
RuntimeError::NoValueError(format!(
"protocol_initializer at epoch {}",
signer_retrieval_epoch
next_signer_retrieval_epoch
))
})?;

Expand Down Expand Up @@ -498,7 +497,7 @@ mod tests {
let epoch = pending_certificate.beacon.epoch;
let mut signer = &mut pending_certificate.signers[0];

let protocol_initializer = MithrilProtocolInitializerBuilder::new(signer.party_id.clone())
let protocol_initializer = MithrilProtocolInitializerBuilder::new()
.build(&100, &fake_data::protocol_parameters())
.expect("build protocol initializer should not fail");
signer.verification_key = key_encode_hex(protocol_initializer.verification_key()).unwrap();
Expand Down Expand Up @@ -563,7 +562,7 @@ mod tests {
.save_protocol_initializer(
current_beacon
.epoch
.offset_to_signer_retrieval_epoch()
.offset_to_next_signer_retrieval_epoch()
.expect("offset_to_signer_retrieval_epoch should not fail"),
protocol_initializer.clone(),
)
Expand Down
25 changes: 5 additions & 20 deletions mithril-signer/src/single_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,20 @@ use mockall::automock;

use crate::AsyncError;

pub struct MithrilProtocolInitializerBuilder {
party_id: PartyId,
}
#[derive(Default)]
pub struct MithrilProtocolInitializerBuilder {}

impl MithrilProtocolInitializerBuilder {
pub fn new(party_id: PartyId) -> Self {
Self { party_id }
pub fn new() -> Self {
Self {}
}

pub fn build(
&self,
stake: &Stake,
protocol_parameters: &ProtocolParameters,
) -> Result<ProtocolInitializer, AsyncError> {
// TODO: Since the stake distribution is now updated, we can't cache only one protocol initializer
// When the protocol initalizer store is implemented, we should get the protocol initializer based on its associated epoch
// The use of this cache leads to 'The path of the Merkle Tree is invalid.' error when the signer creates a single signature
// and is source of flakiness of the CI

// TODO: Uncomment next line and remove the 4 following lines with deterministic random generator when the protocol initializer store is created
//let mut rng = rand_core::OsRng;
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;
// 32 chars are appended after the party ID to ensure the length is at least 32 while still grants some uniqueness
let seed: [u8; 32] = format!("{}azerazerazerazerazerazerazerazer", self.party_id)
.as_bytes()[..32]
.try_into()?;
let mut rng = ChaCha20Rng::from_seed(seed);
//
let mut rng = rand_core::OsRng;
let protocol_initializer = ProtocolInitializer::setup(
protocol_parameters.to_owned().into(),
stake.to_owned(),
Expand Down

0 comments on commit 5a26a16

Please sign in to comment.