Skip to content

Commit

Permalink
Apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta committed Dec 2, 2022
1 parent a4f5811 commit 1a37204
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
63 changes: 31 additions & 32 deletions mithril-aggregator/src/multi_signer.rs
Expand Up @@ -36,6 +36,10 @@ pub enum ProtocolError {
#[error("signer already registered")]
ExistingSigner(),

/// Signer was not registered.
#[error("signer did not register")]
UnregisteredParty(),

/// Signer registration failed.
#[error("signer registration failed")]
FailedSignerRegistration(#[from] ProtocolRegistrationError),
Expand Down Expand Up @@ -717,40 +721,35 @@ impl MultiSigner for MultiSignerImpl {

// If there is no reg_party, then we simply received a signature from a non-registered
// party, and we can ignore the request.
if let Some((vk, stake)) = clerk.get_reg_party(&signature.signer_index) {
signature
.verify(
&protocol_parameters,
&vk,
&stake,
&avk,
message.compute_hash().as_bytes(),
)
.map_err(|e| ProtocolError::Core(e.to_string()))?;
let (vk, stake) = clerk
.get_reg_party(&signature.signer_index)
.ok_or_else(ProtocolError::UnregisteredParty)?;
signature
.verify(
&protocol_parameters,
&vk,
&stake,
&avk,
message.compute_hash().as_bytes(),
)
.map_err(|e| ProtocolError::Core(e.to_string()))?;

// Register single signature
let beacon = self
.current_beacon
.as_ref()
.ok_or_else(ProtocolError::UnavailableBeacon)?;

match self
.single_signature_store
.save_single_signatures(beacon, signatures)
.await?
{
Some(_) => {
return Err(ProtocolError::ExistingSingleSignature(
signatures.party_id.clone(),
));
}
None => {
return Ok(());
}
}
}
// Register single signature
let beacon = self
.current_beacon
.as_ref()
.ok_or_else(ProtocolError::UnavailableBeacon)?;

Ok(())
return match self
.single_signature_store
.save_single_signatures(beacon, signatures)
.await?
{
Some(_) => Err(ProtocolError::ExistingSingleSignature(
signatures.party_id.clone(),
)),
None => Ok(()),
};
}

/// Retrieves a multi signature from a message
Expand Down
2 changes: 1 addition & 1 deletion mithril-stm/README.md
Expand Up @@ -143,7 +143,7 @@ fn main() {

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.

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).
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).

```shell
+----------------------+
Expand Down
5 changes: 4 additions & 1 deletion mithril-stm/src/stm.rs
Expand Up @@ -558,7 +558,10 @@ impl<D: Digest + Clone + FixedOutput> StmClerk<D> {

/// Get the (VK, stake) of a party given its index.
pub fn get_reg_party(&self, party_index: &Index) -> Option<(StmVerificationKey, Stake)> {
self.closed_reg.reg_parties.get(*party_index as usize).map(|r| r.into())
self.closed_reg
.reg_parties
.get(*party_index as usize)
.map(|&r| r.into())
}
}

Expand Down

0 comments on commit 1a37204

Please sign in to comment.