Skip to content

Paralel panics #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
712 changes: 360 additions & 352 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

127 changes: 85 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions demo/protocol-demo/src/demonstrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ impl ProtocolDemonstrator for Demonstrator {
players_artifacts.push(PlayerArtifact {
party_id: protocol_initializer.party_id(),
stake: protocol_initializer.stake(),
verification_key: key_encode_hex(verification_key).unwrap(),
initializer: key_encode_hex(protocol_initializer).unwrap(),
verification_key: key_encode_hex(&verification_key).unwrap(),
initializer: key_encode_hex(&protocol_initializer).unwrap(),
})
}
let players_with_keys = players_artifacts
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/multi_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl MultiSigner for MultiSignerImpl {
.get_stake_distribution()
.iter()
.filter_map(|(party_id, stake)| match self.get_signer(*party_id) {
Ok(Some(verification_key)) => match key_encode_hex(verification_key) {
Ok(Some(verification_key)) => match key_encode_hex(&verification_key) {
Ok(verification_key) => Some(entities::SignerWithStake::new(
*party_id as u64,
verification_key,
Expand Down Expand Up @@ -382,7 +382,7 @@ impl MultiSigner for MultiSignerImpl {
let completed_at = started_at.clone();
let signers = self.get_signers()?;
let aggregate_verification_key =
key_encode_hex(&self.avk.as_ref().unwrap()).map_err(ProtocolError::Codec)?;
key_encode_hex(self.avk.as_ref().unwrap()).map_err(ProtocolError::Codec)?;
let multi_signature =
key_encode_hex(&multi_signature).map_err(ProtocolError::Codec)?;
Ok(Some(entities::Certificate::new(
Expand Down
74 changes: 66 additions & 8 deletions mithril-common/src/crypto_helper/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,81 @@ use hex::{FromHex, ToHex};
use serde::de::DeserializeOwned;
use serde::Serialize;

////////// Temporary trait, to understand the flaky tests ///////////

use mithril::{multi_sig_blstrs::*, stm::*};

pub trait BytesConv: Sized {
fn from_byte(bytes: &[u8]) -> Result<Self, String>;
fn to_byte(&self) -> Vec<u8>;
}

impl BytesConv for VerificationKeyPoP {
fn from_byte(bytes: &[u8]) -> Result<Self, String> {
VerificationKeyPoP::from_bytes(bytes).map_err(|_| format!("Failed"))
}

fn to_byte(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}
impl BytesConv for StmInitializer {
fn from_byte(bytes: &[u8]) -> Result<Self, String> {
StmInitializer::from_bytes(bytes).map_err(|_| format!("Failed"))
}

fn to_byte(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}

impl BytesConv for StmSig<blake2::Blake2b> {
fn from_byte(bytes: &[u8]) -> Result<Self, String> {
StmSig::<blake2::Blake2b>::from_bytes(bytes).map_err(|_| format!("Failed"))
}

fn to_byte(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}

impl BytesConv for StmAggrSig<blake2::Blake2b> {
fn from_byte(bytes: &[u8]) -> Result<Self, String> {
StmAggrSig::<blake2::Blake2b>::from_bytes(bytes).map_err(|_| format!("Failed"))
}

fn to_byte(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}

impl BytesConv for StmAggrVerificationKey<blake2::Blake2b> {
fn from_byte(bytes: &[u8]) -> Result<Self, String> {
StmAggrVerificationKey::<blake2::Blake2b>::from_bytes(bytes).map_err(|_| format!("Failed"))
}

fn to_byte(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}

////////// Temporary trait, to understand the flaky tests ///////////

/// Encode key to hex helper
pub fn key_encode_hex<T>(from: T) -> Result<String, String>
pub fn key_encode_hex<T>(from: &T) -> Result<String, String>
where
T: Serialize,
T: BytesConv,
{
Ok(serde_json::to_string(&from)
.map_err(|e| format!("can't convert to hex: {}", e))?
.encode_hex::<String>())
Ok(from.to_byte().encode_hex::<String>())
}

/// Decode key from hex helper
pub fn key_decode_hex<T>(from: &str) -> Result<T, String>
where
T: DeserializeOwned,
T: BytesConv,
{
let from_vec = Vec::from_hex(from).map_err(|e| format!("can't parse from hex: {}", e))?;
serde_json::from_slice(from_vec.as_slice()).map_err(|e| format!("can't deserialize: {}", e))
T::from_byte(&from_vec)
}

#[cfg(test)]
Expand All @@ -42,7 +100,7 @@ pub mod tests {
let verification_key: ProtocolSignerVerificationKey =
protocol_initializer.verification_key();
let verification_key_hex =
key_encode_hex(verification_key).expect("unexpected hex encoding error");
key_encode_hex(&verification_key).expect("unexpected hex encoding error");
let verification_key_restored =
key_decode_hex(&verification_key_hex).expect("unexpected hex decoding error");
assert_eq!(verification_key, verification_key_restored);
Expand Down
7 changes: 6 additions & 1 deletion mithril-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
digest = { version = "0.9.0", features=["alloc"] }
blst = "0.3.7"
#blst = "0.3.7"
bls12_381 = { version = "0.7.0", features=["experimental"] }
#blstrs = "0.4.2"
ff = "0.12"
group = { version = "0.12.0", features = ["tests"] }

num-bigint = "0.4.0"
num-rational = "0.4.0"
num-traits = "0.2.14"
Expand Down
2 changes: 2 additions & 0 deletions mithril-core/proptest-regressions/stm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 31b06535674c5a44ff216443cbd6d1b7a694cc79aa89c394aa189e1c1fea061d # shrinks to msg = [0, 0, 4, 8, 1, 1, 0, 2, 7, 3, 22, 62, 62, 38, 23, 0], misbehaving_parties = 2
cc 4d730f7c017eefd41e0c15b7507153173b1ab32e35d1847b0e8ee3af9e71a1e6 # shrinks to msg = [153, 245, 99, 170, 115, 216, 160, 137, 5, 33, 137, 38, 199, 129, 165, 21]
cc 3ff681357b6e1bdb0d67ec6bd0ed81fe3bf8eb96bd437e4ab482161c7d254783 # shrinks to msg = [229, 102, 13, 206, 136, 125, 82, 87, 110, 14, 168, 139, 242, 227, 255, 132]
Loading