Skip to content

Commit 6833d2f

Browse files
authored
Merge pull request #2629 from input-output-hk/curiecrypt/deprecate-old-structs
Enhance STM library readability - Deprecate Old Structs
2 parents 81d08dc + a5b7cc1 commit 6833d2f

File tree

24 files changed

+201
-162
lines changed

24 files changed

+201
-162
lines changed

Cargo.lock

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

demo/protocol-demo/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ Party #1: party created with 741 stakes
7373
Party #2: party created with 144 stakes
7474
Party #3: party created with 734 stakes
7575
Party #4: party created with 41 stakes
76-
Protocol established to StmParameters { m: 100, k: 5, phi_f: 0.2 }
76+
Protocol established to Parameters { m: 100, k: 5, phi_f: 0.2 }
7777
7878
>> Protocol initialize phase:
7979
Verifier: verifier created
80-
Verifier: protocol params updated to StmParameters { m: 100, k: 5, phi_f: 0.2 }
81-
Party #0: protocol params updated to StmParameters { m: 100, k: 5, phi_f: 0.2 }
82-
Party #1: protocol params updated to StmParameters { m: 100, k: 5, phi_f: 0.2 }
83-
Party #2: protocol params updated to StmParameters { m: 100, k: 5, phi_f: 0.2 }
84-
Party #3: protocol params updated to StmParameters { m: 100, k: 5, phi_f: 0.2 }
85-
Party #4: protocol params updated to StmParameters { m: 100, k: 5, phi_f: 0.2 }
80+
Verifier: protocol params updated to Parameters { m: 100, k: 5, phi_f: 0.2 }
81+
Party #0: protocol params updated to Parameters { m: 100, k: 5, phi_f: 0.2 }
82+
Party #1: protocol params updated to Parameters { m: 100, k: 5, phi_f: 0.2 }
83+
Party #2: protocol params updated to Parameters { m: 100, k: 5, phi_f: 0.2 }
84+
Party #3: protocol params updated to Parameters { m: 100, k: 5, phi_f: 0.2 }
85+
Party #4: protocol params updated to Parameters { m: 100, k: 5, phi_f: 0.2 }
8686
Verifier: protocol keys registration from [(0, 826), (1, 741), (2, 144), (3, 734), (4, 41)]
8787
Party #0: protocol keys registration from [(0, 826), (1, 741), (2, 144), (3, 734), (4, 41)]
8888
Party #1: protocol keys registration from [(0, 826), (1, 741), (2, 144), (3, 734), (4, 41)]

demo/protocol-demo/src/types.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use mithril_stm::{
2-
KeyReg, Stake, StmAggrSig, StmClerk, StmInitializer, StmParameters, StmSig, StmSigner,
3-
StmVerificationKeyPoP,
2+
AggregateSignature, Clerk, Initializer, KeyRegistration, Parameters, Signer, SingleSignature,
3+
Stake, VerificationKeyProofOfPossession,
44
};
55

66
use blake2::{Blake2b, digest::consts::U32};
@@ -14,26 +14,26 @@ pub type ProtocolPartyId = String;
1414
/// Alias of [MithrilStm:Stake](type@mithril_stm::Stake).
1515
pub type ProtocolStake = Stake;
1616

17-
/// Alias of [MithrilStm::StmParameters](struct@mithril_stm::StmParameters).
18-
pub type ProtocolParameters = StmParameters;
17+
/// Alias of [MithrilStm::Parameters](struct@mithril_stm::Parameters).
18+
pub type ProtocolParameters = Parameters;
1919

20-
/// Alias of [MithrilStm:StmSigner](struct@mithril_stm::StmSigner).
21-
pub type ProtocolSigner = StmSigner<D>;
20+
/// Alias of [MithrilStm:Signer](struct@mithril_stm::Signer).
21+
pub type ProtocolSigner = Signer<D>;
2222

23-
/// Alias of [MithrilStm:StmClerk](struct@mithril_stm::StmClerk).
24-
pub type ProtocolClerk = StmClerk<D>;
23+
/// Alias of [MithrilStm:Clerk](struct@mithril_stm::Clerk).
24+
pub type ProtocolClerk = Clerk<D>;
2525

26-
/// Alias of [MithrilStm:StmInitializer](struct@mithril_stm::StmInitializer).
27-
pub type ProtocolInitializerNotCertified = StmInitializer;
26+
/// Alias of [MithrilStm:Initializer](struct@mithril_stm::Initializer).
27+
pub type ProtocolInitializerNotCertified = Initializer;
2828

29-
/// Alias of [MithrilStm:KeyReg](struct@mithril_stm::KeyReg). (Test only)
30-
pub type ProtocolKeyRegistrationNotCertified = KeyReg;
29+
/// Alias of [MithrilStm:KeyRegistration](struct@mithril_stm::KeyRegistration). (Test only)
30+
pub type ProtocolKeyRegistrationNotCertified = KeyRegistration;
3131

32-
/// Alias of [MithrilStm:StmSig](struct@mithril_stm::StmSig).
33-
pub type ProtocolSingleSignature = StmSig;
32+
/// Alias of [MithrilStm:SingleSignature](struct@mithril_stm::SingleSignature).
33+
pub type ProtocolSingleSignature = SingleSignature;
3434

35-
/// Alias of [MithrilStm:StmAggrSig](struct@mithril_stm::StmAggrSig).
36-
pub type ProtocolMultiSignature = StmAggrSig<D>;
35+
/// Alias of [MithrilStm:AggregateSignature](struct@mithril_stm::AggregateSignature).
36+
pub type ProtocolMultiSignature = AggregateSignature<D>;
3737

38-
/// Alias of [MithrilStm:StmVerificationKeyPoP](type@mithril_stm::StmVerificationKeyPoP).
39-
pub type ProtocolSignerVerificationKey = StmVerificationKeyPoP;
38+
/// Alias of [MithrilStm:VerificationKeyProofOfPossession](type@mithril_stm::VerificationKeyProofOfPossession).
39+
pub type ProtocolSignerVerificationKey = VerificationKeyProofOfPossession;

docs/website/root/manual/develop/protocol-simulation.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ Party #1: party created with 741 stakes
130130
Party #2: party created with 144 stakes
131131
Party #3: party created with 734 stakes
132132
Party #4: party created with 41 stakes
133-
Protocol established to StmParameters { m: 50, k: 5, phi_f: 0.65 }
133+
Protocol established to Parameters { m: 50, k: 5, phi_f: 0.65 }
134134

135135
>> Protocol initialization phase:
136136
Verifier: verifier created
137-
Verifier: protocol params updated to StmParameters { m: 50, k: 5, phi_f: 0.65 }
138-
Party #0: protocol params updated to StmParameters { m: 50, k: 5, phi_f: 0.65 }
139-
Party #1: protocol params updated to StmParameters { m: 50, k: 5, phi_f: 0.65 }
140-
Party #2: protocol params updated to StmParameters { m: 50, k: 5, phi_f: 0.65 }
141-
Party #3: protocol params updated to StmParameters { m: 50, k: 5, phi_f: 0.65 }
142-
Party #4: protocol params updated to StmParameters { m: 50, k: 5, phi_f: 0.65 }
137+
Verifier: protocol params updated to Parameters { m: 50, k: 5, phi_f: 0.65 }
138+
Party #0: protocol params updated to Parameters { m: 50, k: 5, phi_f: 0.65 }
139+
Party #1: protocol params updated to Parameters { m: 50, k: 5, phi_f: 0.65 }
140+
Party #2: protocol params updated to Parameters { m: 50, k: 5, phi_f: 0.65 }
141+
Party #3: protocol params updated to Parameters { m: 50, k: 5, phi_f: 0.65 }
142+
Party #4: protocol params updated to Parameters { m: 50, k: 5, phi_f: 0.65 }
143143
Verifier: protocol keys registration from [("0", 826), ("1", 741), ("2", 144), ("3", 734), ("4", 41)]
144144
Party #0: protocol keys registration from [("0", 826), ("1", 741), ("2", 144), ("3", 734), ("4", 41)]
145145
Party #1: protocol keys registration from [("0", 826), ("1", 741), ("2", 144), ("3", 734), ("4", 41)]
@@ -252,16 +252,16 @@ Party #1: party created with 741 stakes
252252
Party #2: party created with 144 stakes
253253
Party #3: party created with 734 stakes
254254
Party #4: party created with 41 stakes
255-
Protocol established to StmParameters { m: 5, k: 5, phi_f: 0.25 }
255+
Protocol established to Parameters { m: 5, k: 5, phi_f: 0.25 }
256256

257257
>> Protocol initialization phase:
258258
Verifier: verifier created
259-
Verifier: protocol params updated to StmParameters { m: 5, k: 5, phi_f: 0.25 }
260-
Party #0: protocol params updated to StmParameters { m: 5, k: 5, phi_f: 0.25 }
261-
Party #1: protocol params updated to StmParameters { m: 5, k: 5, phi_f: 0.25 }
262-
Party #2: protocol params updated to StmParameters { m: 5, k: 5, phi_f: 0.25 }
263-
Party #3: protocol params updated to StmParameters { m: 5, k: 5, phi_f: 0.25 }
264-
Party #4: protocol params updated to StmParameters { m: 5, k: 5, phi_f: 0.25 }
259+
Verifier: protocol params updated to Parameters { m: 5, k: 5, phi_f: 0.25 }
260+
Party #0: protocol params updated to Parameters { m: 5, k: 5, phi_f: 0.25 }
261+
Party #1: protocol params updated to Parameters { m: 5, k: 5, phi_f: 0.25 }
262+
Party #2: protocol params updated to Parameters { m: 5, k: 5, phi_f: 0.25 }
263+
Party #3: protocol params updated to Parameters { m: 5, k: 5, phi_f: 0.25 }
264+
Party #4: protocol params updated to Parameters { m: 5, k: 5, phi_f: 0.25 }
265265
Verifier: protocol keys registration from [("0", 826), ("1", 741), ("2", 144), ("3", 734), ("4", 41)]
266266
Party #0: protocol keys registration from [("0", 826), ("1", 741), ("2", 144), ("3", 734), ("4", 41)]
267267
Party #1: protocol keys registration from [("0", 826), ("1", 741), ("2", 144), ("3", 734), ("4", 41)]

mithril-common/src/crypto_helper/cardano/key_certification.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! API for mithril key certification.
2-
//! Includes the wrappers for StmInitializer and KeyReg, and ProtocolRegistrationErrorWrapper.
2+
//! Includes the wrappers for Initializer and KeyRegistration, and ProtocolRegistrationErrorWrapper.
33
//! These wrappers allows keeping mithril-stm agnostic to Cardano, while providing some
44
//! guarantees that mithril-stm will not be misused in the context of Cardano.
55
@@ -15,8 +15,8 @@ use serde::{Deserialize, Serialize};
1515
use thiserror::Error;
1616

1717
use mithril_stm::{
18-
ClosedKeyReg, KeyReg, RegisterError, Stake, StmInitializer, StmParameters, StmSigner,
19-
StmVerificationKeyPoP,
18+
ClosedKeyRegistration, Initializer, KeyRegistration, Parameters, RegisterError, Signer, Stake,
19+
VerificationKeyProofOfPossession,
2020
};
2121

2222
use crate::{
@@ -95,13 +95,13 @@ pub enum ProtocolInitializerErrorWrapper {
9595
KesMismatch(KesPeriod, KesPeriod),
9696
}
9797

98-
/// Wrapper structure for [MithrilStm:StmInitializer](mithril_stm::stm::StmInitializer).
98+
/// Wrapper structure for [MithrilStm:Initializer](mithril_stm::stm::Initializer).
9999
/// It now obtains a KES signature over the Mithril key. This allows the signers prove
100100
/// their correct identity with respect to a Cardano PoolID.
101101
#[derive(Debug, Clone, Serialize, Deserialize)]
102102
pub struct StmInitializerWrapper {
103-
/// The StmInitializer
104-
stm_initializer: StmInitializer,
103+
/// The Initializer
104+
stm_initializer: Initializer,
105105

106106
/// The KES signature over the Mithril key
107107
///
@@ -110,17 +110,17 @@ pub struct StmInitializerWrapper {
110110
}
111111

112112
impl StmInitializerWrapper {
113-
/// Builds an `StmInitializer` that is ready to register with the key registration service.
113+
/// Builds an `Initializer` that is ready to register with the key registration service.
114114
/// This function generates the signing and verification key with a PoP, signs the verification
115115
/// key with a provided KES signer implementation, and initializes the structure.
116116
pub fn setup<R: RngCore + CryptoRng>(
117-
params: StmParameters,
117+
params: Parameters,
118118
kes_signer: Option<Arc<dyn KesSigner>>,
119119
kes_period: Option<KesPeriod>,
120120
stake: Stake,
121121
rng: &mut R,
122122
) -> StdResult<Self> {
123-
let stm_initializer = StmInitializer::setup(params, stake, rng);
123+
let stm_initializer = Initializer::setup(params, stake, rng);
124124
let kes_signature = if let Some(kes_signer) = kes_signer {
125125
let (signature, _op_cert) = kes_signer.sign(
126126
&stm_initializer.verification_key().to_bytes(),
@@ -142,7 +142,7 @@ impl StmInitializerWrapper {
142142
}
143143

144144
/// Extract the verification key.
145-
pub fn verification_key(&self) -> StmVerificationKeyPoP {
145+
pub fn verification_key(&self) -> VerificationKeyProofOfPossession {
146146
self.stm_initializer.verification_key()
147147
}
148148

@@ -163,8 +163,8 @@ impl StmInitializerWrapper {
163163

164164
/// Build the `avk` for the given list of parties.
165165
///
166-
/// Note that if this StmInitializer was modified *between* the last call to `register`,
167-
/// then the resulting `StmSigner` may not be able to produce valid signatures.
166+
/// Note that if this Initializer was modified *between* the last call to `register`,
167+
/// then the resulting `Signer` may not be able to produce valid signatures.
168168
///
169169
/// Returns a `StmSignerWrapper` specialized to
170170
/// * this `StmSignerWrapper`'s ID and current stake
@@ -175,8 +175,8 @@ impl StmInitializerWrapper {
175175
/// This function fails if the initializer is not registered.
176176
pub fn new_signer(
177177
self,
178-
closed_reg: ClosedKeyReg<D>,
179-
) -> Result<StmSigner<D>, ProtocolRegistrationErrorWrapper> {
178+
closed_reg: ClosedKeyRegistration<D>,
179+
) -> Result<Signer<D>, ProtocolRegistrationErrorWrapper> {
180180
self.stm_initializer
181181
.new_signer(closed_reg)
182182
.map_err(ProtocolRegistrationErrorWrapper::CoreRegister)
@@ -201,7 +201,7 @@ impl StmInitializerWrapper {
201201
/// The function fails if the given string of bytes is not of required size.
202202
pub fn from_bytes(bytes: &[u8]) -> Result<Self, RegisterError> {
203203
let stm_initializer =
204-
StmInitializer::from_bytes(bytes.get(..256).ok_or(RegisterError::SerializationError)?)?;
204+
Initializer::from_bytes(bytes.get(..256).ok_or(RegisterError::SerializationError)?)?;
205205
let bytes = bytes.get(256..).ok_or(RegisterError::SerializationError)?;
206206
let kes_signature = if bytes.is_empty() {
207207
None
@@ -216,14 +216,14 @@ impl StmInitializerWrapper {
216216
}
217217

218218
cfg_test_tools! {
219-
/// Override the protocol parameters of the `StmInitializer` for testing purposes only.
219+
/// Override the protocol parameters of the `Initializer` for testing purposes only.
220220
pub fn override_protocol_parameters(&mut self, protocol_parameters: &ProtocolParameters) {
221221
self.stm_initializer.params = protocol_parameters.to_owned();
222222
}
223223
}
224224
}
225225

226-
/// Wrapper structure for [MithrilStm:KeyReg](mithril_stm::key_reg::KeyReg).
226+
/// Wrapper structure for [MithrilStm:KeyRegistration](mithril_stm::key_reg::KeyRegistration).
227227
/// The wrapper not only contains a map between `Mithril vkey <-> Stake`, but also
228228
/// a map `PoolID <-> Stake`. This information is recovered from the node state, and
229229
/// is used to verify the identity of a Mithril signer. Furthermore, the `register` function
@@ -232,7 +232,7 @@ impl StmInitializerWrapper {
232232
#[derive(Debug, Clone)]
233233
pub struct KeyRegWrapper {
234234
kes_verifier: Arc<dyn KesVerifier>,
235-
stm_key_reg: KeyReg,
235+
stm_key_reg: KeyRegistration,
236236
stake_distribution: HashMap<ProtocolPartyId, Stake>,
237237
}
238238

@@ -242,7 +242,7 @@ impl KeyRegWrapper {
242242
pub fn init(stake_dist: &ProtocolStakeDistribution) -> Self {
243243
Self {
244244
kes_verifier: Arc::new(KesVerifierStandard),
245-
stm_key_reg: KeyReg::init(),
245+
stm_key_reg: KeyRegistration::init(),
246246
stake_distribution: HashMap::from_iter(stake_dist.to_vec()),
247247
}
248248
}
@@ -293,8 +293,8 @@ impl KeyRegWrapper {
293293
}
294294

295295
/// Finalize the key registration.
296-
/// This function disables `KeyReg::register`, consumes the instance of `self`, and returns a `ClosedKeyReg`.
297-
pub fn close<D: Digest + FixedOutput>(self) -> ClosedKeyReg<D> {
296+
/// This function disables `ClosedKeyRegistration::register`, consumes the instance of `self`, and returns a `ClosedKeyRegistration`.
297+
pub fn close<D: Digest + FixedOutput>(self) -> ClosedKeyRegistration<D> {
298298
self.stm_key_reg.close()
299299
}
300300
}
@@ -317,7 +317,7 @@ mod test {
317317

318318
#[test]
319319
fn test_vector_key_reg() {
320-
let params = StmParameters {
320+
let params = Parameters {
321321
m: 5,
322322
k: 5,
323323
phi_f: 1.0,

0 commit comments

Comments
 (0)