Skip to content

Commit

Permalink
chore: update and enable PeerDAS tests to latest spec test release (`…
Browse files Browse the repository at this point in the history
…1.5.0-alpha-5`) (#6312)

* enable DAS tests

* update spec testing code

* Update PeerDAS kzg tests input structures to latest spec.

* Update `ef_tests` ignore files.
  • Loading branch information
kevaundray authored Aug 28, 2024
1 parent c7b9cbe commit 653126f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 59 deletions.
7 changes: 0 additions & 7 deletions testing/ef_tests/check_all_files_accessed.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# following regular expressions, we will assume they are to be ignored (i.e., we are purposefully
# *not* running the spec tests).
excluded_paths = [
# TODO(das): ignore until new spec test release with column subnet count = 64.
"tests/.*/.*/.*/get_custody_columns/",
# Eth1Block and PowBlock
#
# Intentionally omitted, as per https://github.com/sigp/lighthouse/issues/1835
Expand All @@ -35,15 +33,10 @@
"tests/.*/.*/ssz_static/LightClientStore",
# LightClientSnapshot
"tests/.*/.*/ssz_static/LightClientSnapshot",
# Unused container for das
"tests/.*/.*/ssz_static/MatrixEntry",
# Unused kzg methods
"tests/.*/.*/kzg/verify_cell_kzg_proof",
# One of the EF researchers likes to pack the tarballs on a Mac
".*\\.DS_Store.*",
# More Mac weirdness.
"tests/mainnet/bellatrix/operations/deposit/pyspec_tests/deposit_with_previous_fork_version__valid_ineffective/._meta.yaml",
"tests/mainnet/eip7594/networking/get_custody_columns/pyspec_tests/get_custody_columns__short_node_id/._meta.yaml",
# bls tests are moved to bls12-381-tests directory
"tests/general/phase0/bls",
# some bls tests are not included now
Expand Down
34 changes: 4 additions & 30 deletions testing/ef_tests/src/cases/kzg_recover_cells_and_kzg_proofs.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use super::*;
use crate::case_result::compare_result;
use kzg::{CellsAndKzgProofs, KzgProof};
use kzg::CellsAndKzgProofs;
use serde::Deserialize;
use std::convert::Infallible;
use std::marker::PhantomData;

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct KZGRecoverCellsAndKzgProofsInput {
pub cell_indices: Vec<u64>,
pub cells: Vec<String>,
pub proofs: Vec<String>,
}

#[derive(Debug, Clone, Deserialize)]
Expand All @@ -35,29 +33,17 @@ impl<E: EthSpec> Case for KZGRecoverCellsAndKZGProofs<E> {

fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
let parse_input = |input: &KZGRecoverCellsAndKzgProofsInput| {
// Proofs are not used for `recover_cells_and_compute_kzg_proofs`, they are only checked
// to satisfy the spec tests.
if input.proofs.len() != input.cell_indices.len() {
return Err(Error::SkippedKnownFailure);
}

let proofs = input
.proofs
.iter()
.map(|s| parse_proof(s))
.collect::<Result<Vec<_>, Error>>()?;

let cells = input
.cells
.iter()
.map(|s| parse_cell(s))
.collect::<Result<Vec<_>, Error>>()?;

Ok((proofs, cells, input.cell_indices.clone()))
Ok((cells, input.cell_indices.clone()))
};

let result =
parse_input(&self.input).and_then(|(input_proofs, input_cells, cell_indices)| {
let result: Result<_, Error> =
parse_input(&self.input).and_then(|(input_cells, cell_indices)| {
let input_cells_ref: Vec<_> = input_cells.iter().map(|cell| &**cell).collect();
let kzg = get_kzg();
let (cells, proofs) = kzg
Expand All @@ -71,18 +57,6 @@ impl<E: EthSpec> Case for KZGRecoverCellsAndKZGProofs<E> {
))
})?;

// Check recovered proofs matches inputs proofs. This is done only to satisfy the
// spec tests, as the ckzg library recomputes all proofs and does not require
// proofs to recover.
for (input_proof, cell_id) in input_proofs.iter().zip(cell_indices) {
if let Err(e) = compare_result::<KzgProof, Infallible>(
&Ok(*input_proof),
&proofs.get(cell_id as usize).cloned(),
) {
return Err(e);
}
}

Ok((cells, proofs))
});

Expand Down
3 changes: 1 addition & 2 deletions testing/ef_tests/src/cases/kzg_verify_blob_kzg_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ static KZG: LazyLock<Arc<Kzg>> = LazyLock::new(|| {
let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES)
.map_err(|e| Error::InternalError(format!("Failed to initialize trusted setup: {:?}", e)))
.expect("failed to initialize trusted setup");
// TODO(das): need to enable these tests when rayon issues in rust_eth_kzg are fixed
let kzg = Kzg::new_from_trusted_setup(trusted_setup)
let kzg = Kzg::new_from_trusted_setup_das_enabled(trusted_setup)
.map_err(|e| Error::InternalError(format!("Failed to initialize kzg: {:?}", e)))
.expect("failed to initialize kzg");
Arc::new(kzg)
Expand Down
25 changes: 7 additions & 18 deletions testing/ef_tests/src/cases/kzg_verify_cell_kzg_proof_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use std::marker::PhantomData;
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct KZGVerifyCellKZGProofBatchInput {
pub row_commitments: Vec<String>,
pub row_indices: Vec<usize>,
pub column_indices: Vec<usize>,
pub commitments: Vec<String>,
pub cell_indices: Vec<u64>,
pub cells: Vec<String>,
pub proofs: Vec<String>,
}
Expand Down Expand Up @@ -37,32 +36,22 @@ impl<E: EthSpec> Case for KZGVerifyCellKZGProofBatch<E> {
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
let parse_input = |input: &KZGVerifyCellKZGProofBatchInput| -> Result<_, Error> {
let (cells, proofs) = parse_cells_and_proofs(&input.cells, &input.proofs)?;
let row_commitments = input
.row_commitments
let commitments = input
.commitments
.iter()
.map(|s| parse_commitment(s))
.collect::<Result<Vec<_>, _>>()?;
let coordinates = input
.row_indices
.iter()
.zip(&input.column_indices)
.map(|(&row, &col)| (row as u64, col as u64))
.collect::<Vec<_>>();

Ok((cells, proofs, coordinates, row_commitments))
Ok((cells, proofs, input.cell_indices.clone(), commitments))
};

let result =
parse_input(&self.input).and_then(|(cells, proofs, coordinates, commitments)| {
parse_input(&self.input).and_then(|(cells, proofs, cell_indices, commitments)| {
let proofs: Vec<Bytes48> = proofs.iter().map(|&proof| proof.into()).collect();
let commitments: Vec<Bytes48> = commitments.iter().map(|&c| c.into()).collect();
let cells = cells.iter().map(|c| c.as_ref()).collect::<Vec<_>>();
let column_indices = coordinates
.into_iter()
.map(|(_row, col)| col)
.collect::<Vec<_>>();
let kzg = get_kzg();
match kzg.verify_cell_proof_batch(&cells, &proofs, column_indices, &commitments) {
match kzg.verify_cell_proof_batch(&cells, &proofs, cell_indices, &commitments) {
Ok(_) => Ok(true),
Err(KzgError::KzgVerificationFailed) => Ok(false),
Err(e) => Err(Error::InternalError(format!(
Expand Down
2 changes: 0 additions & 2 deletions testing/ef_tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ fn kzg_verify_kzg_proof() {
KZGVerifyKZGProofHandler::<MainnetEthSpec>::default().run();
}

/* TODO(das): enable these tests
#[test]
fn kzg_compute_cells_and_proofs() {
KZGComputeCellsAndKZGProofHandler::<MainnetEthSpec>::default()
Expand All @@ -919,7 +918,6 @@ fn kzg_recover_cells_and_proofs() {
KZGRecoverCellsAndKZGProofHandler::<MainnetEthSpec>::default()
.run_for_feature(ForkName::Deneb, FeatureName::Eip7594);
}
*/

#[test]
fn merkle_proof_validity() {
Expand Down

0 comments on commit 653126f

Please sign in to comment.