compacted_attestation.rs

Overview

This file defines the CompactedAttestation struct and implements conversions between CompactedAttestation and the Envelope type specialized for GoshBLS signatures and AttestationData. The primary purpose is to represent and handle a compacted form of attestations, which aggregate multiple individual signatures efficiently. This facilitates optimized storage and processing of attestations within the system.

Key functionalities include:

Detailed Breakdown

Struct: CompactedAttestation

pub struct CompactedAttestation {
    parent_block_id: BlockIdentifier,
    envelope_hash: AckiNackiEnvelopeHash,
    aggregated_signature: <GoshBLS as BLSSignatureScheme>::Signature,
    signature_occurrences: BTreeMap<SignerIndex, u16>,
    target_type: AttestationTargetType,
}

Description

CompactedAttestation encapsulates a compact representation of an attestation that aggregates multiple signatures into one. It contains metadata about the parent block, a unique hash of the attestation envelope, the aggregated BLS signature, and a mapping of signers to the count of their signature occurrences.

Fields

Traits

Methods

signers

pub fn signers(&self) -> impl Iterator<Item = &SignerIndex>

Returns an iterator over the set of signers (SignerIndex) who contributed signatures to the aggregated signature.

let compacted: CompactedAttestation = /* obtain instance */;
for signer in compacted.signers() {
    println!("Signer index: {:?}", signer);
}

Trait Implementations for Conversion

From<&Envelope<GoshBLS, AttestationData>> for CompactedAttestation

fn from(value: &Envelope<GoshBLS, AttestationData>) -> Self

Creates a CompactedAttestation instance from a reference to an Envelope containing AttestationData signed with GoshBLS.

Usage example:

let envelope: Envelope<GoshBLS, AttestationData> = /* existing envelope */;
let compacted: CompactedAttestation = CompactedAttestation::from(&envelope);

From<(CompactedAttestation, &CompactedMapKey)> for Envelope<GoshBLS, AttestationData>

fn from(value: (CompactedAttestation, &CompactedMapKey)) -> Self

Reconstructs an Envelope from a tuple containing a CompactedAttestation and a reference to a CompactedMapKey.

Usage example:

let compacted: CompactedAttestation = /* existing compacted attestation */;
let map_key: &CompactedMapKey = /* reference to map key */;
let envelope: Envelope<GoshBLS, AttestationData> = (compacted, map_key).into();

Implementation Details and Algorithms

Interaction with Other Modules

Visual Diagram

classDiagram
class CompactedAttestation {
-parent_block_id: BlockIdentifier
-envelope_hash: AckiNackiEnvelopeHash
-aggregated_signature: Signature
-signature_occurrences: BTreeMap<SignerIndex, u16>
-target_type: AttestationTargetType
+signers(): Iterator<SignerIndex>
}
class Envelope {
<<generic>>
+create()
}
class CompactedMapKey {
+block_identifier()
+block_seq_no()
}
CompactedAttestation --> "1" Envelope : converts to/from
CompactedAttestation --> "1" CompactedMapKey : uses in conversion