Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented the kzg_commitment_to_versioned_hash function #112

Merged
merged 2 commits into from
Feb 21, 2025
Merged
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
8 changes: 8 additions & 0 deletions crates/common/consensus/src/deneb/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use anyhow::{anyhow, bail, ensure};
use blst::min_pk::{AggregatePublicKey, PublicKey};
use ethereum_hashing::{hash, hash_fixed};
use itertools::Itertools;
use kzg::eth::c_bindings::KZGCommitment;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::{
Expand Down Expand Up @@ -61,6 +62,7 @@ use crate::{
helpers::xor,
historical_summary::HistoricalSummary,
indexed_attestation::IndexedAttestation,
kzg_commitment::VERSIONED_HASH_VERSION_KZG,
misc::{
compute_activation_exit_epoch, compute_committee, compute_domain, compute_epoch_at_slot,
compute_shuffled_index, compute_signing_root, compute_start_slot_at_epoch,
Expand Down Expand Up @@ -1800,3 +1802,9 @@ pub fn eth_aggregate_pubkeys(pubkeys: &[&PubKey]) -> anyhow::Result<PublicKey> {
.map_err(|err| anyhow!("Failed to aggregate and validate public keys {err:?}"))?;
Ok(aggregate_public_key.to_public_key())
}

pub fn kzg_commitment_to_versioned_hash(kzg_commitment: &KZGCommitment) -> B256 {
let mut versioned_hash = hash(&kzg_commitment.bytes);
versioned_hash[0] = VERSIONED_HASH_VERSION_KZG;
B256::from_slice(&versioned_hash)
}