Skip to content

Commit 6dc614f

Browse files
authored
Add PeerDAS KZG lib integration (construction & KZG verification) (#6212)
* Add peerdas KZG library and use it for data column construction and cell kzg verification (#5701, #5941, #6118, #6179) Co-authored-by: kevaundray <[email protected]> * Update `rust_eth_kzg` crate to published version. * Update kzg metrics buckets. * Merge branch 'unstable' into peerdas-kzg * Update KZG version to fix windows mem allocation. * Refactor common logic from build sidecar and reconstruction. Remove unnecessary `needless_lifetimes`. Co-authored-by: realbigsean <[email protected]> * Copy existing trusted setup into `PeerDASTrustedSetup` for consistency and maintain `--trusted-setup` functionality. * Merge branch 'unstable' into peerdas-kzg * Merge branch 'peerdas-kzg' of github.com:jimmygchen/lighthouse into peerdas-kzg * Merge branch 'unstable' into peerdas-kzg * Merge branch 'unstable' into peerdas-kzg * Load PeerDAS KZG only if PeerDAS is enabled.
1 parent ff15c78 commit 6dc614f

File tree

11 files changed

+627
-284
lines changed

11 files changed

+627
-284
lines changed

Cargo.lock

+93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ delay_map = "0.3"
114114
derivative = "2"
115115
dirs = "3"
116116
either = "1.9"
117+
rust_eth_kzg = "0.3.4"
117118
discv5 = { version = "0.4.1", features = ["libp2p"] }
118119
env_logger = "0.9"
119120
error-chain = "0.12"

beacon_node/beacon_chain/src/data_column_verification.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::block_verification::{
22
cheap_state_advance_to_obtain_committees, get_validator_pubkey_cache, process_block_slash_info,
33
BlockSlashInfo,
44
};
5-
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
5+
use crate::kzg_utils::validate_data_columns;
6+
use crate::{metrics, BeaconChain, BeaconChainError, BeaconChainTypes};
67
use derivative::Derivative;
78
use fork_choice::ProtoBlock;
89
use kzg::{Error as KzgError, Kzg};
@@ -11,6 +12,7 @@ use slasher::test_utils::E;
1112
use slog::debug;
1213
use slot_clock::SlotClock;
1314
use ssz_derive::{Decode, Encode};
15+
use std::iter;
1416
use std::sync::Arc;
1517
use types::data_column_sidecar::{ColumnIndex, DataColumnIdentifier};
1618
use types::{
@@ -255,9 +257,10 @@ impl<E: EthSpec> KzgVerifiedCustodyDataColumn<E> {
255257
/// Returns an error if the kzg verification check fails.
256258
pub fn verify_kzg_for_data_column<E: EthSpec>(
257259
data_column: Arc<DataColumnSidecar<E>>,
258-
_kzg: &Kzg,
260+
kzg: &Kzg,
259261
) -> Result<KzgVerifiedDataColumn<E>, KzgError> {
260-
// TODO(das): KZG verification to be implemented
262+
let _timer = metrics::start_timer(&metrics::KZG_VERIFICATION_DATA_COLUMN_SINGLE_TIMES);
263+
validate_data_columns(kzg, iter::once(&data_column))?;
261264
Ok(KzgVerifiedDataColumn { data: data_column })
262265
}
263266

@@ -267,13 +270,14 @@ pub fn verify_kzg_for_data_column<E: EthSpec>(
267270
/// Note: This function should be preferred over calling `verify_kzg_for_data_column`
268271
/// in a loop since this function kzg verifies a list of data columns more efficiently.
269272
pub fn verify_kzg_for_data_column_list<'a, E: EthSpec, I>(
270-
_data_column_iter: I,
271-
_kzg: &'a Kzg,
273+
data_column_iter: I,
274+
kzg: &'a Kzg,
272275
) -> Result<(), KzgError>
273276
where
274277
I: Iterator<Item = &'a Arc<DataColumnSidecar<E>>> + Clone,
275278
{
276-
// TODO(das): implement KZG verification
279+
let _timer = metrics::start_timer(&metrics::KZG_VERIFICATION_DATA_COLUMN_BATCH_TIMES);
280+
validate_data_columns(kzg, data_column_iter)?;
277281
Ok(())
278282
}
279283

0 commit comments

Comments
 (0)