Fix gossip verification of duplicate attester slashings (#5385)

* Fix gossip verification of duplicate attester slashings
This commit is contained in:
Michael Sproul
2024-03-21 07:47:38 +11:00
committed by GitHub
parent f33ce8cc34
commit 65a6118c53
5 changed files with 208 additions and 19 deletions

View File

@@ -231,11 +231,9 @@ pub fn process_attester_slashings<T: EthSpec>(
spec: &ChainSpec,
) -> Result<(), BlockProcessingError> {
for (i, attester_slashing) in attester_slashings.iter().enumerate() {
verify_attester_slashing(state, attester_slashing, verify_signatures, spec)
.map_err(|e| e.into_with_index(i))?;
let slashable_indices =
get_slashable_indices(state, attester_slashing).map_err(|e| e.into_with_index(i))?;
verify_attester_slashing(state, attester_slashing, verify_signatures, spec)
.map_err(|e| e.into_with_index(i))?;
for i in slashable_indices {
slash_validator(state, i as usize, None, ctxt, spec)?;

View File

@@ -13,16 +13,15 @@ fn error(reason: Invalid) -> BlockOperationError<Invalid> {
/// Indicates if an `AttesterSlashing` is valid to be included in a block in the current epoch of
/// the given state.
///
/// Returns `Ok(())` if the `AttesterSlashing` is valid, otherwise indicates the reason for
/// Returns `Ok(indices)` with `indices` being a non-empty vec of validator indices in ascending
/// order if the `AttesterSlashing` is valid. Otherwise returns `Err(e)` with the reason for
/// invalidity.
///
/// Spec v0.12.1
pub fn verify_attester_slashing<T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing<T>,
verify_signatures: VerifySignatures,
spec: &ChainSpec,
) -> Result<()> {
) -> Result<Vec<u64>> {
let attestation_1 = &attester_slashing.attestation_1;
let attestation_2 = &attester_slashing.attestation_2;
@@ -38,14 +37,12 @@ pub fn verify_attester_slashing<T: EthSpec>(
is_valid_indexed_attestation(state, attestation_2, verify_signatures, spec)
.map_err(|e| error(Invalid::IndexedAttestation2Invalid(e)))?;
Ok(())
get_slashable_indices(state, attester_slashing)
}
/// For a given attester slashing, return the indices able to be slashed in ascending order.
///
/// Returns Ok(indices) if `indices.len() > 0`.
///
/// Spec v0.12.1
/// Returns Ok(indices) if `indices.len() > 0`
pub fn get_slashable_indices<T: EthSpec>(
state: &BeaconState<T>,
attester_slashing: &AttesterSlashing<T>,