Skip to content

Commit

Permalink
Remove IndexedAttestation faulty Decode impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Jun 17, 2024
1 parent b123b41 commit 2e67125
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
21 changes: 0 additions & 21 deletions consensus/types/src/indexed_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{test_utils::TestRandom, AggregateSignature, AttestationData, EthSpec
use core::slice::Iter;
use derivative::Derivative;
use serde::{Deserialize, Serialize};
use ssz::Decode;
use ssz::Encode;
use ssz_derive::{Decode, Encode};
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -187,26 +186,6 @@ impl<'a, E: EthSpec> IndexedAttestationRef<'a, E> {
}
}

impl<E: EthSpec> Decode for IndexedAttestation<E> {
fn is_ssz_fixed_len() -> bool {
false
}

fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, ssz::DecodeError> {
if let Ok(result) = IndexedAttestationBase::from_ssz_bytes(bytes) {
return Ok(IndexedAttestation::Base(result));
}

if let Ok(result) = IndexedAttestationElectra::from_ssz_bytes(bytes) {
return Ok(IndexedAttestation::Electra(result));
}

Err(ssz::DecodeError::BytesInvalid(String::from(
"bytes not valid for any fork variant",
)))
}
}

/// Implementation of non-crypto-secure `Hash`, for use with `HashMap` and `HashSet`.
///
/// Guarantees `att1 == att2 -> hash(att1) == hash(att2)`.
Expand Down
9 changes: 7 additions & 2 deletions slasher/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use std::marker::PhantomData;
use std::sync::Arc;
use tree_hash::TreeHash;
use types::{
Epoch, EthSpec, Hash256, IndexedAttestation, ProposerSlashing, SignedBeaconBlockHeader, Slot,
Epoch, EthSpec, Hash256, IndexedAttestation, IndexedAttestationBase, ProposerSlashing,
SignedBeaconBlockHeader, Slot,
};

/// Current database schema version, to check compatibility of on-disk DB with software.
Expand Down Expand Up @@ -481,7 +482,11 @@ impl<E: EthSpec> SlasherDB<E> {
.ok_or(Error::MissingIndexedAttestation {
id: indexed_attestation_id.as_u64(),
})?;
ssz_decode(bytes)
// TODO(electra): make slasher fork-aware and return correct variant of attestation. Both
// Base and Electra variant can the same SSZ encoding, however the smaller list maximum of
// Base can error with an Electra attestation with heavy participation.
let indexed_attestation: IndexedAttestationBase<E> = ssz_decode(bytes)?;
Ok(IndexedAttestation::Base(indexed_attestation))
}

fn get_attestation_data_root(
Expand Down

0 comments on commit 2e67125

Please sign in to comment.