Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/testing/src/consensus_testing/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
AttestationSignatures,
)
from lean_spec.subspecs.containers.slot import Slot
from lean_spec.subspecs.containers.state.types import AttestationSignatureKey
from lean_spec.subspecs.xmss.aggregation import MultisigAggregatedSignature
from lean_spec.subspecs.xmss.aggregation import (
AttestationSignatureKey,
MultisigAggregatedSignature,
)
from lean_spec.subspecs.xmss.containers import KeyPair, PublicKey, Signature
from lean_spec.subspecs.xmss.interface import (
PROD_SIGNATURE_SCHEME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
from lean_spec.subspecs.containers.slot import Slot
from lean_spec.subspecs.containers.state import Validators
from lean_spec.subspecs.containers.state.state import State
from lean_spec.subspecs.containers.state.types import AttestationSignatureKey
from lean_spec.subspecs.forkchoice import Store
from lean_spec.subspecs.koalabear import Fp
from lean_spec.subspecs.ssz import hash_tree_root
from lean_spec.subspecs.xmss.aggregation import AttestationSignatureKey
from lean_spec.subspecs.xmss.containers import Signature
from lean_spec.subspecs.xmss.types import HashDigestList, HashTreeOpening, Randomness
from lean_spec.types import Bytes32, Uint64
Expand Down
14 changes: 6 additions & 8 deletions src/lean_spec/subspecs/containers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
AggregationBits,
Attestation,
AttestationData,
NaiveAggregatedSignature,
SignedAggregatedAttestation,
AttestationsByValidator,
SignedAttestation,
)
from .block import (
Expand All @@ -31,19 +30,18 @@

__all__ = [
"AggregatedAttestation",
"NaiveAggregatedSignature",
"AggregationBits",
"AttestationData",
"Attestation",
"SignedAttestation",
"SignedAggregatedAttestation",
"AttestationData",
"AttestationsByValidator",
"Block",
"BlockWithAttestation",
"BlockBody",
"BlockHeader",
"BlockWithAttestation",
"Checkpoint",
"Config",
"SignedAttestation",
"SignedBlockWithAttestation",
"Validator",
"State",
"Validator",
]
12 changes: 5 additions & 7 deletions src/lean_spec/subspecs/containers/attestation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
AggregatedAttestation,
Attestation,
AttestationData,
SignedAggregatedAttestation,
SignedAttestation,
)
from .types import AggregationBits, NaiveAggregatedSignature
from .types import AggregationBits, AttestationsByValidator

__all__ = [
"AttestationData",
"Attestation",
"SignedAttestation",
"SignedAggregatedAttestation",
"AggregatedAttestation",
"NaiveAggregatedSignature",
"AggregationBits",
"Attestation",
"AttestationData",
"AttestationsByValidator",
"SignedAttestation",
]
21 changes: 1 addition & 20 deletions src/lean_spec/subspecs/containers/attestation/attestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from ...xmss.containers import Signature
from ..checkpoint import Checkpoint
from .types import AggregationBits, NaiveAggregatedSignature
from .types import AggregationBits


class AttestationData(Container):
Expand Down Expand Up @@ -107,22 +107,3 @@ def aggregate_by_data(
)
for data, validator_ids in data_to_validator_ids.items()
]


class SignedAggregatedAttestation(Container):
"""Aggregated attestation bundled with aggregated signatures."""

message: AggregatedAttestation
"""Aggregated attestation data."""

signature: NaiveAggregatedSignature
"""Aggregated attestation plus its combined signature.

Stores a naive list of validator signatures that mirrors the attestation
order.

TODO:
- signatures will be replaced by MegaBytes in next PR to include leanVM proof.
- this will be replaced by a SNARK in future devnets.
- this will be aggregated by aggregators in future devnets.
"""
18 changes: 9 additions & 9 deletions src/lean_spec/subspecs/containers/attestation/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

from __future__ import annotations

from lean_spec.types import SSZList, Uint64
from typing import TYPE_CHECKING

from lean_spec.types import Uint64
from lean_spec.types.bitfields import BaseBitlist

from ...chain.config import VALIDATOR_REGISTRY_LIMIT
from ...xmss.containers import Signature

if TYPE_CHECKING:
from .attestation import AttestationData

AttestationsByValidator = dict[Uint64, "AttestationData"]
"""Mapping from validator index to attestation data."""


class AggregationBits(BaseBitlist):
Expand Down Expand Up @@ -57,10 +64,3 @@ def to_validator_indices(self) -> list[Uint64]:
raise AssertionError("Aggregated attestation must reference at least one validator")

return indices


class NaiveAggregatedSignature(SSZList[Signature]):
"""Naive list of validator signatures used for aggregation placeholders."""

ELEMENT_TYPE = Signature
LIMIT = int(VALIDATOR_REGISTRY_LIMIT)
2 changes: 2 additions & 0 deletions src/lean_spec/subspecs/containers/block/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from .types import (
AggregatedAttestations,
AttestationSignatures,
BlockLookup,
)

__all__ = [
"Block",
"BlockBody",
"BlockHeader",
"BlockLookup",
"BlockSignatures",
"BlockWithAttestation",
"SignedBlockWithAttestation",
Expand Down
12 changes: 11 additions & 1 deletion src/lean_spec/subspecs/containers/block/types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
"""Block-specific SSZ types for the Lean Ethereum consensus specification."""

from __future__ import annotations

from typing import TYPE_CHECKING

from lean_spec.subspecs.xmss.aggregation import MultisigAggregatedSignature
from lean_spec.types import SSZList
from lean_spec.types import Bytes32, SSZList

from ...chain.config import VALIDATOR_REGISTRY_LIMIT
from ..attestation import AggregatedAttestation

if TYPE_CHECKING:
from .block import Block

BlockLookup = dict[Bytes32, "Block"]
"""Mapping from block root to Block objects."""


class AggregatedAttestations(SSZList[AggregatedAttestation]):
"""List of aggregated attestations included in a block."""
Expand Down
12 changes: 1 addition & 11 deletions src/lean_spec/subspecs/containers/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

from .state import State
from .types import (
AggregatedSignaturePayload,
AggregatedSignaturePayloads,
AttestationsByValidator,
AttestationSignatureKey,
BlockLookup,
HistoricalBlockHashes,
JustificationRoots,
JustificationValidators,
Expand All @@ -16,16 +11,11 @@
)

__all__ = [
"State",
"AggregatedSignaturePayload",
"AggregatedSignaturePayloads",
"AttestationSignatureKey",
"AttestationsByValidator",
"BlockLookup",
"HistoricalBlockHashes",
"JustificationRoots",
"JustificationValidators",
"JustifiedSlots",
"State",
"StateLookup",
"Validators",
]
8 changes: 5 additions & 3 deletions src/lean_spec/subspecs/containers/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from typing import AbstractSet, Iterable

from lean_spec.subspecs.ssz.hash import hash_tree_root
from lean_spec.subspecs.xmss.aggregation import MultisigAggregatedSignature
from lean_spec.subspecs.xmss.aggregation import (
AggregatedSignaturePayloads,
AttestationSignatureKey,
MultisigAggregatedSignature,
)
from lean_spec.subspecs.xmss.containers import PublicKey, Signature
from lean_spec.types import (
ZERO_HASH,
Expand All @@ -21,8 +25,6 @@
from ..config import Config
from ..slot import Slot
from .types import (
AggregatedSignaturePayloads,
AttestationSignatureKey,
HistoricalBlockHashes,
JustificationRoots,
JustificationValidators,
Expand Down
21 changes: 1 addition & 20 deletions src/lean_spec/subspecs/containers/state/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,17 @@
from typing import TYPE_CHECKING

from lean_spec.subspecs.chain.config import DEVNET_CONFIG
from lean_spec.subspecs.xmss.aggregation import MultisigAggregatedSignature
from lean_spec.types import Bytes32, SSZList, Uint64
from lean_spec.types import Bytes32, SSZList
from lean_spec.types.bitfields import BaseBitlist

from ..attestation import AggregationBits, AttestationData
from ..block import Block
from ..validator import Validator

if TYPE_CHECKING:
from .state import State

# Type aliases for signature aggregation
AttestationSignatureKey = tuple[Uint64, bytes]
"""Key type for looking up signatures: (validator_id, attestation_data_root)."""

AggregatedSignaturePayload = tuple[AggregationBits, MultisigAggregatedSignature]
"""Aggregated signature payload with its participant bitlist."""

AggregatedSignaturePayloads = list[AggregatedSignaturePayload]
"""List of aggregated signature payloads with their participant bitlists."""

BlockLookup = dict[Bytes32, Block]
"""Mapping from block root to Block objects."""

StateLookup = dict[Bytes32, "State"]
"""Mapping from state root to State objects."""

AttestationsByValidator = dict[Uint64, AttestationData]
"""Mapping from validator index to attestation data."""


class HistoricalBlockHashes(SSZList[Bytes32]):
"""List of historical block root hashes up to historical_roots_limit."""
Expand Down
12 changes: 6 additions & 6 deletions src/lean_spec/subspecs/forkchoice/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
AggregationBits,
Attestation,
AttestationData,
AttestationsByValidator,
Block,
Checkpoint,
Config,
SignedAttestation,
SignedBlockWithAttestation,
State,
)
from lean_spec.subspecs.containers.block import BlockLookup
from lean_spec.subspecs.containers.slot import Slot
from lean_spec.subspecs.containers.state.types import (
from lean_spec.subspecs.containers.state import StateLookup
from lean_spec.subspecs.ssz.hash import hash_tree_root
from lean_spec.subspecs.xmss.aggregation import (
AggregatedSignaturePayloads,
AttestationsByValidator,
AttestationSignatureKey,
BlockLookup,
StateLookup,
MultisigAggregatedSignature,
)
from lean_spec.subspecs.ssz.hash import hash_tree_root
from lean_spec.subspecs.xmss.aggregation import MultisigAggregatedSignature
from lean_spec.subspecs.xmss.containers import Signature
from lean_spec.subspecs.xmss.interface import TARGET_SIGNATURE_SCHEME, GeneralizedXmssScheme
from lean_spec.types import (
Expand Down
15 changes: 14 additions & 1 deletion src/lean_spec/subspecs/xmss/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from __future__ import annotations

from typing import Self, Sequence
from typing import TYPE_CHECKING, Self, Sequence

from lean_multisig_py import aggregate_signatures as aggregate_signatures_py
from lean_multisig_py import setup_prover, setup_verifier
Expand All @@ -18,6 +18,12 @@
from lean_spec.types import Uint64
from lean_spec.types.byte_arrays import ByteListMiB

if TYPE_CHECKING:
from lean_spec.subspecs.containers.attestation import AggregationBits

AttestationSignatureKey = tuple[Uint64, bytes]
"""Key type for looking up signatures: (validator id, attestation data root)."""


class MultisigError(RuntimeError):
"""Base exception for multisig aggregation helpers."""
Expand Down Expand Up @@ -108,3 +114,10 @@ def verify_aggregated_payload(
)
except Exception as exc:
raise MultisigAggregationError(f"Multisig verification failed: {exc}") from exc


AggregatedSignaturePayload = tuple[AggregationBits, MultisigAggregatedSignature]
"""Aggregated signature payload with its participant bitlist."""

AggregatedSignaturePayloads = list[AggregatedSignaturePayload]
"""List of aggregated signature payloads with their participant bitlists."""
Loading