Files
lighthouse/slasher/src/attester_record.rs
Michael Sproul 5828ff1204 Implement slasher (#1567)
This is an implementation of a slasher that lives inside the BN and can be enabled via `lighthouse bn --slasher`.

Features included in this PR:

- [x] Detection of attester slashing conditions (double votes, surrounds existing, surrounded by existing)
- [x] Integration into Lighthouse's attestation verification flow
- [x] Detection of proposer slashing conditions
- [x] Extraction of attestations from blocks as they are verified
- [x] Compression of chunks
- [x] Configurable history length
- [x] Pruning of old attestations and blocks
- [x] More tests

Future work:

* Focus on a slice of history separate from the most recent N epochs (e.g. epochs `current - K` to `current - M`)
* Run out-of-process
* Ingest attestations from the chain without a resync

Design notes are here https://hackmd.io/@sproul/HJSEklmPL
2020-11-23 03:43:22 +00:00

58 lines
1.8 KiB
Rust

use ssz_derive::{Decode, Encode};
use tree_hash::TreeHash as _;
use tree_hash_derive::TreeHash;
use types::{AggregateSignature, EthSpec, Hash256, IndexedAttestation, VariableList};
#[derive(Debug, Clone, Copy, Encode, Decode)]
pub struct AttesterRecord {
/// The hash of the attestation data, for checking double-voting.
pub attestation_data_hash: Hash256,
/// The hash of the indexed attestation, so it can be loaded.
pub indexed_attestation_hash: Hash256,
}
#[derive(Debug, Clone, Encode, Decode, TreeHash)]
struct IndexedAttestationHeader<T: EthSpec> {
pub attesting_indices: VariableList<u64, T::MaxValidatorsPerCommittee>,
pub data_root: Hash256,
pub signature: AggregateSignature,
}
impl<T: EthSpec> From<IndexedAttestation<T>> for AttesterRecord {
fn from(indexed_attestation: IndexedAttestation<T>) -> AttesterRecord {
let attestation_data_hash = indexed_attestation.data.tree_hash_root();
let header = IndexedAttestationHeader::<T> {
attesting_indices: indexed_attestation.attesting_indices,
data_root: attestation_data_hash,
signature: indexed_attestation.signature,
};
let indexed_attestation_hash = header.tree_hash_root();
AttesterRecord {
attestation_data_hash,
indexed_attestation_hash,
}
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::test_utils::indexed_att;
// Check correctness of fast hashing
#[test]
fn fast_hash() {
let data = vec![
indexed_att(vec![], 0, 0, 0),
indexed_att(vec![1, 2, 3], 12, 14, 1),
indexed_att(vec![4], 0, 5, u64::MAX),
];
for att in data {
assert_eq!(
att.tree_hash_root(),
AttesterRecord::from(att).indexed_attestation_hash
);
}
}
}