fold.rs

Overview

This file provides functionality to fold multiple BLS-signed attestations into a single aggregated attestation envelope. Folding is an operation that aggregates multiple individual signatures and their associated signer information into one combined signature. This reduces overhead and improves efficiency when handling attestations in consensus or validation protocols.

The main public function is try_fold, which attempts to fold a list of signatures with their signer occurrences optimistically first, and if that fails, falls back to a more granular one-by-one folding with signature verification. The result indicates the successfully folded envelope (if any) and the set of "poisoned" envelopes that failed verification or merging.

This file interacts primarily with:

The folding process is critical in aggregating attestations securely and efficiently in the broader consensus or attestation processing system.


Structs

TryFoldResult

pub struct TryFoldResult {
    pub folded: Option<Envelope<GoshBLS, AttestationData>>,
    pub poisoned: Vec<Envelope<GoshBLS, AttestationData>>,
}

Functions

try_fold

pub fn try_fold(
    attestation_data: AttestationData,
    to_combine: Vec<(HashMap<SignerIndex, u16>, Signature)>,
    bk_set: &BlockKeeperSet,
) -> TryFoldResult

try_fold_all_optimistic

fn try_fold_all_optimistic(
    attestation_data: AttestationData,
    to_combine: &[(HashMap<SignerIndex, u16>, Signature)],
    bk_set: &BlockKeeperSet,
) -> Option<Envelope<GoshBLS, AttestationData>>

try_fold_one_by_one_checked

fn try_fold_one_by_one_checked(
    attestation_data: AttestationData,
    to_combine: Vec<(HashMap<SignerIndex, u16>, Signature)>,
    bk_set: &BlockKeeperSet,
) -> TryFoldResult

Important Implementation Details


Interactions with Other System Components

These dependencies indicate this file is part of a larger attestation and consensus subsystem responsible for signature aggregation and verification.


Visual Diagram

flowchart TD
A[try_fold] --> B[try_fold_all_optimistic]
B -->|Success| C[Return folded Envelope]
B -->|Fail| D[try_fold_one_by_one_checked]
D --> E[Iterate signatures]
E --> F{Verify signature}
F -->|Ok| G{Folded envelope exists?}
G -->|Yes| H[Merge signature into folded envelope]
G -->|No| I[Set folded envelope = current envelope]
F -->|Fail| J[Add envelope to poisoned list]
D --> K[Return TryFoldResult with folded & poisoned]
subgraph Inputs
attestation_data
to_combine
bk_set
end
subgraph Outputs
TryFoldResult
end
A --> Outputs