Skip to content

Commit dcd1396

Browse files
committed
Adapt rest of the repo to changes
1 parent 80f5c69 commit dcd1396

File tree

4 files changed

+74
-24
lines changed

4 files changed

+74
-24
lines changed

mithril-aggregator/src/multi_signer.rs

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -696,34 +696,54 @@ impl MultiSigner for MultiSignerImpl {
696696
.get_protocol_parameters()
697697
.await?
698698
.ok_or_else(ProtocolError::UnavailableProtocolParameters)?;
699-
let avk = &self
699+
700+
let clerk = self
700701
.clerk
701702
.as_ref()
702-
.ok_or_else(ProtocolError::UnavailableClerk)?
703-
.compute_avk();
703+
.ok_or_else(ProtocolError::UnavailableClerk)?;
704704

705-
signatures
705+
let signature = signatures
706706
.to_protocol_signature()
707-
.map_err(ProtocolError::Codec)?
708-
.verify(&protocol_parameters, avk, message.compute_hash().as_bytes())
709-
.map_err(|e| ProtocolError::Core(e.to_string()))?;
710-
711-
// Register single signature
712-
let beacon = self
713-
.current_beacon
714-
.as_ref()
715-
.ok_or_else(ProtocolError::UnavailableBeacon)?;
707+
.map_err(ProtocolError::Codec)?;
708+
709+
let avk = clerk.compute_avk();
710+
711+
// If there is no reg_party, then we simply received a signature from a non-registered
712+
// party, and we can ignore the request.
713+
if let Some((vk, stake)) = clerk.get_reg_party(&signature.signer_index) {
714+
signature
715+
.verify(
716+
&protocol_parameters,
717+
&vk,
718+
&stake,
719+
&avk,
720+
message.compute_hash().as_bytes(),
721+
)
722+
.map_err(|e| ProtocolError::Core(e.to_string()))?;
716723

717-
match self
718-
.single_signature_store
719-
.save_single_signatures(beacon, signatures)
720-
.await?
721-
{
722-
Some(_) => Err(ProtocolError::ExistingSingleSignature(
723-
signatures.party_id.clone(),
724-
)),
725-
None => Ok(()),
724+
// Register single signature
725+
let beacon = self
726+
.current_beacon
727+
.as_ref()
728+
.ok_or_else(ProtocolError::UnavailableBeacon)?;
729+
730+
match self
731+
.single_signature_store
732+
.save_single_signatures(beacon, signatures)
733+
.await?
734+
{
735+
Some(_) => {
736+
return Err(ProtocolError::ExistingSingleSignature(
737+
signatures.party_id.clone(),
738+
));
739+
}
740+
None => {
741+
return Ok(());
742+
}
743+
}
726744
}
745+
746+
Ok(())
727747
}
728748

729749
/// Retrieves a multi signature from a message

mithril-signer/src/single_signer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,13 @@ mod tests {
271271
let decoded_sig: ProtocolSingleSignature = key_decode_hex(&sign_result.signature).unwrap();
272272
assert!(
273273
decoded_sig
274-
.verify(&protocol_parameters, &avk, &expected_message)
274+
.verify(
275+
&protocol_parameters,
276+
&protocol_signer.verification_key(),
277+
&protocol_signer.get_stake(),
278+
&avk,
279+
&expected_message
280+
)
275281
.is_ok(),
276282
"produced single signature should be valid"
277283
);

mithril-stm/src/merkle_tree.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ impl MTLeaf {
9191
}
9292
}
9393

94+
impl From<MTLeaf> for (StmVerificationKey, Stake) {
95+
fn from(leaf: MTLeaf) -> (StmVerificationKey, Stake) {
96+
(leaf.0, leaf.1)
97+
}
98+
}
99+
94100
impl PartialOrd for MTLeaf {
95101
/// Ordering of MT Values.
96102
///

mithril-stm/src/stm.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ pub struct StmInitializer {
169169
/// Participant in the protocol can sign messages.
170170
/// This instance can only be generated out of an `StmInitializer` and a `ClosedKeyReg`.
171171
/// This ensures that a `MerkleTree` root is not computed before all participants have registered.
172-
#[allow(dead_code)]
173172
#[derive(Debug, Clone)]
174173
pub struct StmSigner<D: Digest> {
175174
mt_index: u64,
@@ -399,6 +398,16 @@ impl<D: Clone + Digest + FixedOutput> StmSigner<D> {
399398
pub fn get_closed_reg(self) -> ClosedKeyReg<D> {
400399
self.closed_reg
401400
}
401+
402+
/// Extract the verification key.
403+
pub fn verification_key(&self) -> StmVerificationKey {
404+
self.vk
405+
}
406+
407+
/// Extract stake from the signer.
408+
pub fn get_stake(&self) -> Stake {
409+
self.stake
410+
}
402411
}
403412

404413
impl<D: Digest + Clone + FixedOutput> StmClerk<D> {
@@ -546,6 +555,15 @@ impl<D: Digest + Clone + FixedOutput> StmClerk<D> {
546555
pub fn compute_avk(&self) -> StmAggrVerificationKey<D> {
547556
StmAggrVerificationKey::from(&self.closed_reg)
548557
}
558+
559+
/// Get the (VK, stake) of a party given it's index.
560+
pub fn get_reg_party(&self, party_index: &Index) -> Option<(StmVerificationKey, Stake)> {
561+
if *party_index as usize >= self.closed_reg.reg_parties.len() {
562+
return None;
563+
}
564+
565+
Some(self.closed_reg.reg_parties[*party_index as usize].into())
566+
}
549567
}
550568

551569
impl StmSig {

0 commit comments

Comments
 (0)