mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 03:31:45 +00:00
Fix gossip verification of duplicate attester slashings (#5385)
* Fix gossip verification of duplicate attester slashings
This commit is contained in:
@@ -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)?;
|
||||
|
||||
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user