Fix light client merkle proofs (#7007)

Fix a regression introduced in this PR:

- https://github.com/sigp/lighthouse/pull/6361

We were indexing into the `MerkleTree` with raw generalized indices, which was incorrect and triggering `debug_assert` failures, as described here:

- https://github.com/sigp/lighthouse/issues/7005


  - Convert `generalized_index` to the correct leaf index prior to proof generation.
- Add sanity checks on indices used in `BeaconState::generate_proof`.
- Remove debug asserts from `MerkleTree::generate_proof` in favour of actual errors. This would have caught the bug earlier.
- Refactor the EF tests so that the merkle validity tests are actually run. They were misconfigured in a way that resulted in them running silently with 0 test cases, and the `check_all_files_accessed.py` script still had an ignore that covered the test files, so this omission wasn't detected.
This commit is contained in:
Michael Sproul
2025-02-18 11:39:49 +11:00
committed by GitHub
parent 1888be554c
commit ff739d56be
7 changed files with 93 additions and 61 deletions

View File

@@ -1000,30 +1000,6 @@ impl<E: EthSpec> Handler for KZGRecoverCellsAndKZGProofHandler<E> {
}
}
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct BeaconStateMerkleProofValidityHandler<E>(PhantomData<E>);
impl<E: EthSpec + TypeName> Handler for BeaconStateMerkleProofValidityHandler<E> {
type Case = cases::BeaconStateMerkleProofValidity<E>;
fn config_name() -> &'static str {
E::name()
}
fn runner_name() -> &'static str {
"light_client"
}
fn handler_name(&self) -> String {
"single_merkle_proof/BeaconState".into()
}
fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
fork_name.altair_enabled()
}
}
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct KzgInclusionMerkleProofValidityHandler<E>(PhantomData<E>);
@@ -1054,10 +1030,10 @@ impl<E: EthSpec + TypeName> Handler for KzgInclusionMerkleProofValidityHandler<E
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct BeaconBlockBodyMerkleProofValidityHandler<E>(PhantomData<E>);
pub struct MerkleProofValidityHandler<E>(PhantomData<E>);
impl<E: EthSpec + TypeName> Handler for BeaconBlockBodyMerkleProofValidityHandler<E> {
type Case = cases::BeaconBlockBodyMerkleProofValidity<E>;
impl<E: EthSpec + TypeName> Handler for MerkleProofValidityHandler<E> {
type Case = cases::GenericMerkleProofValidity<E>;
fn config_name() -> &'static str {
E::name()
@@ -1068,11 +1044,11 @@ impl<E: EthSpec + TypeName> Handler for BeaconBlockBodyMerkleProofValidityHandle
}
fn handler_name(&self) -> String {
"single_merkle_proof/BeaconBlockBody".into()
"single_merkle_proof".into()
}
fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
fork_name.capella_enabled()
fork_name.altair_enabled()
}
}