Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/ethlambda/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use cli::CliOptions;
use ethlambda_blockchain::MILLISECONDS_PER_SLOT;
use ethlambda_blockchain::block_builder::ProposerConfig;
use ethlambda_blockchain::key_manager::ValidatorKeyPair;
use ethlambda_crypto::signature::ValidatorSecretKey;
use ethlambda_network_api::{InitBlockChain, InitP2P, ToBlockChainToP2PRef, ToP2PToBlockChainRef};
use ethlambda_p2p::{
Bootnode, P2P, PeerId, SwarmConfig, attestation_subscription_subnets, build_swarm, parse_enrs,
Expand All @@ -44,7 +45,6 @@ use ethlambda_types::primitives::{H256, HashTreeRoot as _};
use ethlambda_types::{
aggregator::AggregatorController,
genesis::GenesisConfig,
signature::ValidatorSecretKey,
state::{State, ValidatorPubkeyBytes},
};
use eyre::WrapErr;
Expand Down
4 changes: 2 additions & 2 deletions crates/blockchain/src/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ use std::collections::{HashMap, HashSet};
use std::time::{Duration, Instant, SystemTime};

use ethlambda_crypto::aggregate_mixed;
use ethlambda_crypto::signature::{ValidatorPubkeys, ValidatorPublicKey, ValidatorSignature};
use ethlambda_storage::Store;
use ethlambda_types::{
ShortRoot,
attestation::{AggregationBits, AttestationData, HashedAttestationData},
block::{ByteList512KiB, SingleMessageAggregate},
primitives::H256,
signature::{ValidatorPublicKey, ValidatorSignature},
state::Validator,
};
use spawned_concurrency::message::Message;
Expand Down Expand Up @@ -796,7 +796,7 @@ mod tests {
/// never checks signature validity, only that it clones and carries a
/// resolvable id — mirrors `ethlambda_storage::store::tests::make_dummy_sig`.
fn dummy_sig() -> ValidatorSignature {
use ethlambda_types::signature::LeanSignatureScheme;
use ethlambda_crypto::signature::LeanSignatureScheme;
use leansig::{serialization::Serializable, signature::SignatureScheme};
use rand::{SeedableRng, rngs::StdRng};

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
time::Instant,
};

use ethlambda_crypto::aggregate_proofs;
use ethlambda_crypto::{aggregate_proofs, signature::ValidatorPubkeys};
use ethlambda_state_transition::{
attestation_data_matches_chain, justified_slots_ops, process_block, process_slots,
slot_is_justifiable_after,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/src/key_manager.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::HashMap;
use std::time::Instant;

use ethlambda_crypto::signature::{ValidatorSecretKey, ValidatorSignature};
use ethlambda_types::{
attestation::{AttestationData, XmssSignature},
primitives::{H256, HashTreeRoot as _},
signature::{ValidatorSecretKey, ValidatorSignature},
};
use tracing::{info, warn};

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{HashMap, HashSet, VecDeque};
use std::time::{Duration, Instant, SystemTime};

use ethlambda_crypto::signature::{ValidatorPubkeys, ValidatorPublicKey, ValidatorSignature};
use ethlambda_network_api::{BlockChainToP2PRef, InitP2P};
use ethlambda_state_transition::is_proposer;
use ethlambda_storage::{ALL_TABLES, Store};
Expand All @@ -10,7 +11,6 @@ use ethlambda_types::{
attestation::{SignedAggregatedAttestation, SignedAttestation},
block::{ByteList512KiB, MultiMessageAggregate, SignedBlock},
primitives::{H256, HashTreeRoot as _},
signature::{ValidatorPublicKey, ValidatorSignature},
};

use crate::aggregation::{
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/src/reaggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use std::collections::HashSet;

use ethlambda_crypto::signature::{ValidatorPubkeys, ValidatorPublicKey};
use ethlambda_storage::Store;
use ethlambda_types::{
attestation::{
Expand All @@ -32,7 +33,6 @@ use ethlambda_types::{
},
block::{SignedBlock, SingleMessageAggregate},
primitives::{H256, HashTreeRoot as _},
signature::ValidatorPublicKey,
};
use tracing::{debug, warn};

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet};

use ethlambda_crypto::signature::{ValidatorPubkeys, ValidatorPublicKey, ValidatorSignature};
use ethlambda_state_transition::{is_proposer, slot_is_justifiable_after};
use ethlambda_storage::{ForkCheckpoints, Store};
use ethlambda_types::{
Expand All @@ -11,7 +12,6 @@ use ethlambda_types::{
block::{Block, BlockHeader, SignedBlock, SingleMessageAggregate},
checkpoint::Checkpoint,
primitives::{H256, HashTreeRoot as _},
signature::{ValidatorPublicKey, ValidatorSignature},
state::{HISTORICAL_ROOTS_LIMIT, State},
};
use tracing::{info, trace, warn};
Expand Down
12 changes: 6 additions & 6 deletions crates/common/crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::sync::Once;

use ethlambda_types::{
block::ByteList512KiB,
primitives::H256,
signature::{ValidatorPublicKey, ValidatorSignature},
};
use ethlambda_types::{block::ByteList512KiB, primitives::H256};

use crate::signature::{ValidatorPublicKey, ValidatorSignature};
use lean_multisig::{
MultiMessageAggregateSignature as LMType2, ProofError,
SingleMessageAggregateSignature as LMType1, aggregate_single_message_signatures,
Expand All @@ -14,6 +12,8 @@ use lean_multisig::{
use leansig_wrapper::{XmssPublicKey as LeanSigPubKey, XmssSignature as LeanSigSignature};
use thiserror::Error;

pub mod signature;

#[cfg(feature = "shadow-integration")]
pub mod shadow_cost;

Expand Down Expand Up @@ -508,7 +508,7 @@ pub fn split_type_2_by_message(
#[cfg(test)]
mod tests {
use super::*;
use ethlambda_types::signature::LeanSignatureScheme;
use crate::signature::LeanSignatureScheme;
use leansig::{serialization::Serializable, signature::SignatureScheme};
use rand::{SeedableRng, rngs::StdRng};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Validator XMSS signatures, public/secret keys, and the leansig-backed
//! primitives behind them.

use std::ops::Range;

use ethlambda_types::{primitives::H256, state::Validator};
use leansig::{
serialization::Serializable,
signature::{SignatureScheme, SignatureSchemeSecretKey as _, SigningError},
};

use crate::primitives::H256;

/// The XMSS signature scheme used for validator signatures.
///
/// This is a post-quantum secure signature scheme based on hash functions.
Expand All @@ -25,11 +27,6 @@ pub type LeanSigSecretKey = <LeanSignatureScheme as SignatureScheme>::SecretKey;

pub type Signature = LeanSigSignature;

/// Size of an XMSS signature in bytes.
///
/// Computed from: path(32*8*4) + rho(7*4) + hashes(46*8*4) + ssz_offsets(3*4) = 2536
pub const SIGNATURE_SIZE: usize = 2536;

/// Error returned when parsing signature or key bytes fails.
#[derive(Debug, Clone, thiserror::Error)]
#[error("signature parse error: {0}")]
Expand Down Expand Up @@ -125,6 +122,26 @@ impl ValidatorSecretKey {
}
}

/// Leansig-backed public-key access for [`Validator`].
///
/// `Validator` lives in `ethlambda-types`, which stays leansig-free, so these
/// helpers can't be inherent methods there. Import this trait to call
/// `validator.get_attestation_pubkey()` / `get_proposal_pubkey()` as before.
pub trait ValidatorPubkeys {
fn get_attestation_pubkey(&self) -> Result<ValidatorPublicKey, SignatureParseError>;
fn get_proposal_pubkey(&self) -> Result<ValidatorPublicKey, SignatureParseError>;
}

impl ValidatorPubkeys for Validator {
fn get_attestation_pubkey(&self) -> Result<ValidatorPublicKey, SignatureParseError> {
ValidatorPublicKey::from_bytes(&self.attestation_pubkey)
}

fn get_proposal_pubkey(&self) -> Result<ValidatorPublicKey, SignatureParseError> {
ValidatorPublicKey::from_bytes(&self.proposal_pubkey)
}
}
Comment thread
MegaRedHand marked this conversation as resolved.
Outdated

#[cfg(test)]
mod tests {
use super::*;
Expand Down
3 changes: 1 addition & 2 deletions crates/common/test-fixtures/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use ethlambda_types::{
attestation::{
AggregatedAttestation as DomainAggregatedAttestation,
AggregationBits as DomainAggregationBits, AttestationData as DomainAttestationData,
XmssSignature,
SIGNATURE_SIZE, XmssSignature,
},
block::{Block as DomainBlock, BlockBody as DomainBlockBody},
checkpoint::Checkpoint as DomainCheckpoint,
primitives::H256,
signature::SIGNATURE_SIZE,
state::{
ChainConfig, JustificationValidators, JustifiedSlots, State, Validator as DomainValidator,
ValidatorPubkeyBytes,
Expand Down
2 changes: 0 additions & 2 deletions crates/common/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ thiserror.workspace = true
serde.workspace = true
hex.workspace = true

leansig.workspace = true

libssz.workspace = true
libssz-derive.workspace = true
libssz-merkle.workspace = true
Expand Down
8 changes: 7 additions & 1 deletion crates/common/types/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{
block::SingleMessageAggregate,
checkpoint::Checkpoint,
primitives::{H256, HashTreeRoot as _},
signature::SIGNATURE_SIZE,
};

/// Validator specific attestation wrapping shared attestation data.
Expand Down Expand Up @@ -55,6 +54,13 @@ pub struct SignedAttestation {
pub signature: XmssSignature,
}

/// Size of an XMSS signature in bytes.
///
/// Computed from: path(32*8*4) + rho(7*4) + hashes(46*8*4) + ssz_offsets(3*4) = 2536.
/// This is the SSZ wire size, independent of the `leansig` scheme itself, so it
/// lives here (leansig-free) rather than in `ethlambda-crypto`.
pub const SIGNATURE_SIZE: usize = 2536;

/// XMSS signature as a fixed-length byte vector (`SIGNATURE_SIZE` bytes).
pub type XmssSignature = SszVector<u8, SIGNATURE_SIZE>;

Expand Down
1 change: 0 additions & 1 deletion crates/common/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub mod checkpoint;
pub mod constants;
pub mod genesis;
pub mod primitives;
pub mod signature;
pub mod state;

/// Display helper for truncated root hashes (8 hex chars)
Expand Down
11 changes: 0 additions & 11 deletions crates/common/types/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
block::{Block, BlockBody, BlockHeader},
checkpoint::Checkpoint,
primitives::{self, H256},
signature::{SignatureParseError, ValidatorPublicKey},
};

// Convenience trait for calling hash_tree_root() without a hasher argument
Expand Down Expand Up @@ -85,16 +84,6 @@ where
serializer.serialize_str(&hex::encode(pubkey))
}

impl Validator {
pub fn get_attestation_pubkey(&self) -> Result<ValidatorPublicKey, SignatureParseError> {
ValidatorPublicKey::from_bytes(&self.attestation_pubkey)
}

pub fn get_proposal_pubkey(&self) -> Result<ValidatorPublicKey, SignatureParseError> {
ValidatorPublicKey::from_bytes(&self.proposal_pubkey)
}
}

pub type ValidatorPubkeyBytes = [u8; 52];

impl State {
Expand Down
1 change: 1 addition & 0 deletions crates/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rust-version.workspace = true
version.workspace = true

[dependencies]
ethlambda-crypto.workspace = true
ethlambda-types.workspace = true

tracing.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use lru::LruCache;
use crate::api::{StorageBackend, StorageReadView, StorageWriteBatch, Table};
use crate::error::Error;

use ethlambda_crypto::signature::ValidatorSignature;
use ethlambda_types::{
attestation::{AggregationBits, AttestationData, HashedAttestationData, bits_is_subset},
block::{
Block, BlockBody, BlockHeader, MultiMessageAggregate, SignedBlock, SingleMessageAggregate,
},
checkpoint::Checkpoint,
primitives::{H256, HashTreeRoot as _},
signature::ValidatorSignature,
state::{ChainConfig, State, anchor_pair_is_consistent},
};
use libssz::{SszDecode, SszEncode};
Expand Down Expand Up @@ -2695,7 +2695,7 @@ mod tests {
// ============ GossipSignatureBuffer Tests ============

fn make_dummy_sig() -> ValidatorSignature {
use ethlambda_types::signature::LeanSignatureScheme;
use ethlambda_crypto::signature::LeanSignatureScheme;
use leansig::{serialization::Serializable, signature::SignatureScheme};
use rand::{SeedableRng, rngs::StdRng};

Expand Down