Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions crates/blockchain/src/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ impl KeyManager {
attestation_data: &AttestationData,
) -> Result<XmssSignature, KeyManagerError> {
let message_hash = attestation_data.tree_hash_root();
let epoch = attestation_data.slot as u32;
self.sign_message(validator_id, epoch, &message_hash)
let slot = attestation_data.slot as u32;
self.sign_message(validator_id, slot, &message_hash)
}

/// Signs a message hash for the specified validator.
///
/// # Arguments
///
/// * `validator_id` - The ID of the validator whose key should be used for signing
/// * `epoch` - The epoch number used in the XMSS signature scheme
/// * `slot` - The slot number used in the XMSS signature scheme
/// * `message` - The message hash to sign
///
/// # Returns
Expand All @@ -92,7 +92,7 @@ impl KeyManager {
fn sign_message(
&mut self,
validator_id: u64,
epoch: u32,
slot: u32,
message: &H256,
) -> Result<XmssSignature, KeyManagerError> {
let secret_key = self
Expand All @@ -101,7 +101,7 @@ impl KeyManager {
.ok_or(KeyManagerError::ValidatorKeyNotFound(validator_id))?;

let signature: ValidatorSignature = secret_key
.sign(epoch, message)
.sign(slot, message)
.map_err(|e| KeyManagerError::SigningError(e.to_string()))?;

// Convert ValidatorSignature to XmssSignature (FixedVector<u8, SignatureSize>)
Expand Down
22 changes: 9 additions & 13 deletions crates/blockchain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ pub fn on_gossip_attestation(
.map_err(|_| StoreError::PubkeyDecodingFailed(validator_id))?;

// Verify the validator's XMSS signature
let epoch: u32 = attestation.data.slot.try_into().expect("slot exceeds u32");
let slot: u32 = attestation.data.slot.try_into().expect("slot exceeds u32");
let signature = ValidatorSignature::from_bytes(&signed_attestation.signature)
.map_err(|_| StoreError::SignatureDecodingFailed)?;
if !signature.is_valid(&validator_pubkey, epoch, &data_root) {
if !signature.is_valid(&validator_pubkey, slot, &data_root) {
return Err(StoreError::SignatureVerificationFailed);
}

Expand Down Expand Up @@ -437,13 +437,13 @@ pub fn on_gossip_aggregated_attestation(
.collect::<Result<_, _>>()?;

let data_root = aggregated.data.tree_hash_root();
let epoch: u32 = aggregated.data.slot.try_into().expect("slot exceeds u32");
let slot: u32 = aggregated.data.slot.try_into().expect("slot exceeds u32");

ethlambda_crypto::verify_aggregated_signature(
&aggregated.proof.proof_data,
pubkeys,
&data_root,
epoch,
slot,
)
.map_err(StoreError::AggregateVerificationFailed)?;

Expand Down Expand Up @@ -1160,7 +1160,7 @@ fn verify_signatures(
return Err(StoreError::InvalidValidatorIndex);
}

let epoch: u32 = attestation.data.slot.try_into().expect("slot exceeds u32");
let slot: u32 = attestation.data.slot.try_into().expect("slot exceeds u32");
let message = attestation.data.tree_hash_root();

// Collect public keys for all participating validators
Expand All @@ -1173,12 +1173,8 @@ fn verify_signatures(
})
.collect::<Result<_, _>>()?;

match verify_aggregated_signature(
&aggregated_proof.proof_data,
public_keys,
&message,
epoch,
) {
match verify_aggregated_signature(&aggregated_proof.proof_data, public_keys, &message, slot)
{
Ok(()) => metrics::inc_pq_sig_aggregated_signatures_valid(),
Err(e) => {
metrics::inc_pq_sig_aggregated_signatures_invalid();
Expand All @@ -1201,14 +1197,14 @@ fn verify_signatures(
.get_pubkey()
.map_err(|_| StoreError::PubkeyDecodingFailed(proposer.index))?;

let epoch = proposer_attestation
let slot = proposer_attestation
.data
.slot
.try_into()
.expect("slot exceeds u32");
let message = proposer_attestation.data.tree_hash_root();

if !proposer_signature.is_valid(&proposer_pubkey, epoch, &message) {
if !proposer_signature.is_valid(&proposer_pubkey, slot, &message) {
return Err(StoreError::ProposerSignatureVerificationFailed);
}
Ok(())
Expand Down
Loading