Skip to main content

dig_slashing/
lib.rs

1//! # dig-slashing
2//!
3//! Validator slashing, attestation participation accounting, inactivity
4//! accounting, and fraud-proof appeal system for the DIG Network L2 blockchain.
5//!
6//! Traces to: [SPEC.md](../docs/resources/SPEC.md) v0.4+.
7//!
8//! # Scope
9//!
10//! Validator slashing only. Four discrete offenses (`ProposerEquivocation`,
11//! `InvalidBlock`, `AttesterDoubleVote`, `AttesterSurroundVote`). Continuous
12//! inactivity accounting (Ethereum Bellatrix parity). Optimistic slashing
13//! lifecycle with 8-epoch fraud-proof appeal window.
14//!
15//! DFSP / storage-provider slashing is **out of scope** — different
16//! subsystem, different future crate.
17//!
18//! # Re-exports
19//!
20//! The crate root re-exports every public type and constant named in any
21//! `DSL-NNN` requirement. Downstream consumers should import from here,
22//! not from individual modules, to keep dependency edges clean.
23//!
24//! # Module layout
25//!
26//! - [`constants`] — protocol constants (BPS, quotients, domain tags)
27//! - [`evidence`] — offense types, evidence envelopes, verifiers
28//! - [`appeal`] — fraud-proof appeal grounds, verifiers, adjudication
29//! - [`bonds`] — reporter/appellant bond escrow
30//! - [`error`] — the `SlashingError` surface
31//! - [`inactivity`] — continuous inactivity-score accounting + penalties
32//! - [`manager`] — slashing lifecycle state machine (`SlashingManager`)
33//! - [`orchestration`] — epoch-boundary + reorg-rewind entry points
34//! - [`participation`] — attestation participation flags + rewards
35//! - [`pending`] — pending-slash book + appeal-attempt tracking
36//! - [`protection`] — validator-local slashing protection
37//! - [`remark`] — REMARK wire encode/parse + block-admission policy
38//! - [`system`] — `SlashingSystem` genesis + bundle of the trackers
39//! - [`traits`] — embedder-implemented trait contracts
40
41pub mod appeal;
42pub mod bonds;
43pub mod constants;
44pub mod error;
45pub mod evidence;
46pub mod inactivity;
47pub mod manager;
48pub mod orchestration;
49pub mod participation;
50pub mod pending;
51pub mod protection;
52pub mod remark;
53pub mod system;
54pub mod traits;
55
56// ── Public re-exports (alphabetical within category) ────────────────────────
57
58pub use appeal::{
59    AppealAdjudicationResult, AppealRejectReason, AppealSustainReason, AppealVerdict,
60    AttesterAppealGround, AttesterSlashingAppeal, BondSplitResult, ClawbackResult,
61    InvalidBlockAppeal, InvalidBlockAppealGround, ProposerAppealGround, ProposerSlashingAppeal,
62    ReporterPenalty, ShortfallAbsorption, SlashAppeal, SlashAppealPayload,
63    adjudicate_absorb_clawback_shortfall, adjudicate_appeal, adjudicate_rejected_challenge_open,
64    adjudicate_rejected_forfeit_appellant_bond, adjudicate_sustained_clawback_rewards,
65    adjudicate_sustained_forfeit_reporter_bond, adjudicate_sustained_reporter_penalty,
66    adjudicate_sustained_restore_status, adjudicate_sustained_revert_base_slash,
67    adjudicate_sustained_revert_collateral, adjudicate_sustained_status_reverted,
68    verify_attester_appeal_attestations_identical, verify_attester_appeal_empty_intersection,
69    verify_attester_appeal_invalid_indexed_attestation_structure,
70    verify_attester_appeal_not_slashable_by_predicate, verify_attester_appeal_signature_a_invalid,
71    verify_attester_appeal_signature_b_invalid,
72    verify_attester_appeal_validator_not_in_intersection,
73    verify_invalid_block_appeal_block_actually_valid,
74    verify_invalid_block_appeal_evidence_epoch_mismatch,
75    verify_invalid_block_appeal_failure_reason_mismatch,
76    verify_invalid_block_appeal_proposer_signature_invalid,
77    verify_proposer_appeal_headers_identical, verify_proposer_appeal_proposer_index_mismatch,
78    verify_proposer_appeal_signature_a_invalid, verify_proposer_appeal_signature_b_invalid,
79    verify_proposer_appeal_slot_mismatch, verify_proposer_appeal_validator_not_active_at_epoch,
80};
81pub use bonds::{BondError, BondEscrow, BondTag};
82pub use constants::{
83    APPELLANT_BOND_MOJOS, ATTESTATION_BASE_BPS, BASE_REWARD_FACTOR, BLS_PUBLIC_KEY_SIZE,
84    BLS_SIGNATURE_SIZE, BOND_AWARD_TO_WINNER_BPS, BPS_DENOMINATOR, DOMAIN_BEACON_ATTESTER,
85    DOMAIN_BEACON_PROPOSER, DOMAIN_SLASH_APPEAL, DOMAIN_SLASHING_EVIDENCE, EQUIVOCATION_BASE_BPS,
86    INACTIVITY_PENALTY_QUOTIENT, INACTIVITY_SCORE_BIAS, INACTIVITY_SCORE_RECOVERY_RATE,
87    INVALID_BLOCK_BASE_BPS, MAX_APPEAL_ATTEMPTS_PER_SLASH, MAX_APPEAL_PAYLOAD_BYTES,
88    MAX_APPEALS_PER_BLOCK, MAX_PENALTY_BPS, MAX_PENDING_SLASHES, MAX_SLASH_PROPOSAL_PAYLOAD_BYTES,
89    MAX_SLASH_PROPOSALS_PER_BLOCK, MAX_VALIDATORS_PER_COMMITTEE, MIN_ATTESTATION_INCLUSION_DELAY,
90    MIN_EFFECTIVE_BALANCE, MIN_EPOCHS_TO_INACTIVITY_PENALTY, MIN_SLASHING_PENALTY_QUOTIENT,
91    PROPORTIONAL_SLASHING_MULTIPLIER, PROPOSER_REWARD_QUOTIENT, PROPOSER_WEIGHT,
92    REPORTER_BOND_MOJOS, SLASH_APPEAL_REMARK_MAGIC_V1, SLASH_APPEAL_WINDOW_EPOCHS,
93    SLASH_EVIDENCE_REMARK_MAGIC_V1, SLASH_LOCK_EPOCHS, TIMELY_HEAD_FLAG_INDEX, TIMELY_HEAD_WEIGHT,
94    TIMELY_SOURCE_FLAG_INDEX, TIMELY_SOURCE_MAX_DELAY_SLOTS, TIMELY_SOURCE_WEIGHT,
95    TIMELY_TARGET_FLAG_INDEX, TIMELY_TARGET_MAX_DELAY_SLOTS, TIMELY_TARGET_WEIGHT,
96    WEIGHT_DENOMINATOR, WHISTLEBLOWER_REWARD_QUOTIENT,
97};
98pub use error::SlashingError;
99pub use evidence::{
100    AttestationData, AttesterSlashing, Checkpoint, IndexedAttestation, InvalidBlockProof,
101    InvalidBlockReason, OffenseType, ProposerSlashing, SignedBlockHeader, SlashingEvidence,
102    SlashingEvidencePayload, VerifiedEvidence, block_signing_message, verify_attester_slashing,
103    verify_evidence, verify_evidence_for_inclusion, verify_invalid_block, verify_proposer_slashing,
104};
105pub use inactivity::{InactivityScoreTracker, in_finality_stall};
106pub use manager::{FinalisationResult, PerValidatorSlash, SlashingManager, SlashingResult};
107pub use orchestration::{
108    EpochBoundaryReport, JustificationView, ReorgReport, rewind_all_on_reorg, run_epoch_boundary,
109};
110pub use participation::{
111    FlagDelta, ParticipationError, ParticipationFlags, ParticipationTracker, base_reward,
112    classify_timeliness, compute_flag_deltas, proposer_inclusion_reward,
113};
114pub use pending::{
115    AppealAttempt, AppealOutcome, PendingSlash, PendingSlashBook, PendingSlashStatus,
116};
117pub use protection::SlashingProtection;
118pub use remark::{
119    BlockAdmissionReport, encode_slash_appeal_remark_payload_v1,
120    encode_slashing_evidence_remark_payload_v1, enforce_block_level_appeal_caps,
121    enforce_block_level_slashing_caps, enforce_slash_appeal_mempool_dedup_policy,
122    enforce_slash_appeal_mempool_policy, enforce_slash_appeal_payload_cap,
123    enforce_slash_appeal_remark_admission, enforce_slash_appeal_terminal_status_policy,
124    enforce_slash_appeal_variant_policy, enforce_slash_appeal_window_policy,
125    enforce_slashing_evidence_mempool_dedup_policy, enforce_slashing_evidence_mempool_policy,
126    enforce_slashing_evidence_payload_cap, enforce_slashing_evidence_remark_admission,
127    parse_slash_appeals_from_conditions, parse_slashing_evidence_from_conditions,
128    process_block_admissions, slash_appeal_remark_puzzle_hash_v1,
129    slash_appeal_remark_puzzle_reveal_v1, slashing_evidence_remark_puzzle_hash_v1,
130    slashing_evidence_remark_puzzle_reveal_v1,
131};
132pub use system::{GenesisParameters, SlashingSystem};
133pub use traits::{
134    CollateralError, CollateralSlasher, EffectiveBalanceView, ExecutionOutcome, InvalidBlockOracle,
135    ProposerView, PublicKeyLookup, RewardClawback, RewardPayout, ValidatorEntry, ValidatorView,
136};
137
138// Re-export the slash-lookback window from `dig-epoch` so downstream
139// consumers do not need to pull the dep transitively to compute
140// `OffenseTooOld` boundaries for tests or REMARK-admission policy.
141// Per SPEC §2.7.
142pub use dig_epoch::SLASH_LOOKBACK_EPOCHS;