Skip to main content

mithril_stm/protocol/aggregate_signature/
aggregate_key.rs

1use crate::{
2    ClosedKeyRegistration, MembershipDigest, proof_system::AggregateVerificationKeyForConcatenation,
3};
4
5#[cfg(feature = "future_snark")]
6use crate::proof_system::AggregateVerificationKeyForSnark;
7
8/// Aggregate verification key combining both the concatenation and SNARK proof systems.
9///
10/// Holds the concatenation aggregate verification key used in the current Mithril protocol,
11/// and optionally the SNARK aggregate verification key when the `future_snark` feature is
12/// enabled.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct AggregateVerificationKey<D: MembershipDigest> {
15    /// Concatenation aggregate verification key.
16    concatenation_aggregate_verification_key: AggregateVerificationKeyForConcatenation<D>,
17    /// SNARK aggregate verification key (when `future_snark` feature is enabled).
18    #[cfg(feature = "future_snark")]
19    snark_aggregate_verification_key: Option<AggregateVerificationKeyForSnark<D>>,
20}
21
22impl<D: MembershipDigest> AggregateVerificationKey<D> {
23    /// Create a new aggregate verification key.
24    pub fn new(
25        concatenation_aggregate_verification_key: AggregateVerificationKeyForConcatenation<D>,
26        #[cfg(feature = "future_snark")] snark_aggregate_verification_key: Option<
27            AggregateVerificationKeyForSnark<D>,
28        >,
29    ) -> Self {
30        Self {
31            concatenation_aggregate_verification_key,
32            #[cfg(feature = "future_snark")]
33            snark_aggregate_verification_key,
34        }
35    }
36
37    /// Returns the concatenation aggregate verification key.
38    pub fn to_concatenation_aggregate_verification_key(
39        &self,
40    ) -> &AggregateVerificationKeyForConcatenation<D> {
41        &self.concatenation_aggregate_verification_key
42    }
43
44    /// Returns the SNARK aggregate verification key, if present.
45    #[cfg(feature = "future_snark")]
46    pub fn to_snark_aggregate_verification_key(
47        &self,
48    ) -> Option<&AggregateVerificationKeyForSnark<D>> {
49        self.snark_aggregate_verification_key.as_ref()
50    }
51}
52
53impl<D: MembershipDigest> From<&ClosedKeyRegistration> for AggregateVerificationKey<D> {
54    fn from(registration: &ClosedKeyRegistration) -> Self {
55        AggregateVerificationKey {
56            concatenation_aggregate_verification_key:
57                AggregateVerificationKeyForConcatenation::from(registration),
58            #[cfg(feature = "future_snark")]
59            snark_aggregate_verification_key: registration
60                .has_snark_verification_keys()
61                .then(|| AggregateVerificationKeyForSnark::from(registration)),
62        }
63    }
64}