Skip to main content

dig_slashing/evidence/
checkpoint.rs

1//! `Checkpoint` — the FFG `(epoch, root)` vote pair.
2//!
3//! Traces to: [SPEC.md §3.3](../../docs/resources/SPEC.md), catalogue row
4//! [DSL-003](../../docs/requirements/domains/evidence/specs/DSL-003.md).
5//!
6//! # Role
7//!
8//! A `Checkpoint` pins a vote to a specific epoch and to a specific beacon
9//! block root at that epoch. Consumed by:
10//!
11//! - [`AttestationData::source`](super::attestation_data::AttestationData) —
12//!   the justified checkpoint the attester is voting from (DSL-004).
13//! - [`AttestationData::target`](super::attestation_data::AttestationData) —
14//!   the checkpoint the attester is voting for (DSL-004).
15//! - [`JustificationView`] trait (DSL-143) — the
16//!   `current_justified_checkpoint` / `previous_justified_checkpoint` /
17//!   `finalized_checkpoint` accessors.
18//!
19//! # Determinism + leafness
20//!
21//! `Checkpoint` has no nested types beyond the 32-byte root. Every derive
22//! (`Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash`) is
23//! defaulted. The type is `Copy` so it can be passed by value across every
24//! downstream API without lifetime or borrow friction.
25
26use dig_protocol::Bytes32;
27use serde::{Deserialize, Serialize};
28
29/// A `(epoch, root)` FFG vote pair.
30///
31/// Per [SPEC §3.3](../../docs/resources/SPEC.md), `Checkpoint` is the
32/// primitive finality-gadget vote: the attester's source and target votes
33/// both carry an epoch number and a beacon block root that pins the vote
34/// to a specific history.
35///
36/// # Fields
37///
38/// - `epoch` — the L2 epoch number of the vote.
39/// - `root` — the canonical beacon block root at the end of that epoch's
40///   canonical chain (the target-root for target votes; the last-justified
41///   root for source votes).
42///
43/// # Equality + hashing
44///
45/// `Checkpoint`s are `PartialEq` iff both `epoch` and `root` match; `Hash`
46/// output is consistent with `Eq` per the Rust stdlib contract. This enables
47/// use as a `HashMap`/`HashSet` key in consumer crates (e.g. a
48/// justification-graph crate).
49///
50/// # Serde
51///
52/// Both `bincode` and `serde_json` round-trip byte-exactly; see
53/// `tests/dsl_003_checkpoint_roundtrip_test.rs` for the full suite.
54#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
55pub struct Checkpoint {
56    /// L2 epoch number of the vote.
57    pub epoch: u64,
58    /// Canonical beacon block root at this checkpoint.
59    pub root: Bytes32,
60}