Skip to content

Commit 8240859

Browse files
committed
Refactor protocol demo types
Also remove the 'allow_skip_signer_certification' feature that was misused. Use directly 'mithril-stm' as dependency in this crate to retrieve protocol types.
1 parent 16cf8fe commit 8240859

File tree

7 files changed

+77
-39
lines changed

7 files changed

+77
-39
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/protocol-demo/Cargo.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithrildemo"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
documentation = { workspace = true }
@@ -10,14 +10,23 @@ repository = { workspace = true }
1010

1111
[dependencies]
1212
base64 = "0.13.0"
13+
blake2 = "0.10.4"
1314
clap = { version = "4.0.18", features = ["derive"] }
1415
hex = "0.4.3"
1516
log = "0.4.14"
16-
mithril-common = { path = "../../mithril-common", features = ["allow_skip_signer_certification"] }
17+
mithril-common = { path = "../../mithril-common" }
1718
rand_chacha = "0.3.1"
1819
rand_core = "0.6.3"
1920
serde = { version = "1.0", features = ["derive"] }
2021
serde_json = "1.0"
2122

23+
[target.'cfg(not(windows))'.dependencies]
24+
# non-windows: use default rug backend
25+
mithril-stm = { path = "../../mithril-stm" }
26+
27+
[target.'cfg(windows)'.dependencies]
28+
# Windows doesn't support rug backend, fallback to num-integer
29+
mithril-stm = { path = "../../mithril-stm", default-features = false, features = ["num-integer-backend"] }
30+
2231
[features]
23-
portable = ["mithril-common/portable"]
32+
portable = ["mithril-common/portable", "mithril-stm/portable"]

demo/protocol-demo/src/demonstrator.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use std::fs;
77
use std::io::Write;
88
use std::path;
99

10-
use mithril_common::crypto_helper::{
11-
key_decode_hex, key_encode_hex, ProtocolClerk, ProtocolInitializerNotCertified,
12-
ProtocolKeyRegistrationNotCertified, ProtocolMultiSignature, ProtocolParameters,
13-
ProtocolPartyId, ProtocolSigner, ProtocolSignerVerificationKey, ProtocolSingleSignature,
14-
ProtocolStake,
10+
use mithril_common::crypto_helper::{key_decode_hex, key_encode_hex};
11+
12+
use crate::types::{
13+
ProtocolClerk, ProtocolInitializerNotCertified, ProtocolKeyRegistrationNotCertified,
14+
ProtocolMultiSignature, ProtocolParameters, ProtocolPartyId, ProtocolSigner,
15+
ProtocolSignerVerificationKey, ProtocolSingleSignature, ProtocolStake,
1516
};
1617

1718
/// Player artifacts

demo/protocol-demo/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod demonstrator;
2+
mod types;
23

34
use crate::demonstrator::{Demonstrator, ProtocolDemonstrator};
45
use clap::Parser;

demo/protocol-demo/src/types.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use mithril_stm::key_reg::KeyReg;
2+
use mithril_stm::stm::{
3+
Stake, StmAggrSig, StmClerk, StmInitializer, StmParameters, StmSig, StmSigner,
4+
StmVerificationKeyPoP,
5+
};
6+
7+
use blake2::{digest::consts::U32, Blake2b};
8+
9+
// Protocol types alias
10+
type D = Blake2b<U32>;
11+
12+
/// The id of a mithril party.
13+
pub type ProtocolPartyId = String;
14+
15+
/// Alias of [MithrilStm:Stake](type@mithril_stm::stm::Stake).
16+
pub type ProtocolStake = Stake;
17+
18+
/// Alias of [MithrilStm::StmParameters](struct@mithril_stm::stm::StmParameters).
19+
pub type ProtocolParameters = StmParameters;
20+
21+
/// Alias of [MithrilStm:StmSigner](struct@mithril_stm::stm::StmSigner).
22+
pub type ProtocolSigner = StmSigner<D>;
23+
24+
/// Alias of [MithrilStm:StmClerk](struct@mithril_stm::stm::StmClerk).
25+
pub type ProtocolClerk = StmClerk<D>;
26+
27+
/// Alias of [MithrilStm:StmInitializer](struct@mithril_stm::stm::StmInitializer).
28+
pub type ProtocolInitializerNotCertified = StmInitializer;
29+
30+
/// Alias of [MithrilStm:KeyReg](struct@mithril_stm::key_reg::KeyReg). (Test only)
31+
pub type ProtocolKeyRegistrationNotCertified = KeyReg;
32+
33+
/// Alias of [MithrilStm:StmSig](struct@mithril_stm::stm::StmSig).
34+
pub type ProtocolSingleSignature = StmSig;
35+
36+
/// Alias of [MithrilStm:StmAggrSig](struct@mithril_stm::stm::StmAggrSig).
37+
pub type ProtocolMultiSignature = StmAggrSig<D>;
38+
39+
/// Alias of [MithrilStm:StmVerificationKeyPoP](type@mithril_stm::stm::StmVerificationKeyPoP).
40+
pub type ProtocolSignerVerificationKey = StmVerificationKeyPoP;

mithril-common/src/crypto_helper/codec.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,24 @@ where
2525

2626
#[cfg(test)]
2727
pub mod tests {
28-
use super::super::tests_setup::*;
29-
use super::super::types::*;
30-
use super::*;
28+
use serde::{Deserialize, Serialize};
3129

32-
use rand_chacha::ChaCha20Rng;
33-
use rand_core::SeedableRng;
30+
use super::{key_decode_hex, key_encode_hex};
31+
32+
#[derive(Debug, PartialEq, Serialize, Deserialize)]
33+
struct TestSerialize {
34+
inner_string: String,
35+
}
3436

3537
#[test]
3638
fn test_key_encode_decode_hex() {
37-
let protocol_params = setup_protocol_parameters();
38-
let stake = 100;
39-
let seed = [0u8; 32];
40-
let mut rng = ChaCha20Rng::from_seed(seed);
41-
let protocol_initializer =
42-
ProtocolInitializerNotCertified::setup(protocol_params, stake, &mut rng);
43-
let verification_key: ProtocolSignerVerificationKey =
44-
protocol_initializer.verification_key();
45-
let verification_key_hex =
46-
key_encode_hex(verification_key).expect("unexpected hex encoding error");
47-
let verification_key_restored =
48-
key_decode_hex(&verification_key_hex).expect("unexpected hex decoding error");
49-
assert_eq!(verification_key, verification_key_restored);
39+
let test_to_serialize = TestSerialize {
40+
inner_string: "my inner string".to_string(),
41+
};
42+
let test_to_serialize_hex =
43+
key_encode_hex(&test_to_serialize).expect("unexpected hex encoding error");
44+
let test_to_serialize_restored =
45+
key_decode_hex(&test_to_serialize_hex).expect("unexpected hex decoding error");
46+
assert_eq!(test_to_serialize, test_to_serialize_restored);
5047
}
5148
}

mithril-common/src/crypto_helper/types.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ use mithril_stm::stm::{
88
};
99
use mithril_stm::AggregationError;
1010

11-
#[cfg(any(test, feature = "allow_skip_signer_certification"))]
12-
use mithril_stm::{key_reg::KeyReg, stm::StmInitializer};
13-
1411
use blake2::{digest::consts::U32, Blake2b};
1512
use ed25519_dalek;
1613
use kes_summed_ed25519::kes::Sum6KesSig;
@@ -78,12 +75,3 @@ pub type ProtocolRegistrationError = ProtocolRegistrationErrorWrapper;
7875

7976
/// Alias of [MithrilStm:AggregationError](enum@mithril_stm::AggregationError).
8077
pub type ProtocolAggregationError = AggregationError;
81-
82-
// Test only
83-
/// (Test only) Alias of [MithrilStm:StmInitializer](struct@mithril_stm::stm::StmInitializer).
84-
#[cfg(any(test, feature = "allow_skip_signer_certification"))]
85-
pub type ProtocolInitializerNotCertified = StmInitializer;
86-
87-
/// (Test only) Alias of [MithrilStm:KeyReg](struct@mithril_stm::key_reg::KeyReg). (Test only)
88-
#[cfg(any(test, feature = "allow_skip_signer_certification"))]
89-
pub type ProtocolKeyRegistrationNotCertified = KeyReg;

0 commit comments

Comments
 (0)