Skip to content

Commit bc19ee5

Browse files
authored
Merge pull request #620 from input-output-hk/simplify-signature
Simplify signature
2 parents f85f10d + 6c9de9b commit bc19ee5

File tree

8 files changed

+156
-86
lines changed

8 files changed

+156
-86
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.

mithril-aggregator/src/multi_signer.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub enum ProtocolError {
3636
#[error("signer already registered")]
3737
ExistingSigner(),
3838

39+
/// Signer was not registered.
40+
#[error("signer did not register")]
41+
UnregisteredParty(),
42+
3943
/// Signer registration failed.
4044
#[error("signer registration failed")]
4145
FailedSignerRegistration(#[from] ProtocolRegistrationError),
@@ -696,16 +700,31 @@ impl MultiSigner for MultiSignerImpl {
696700
.get_protocol_parameters()
697701
.await?
698702
.ok_or_else(ProtocolError::UnavailableProtocolParameters)?;
699-
let avk = &self
703+
704+
let clerk = self
700705
.clerk
701706
.as_ref()
702-
.ok_or_else(ProtocolError::UnavailableClerk)?
703-
.compute_avk();
707+
.ok_or_else(ProtocolError::UnavailableClerk)?;
704708

705-
signatures
709+
let signature = signatures
706710
.to_protocol_signature()
707-
.map_err(ProtocolError::Codec)?
708-
.verify(&protocol_parameters, avk, message.compute_hash().as_bytes())
711+
.map_err(ProtocolError::Codec)?;
712+
713+
let avk = clerk.compute_avk();
714+
715+
// If there is no reg_party, then we simply received a signature from a non-registered
716+
// party, and we can ignore the request.
717+
let (vk, stake) = clerk
718+
.get_reg_party(&signature.signer_index)
719+
.ok_or_else(ProtocolError::UnregisteredParty)?;
720+
signature
721+
.verify(
722+
&protocol_parameters,
723+
&vk,
724+
&stake,
725+
&avk,
726+
message.compute_hash().as_bytes(),
727+
)
709728
.map_err(|e| ProtocolError::Core(e.to_string()))?;
710729

711730
// Register single signature
@@ -714,7 +733,7 @@ impl MultiSigner for MultiSignerImpl {
714733
.as_ref()
715734
.ok_or_else(ProtocolError::UnavailableBeacon)?;
716735

717-
match self
736+
return match self
718737
.single_signature_store
719738
.save_single_signatures(beacon, signatures)
720739
.await?
@@ -723,7 +742,7 @@ impl MultiSigner for MultiSignerImpl {
723742
signatures.party_id.clone(),
724743
)),
725744
None => Ok(()),
726-
}
745+
};
727746
}
728747

729748
/// 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/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-stm"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = { workspace = true }
55
authors = { workspace = true }
66
documentation = { workspace = true }

mithril-stm/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ fn main() {
116116
let avk = clerk.compute_avk();
117117

118118
// Check all parties can verify every sig
119-
for s in sigs.iter() {
120-
assert!(s.verify(&params, &avk, &msg).is_ok(), "Verification failed");
119+
for (s, p) in sigs.iter().zip(ps.iter()) {
120+
assert!(s.verify(&params, &p.verification_key(), &p.get_stake(), &avk, &msg).is_ok(), "Verification failed");
121121
}
122122

123123
// Aggregate with random parties
@@ -143,7 +143,7 @@ fn main() {
143143

144144
Here we give the benchmark results of STM for size and time. We run the benchmarks on macOS 12.6 on an Apple M1 Pro machine with 16 GB of RAM.
145145

146-
Note that the size of an individual signature with one valid index is **176 bytes** and increases linearly in the length of valid indices (where an index is 8 bytes).
146+
Note that the size of an individual signature with one valid index is **72 bytes** (48 bytes from `sigma`, 8 bytes from `party_index`, 8 bytes for the `length` of winning indices and at least 8 bytes for a single winning `index`) and increases linearly in the length of valid indices (where an index is 8 bytes).
147147

148148
```shell
149149
+----------------------+

mithril-stm/src/merkle_tree.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Creation and verification of Merkle Trees
22
use crate::error::MerkleTreeError;
33
use crate::multi_sig::VerificationKey;
4-
use crate::stm::Stake;
5-
use blake2::digest::{Digest, FixedOutput};
4+
use crate::stm::{Stake, StmVerificationKey};
5+
use blake2::digest::{consts::U32, Digest, FixedOutput};
6+
use blake2::Blake2b;
67
use serde::{Deserialize, Serialize};
78
use std::cmp::Ordering;
89
use std::convert::TryFrom;
@@ -74,6 +75,14 @@ pub struct MerkleTree<D: Digest> {
7475
}
7576

7677
impl MTLeaf {
78+
pub(crate) fn from_bytes(bytes: &[u8]) -> Result<Self, MerkleTreeError<Blake2b<U32>>> {
79+
let pk = StmVerificationKey::from_bytes(bytes)
80+
.map_err(|_| MerkleTreeError::SerializationError)?;
81+
let mut u64_bytes = [0u8; 8];
82+
u64_bytes.copy_from_slice(&bytes[96..]);
83+
let stake = Stake::from_be_bytes(u64_bytes);
84+
Ok(MTLeaf(pk, stake))
85+
}
7786
pub(crate) fn to_bytes(self) -> [u8; 104] {
7887
let mut result = [0u8; 104];
7988
result[..96].copy_from_slice(&self.0.to_bytes());
@@ -82,6 +91,12 @@ impl MTLeaf {
8291
}
8392
}
8493

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

0 commit comments

Comments
 (0)