Skip to content

Commit

Permalink
fix: fixed requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayden-ML committed Feb 13, 2025
1 parent 1fff8f6 commit b6b2ef1
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions crates/common/consensus/src/deneb/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,25 +1777,15 @@ pub fn eth_fast_aggregate_verify(
pub fn eth_aggregate_pubkeys(pubkeys: &[&PubKey]) -> anyhow::Result<PublicKey> {
ensure!(!pubkeys.is_empty(), "Public keys list cannot be empty");

ensure!(
pubkeys
.iter()
.all(|key| PublicKey::from_bytes(&key.inner).is_ok()),
"Invalid public key found"
);

let mut result = AggregatePublicKey::from_public_key(
&PublicKey::from_bytes(&pubkeys[0].inner)
.map_err(|err| anyhow!("Failed to decode the first public key {err:?}"))?,
);

for pubkey in pubkeys[1..].iter() {
let pubkey = PublicKey::from_bytes(&pubkey.inner)
.map_err(|err| anyhow!("Failed to decode public key {err:?}"))?;
result
.add_public_key(&pubkey, true)
.map_err(|err| anyhow!("Failed to get result {err:?}"))?;
}

Ok(result.to_public_key())
let pubkeys = pubkeys
.iter()
.map(|public_key| {
PublicKey::from_bytes(&public_key.inner)
.map_err(|err| anyhow!("Failed to decode public key {err:?}"))
})
.collect::<anyhow::Result<Vec<PublicKey>>>()?;
let aggregate_public_key =
AggregatePublicKey::aggregate(&pubkeys.iter().collect::<Vec<_>>(), true)
.map_err(|err| anyhow!("Failed to aggregate and validate public keys {err:?}"))?;
Ok(aggregate_public_key.to_public_key())
}

0 comments on commit b6b2ef1

Please sign in to comment.