1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
//! External-state traits.
//!
//! Traces to: [SPEC.md §15.2](../docs/resources/SPEC.md), catalogue rows
//! [DSL-131..145](../docs/requirements/domains/).
//!
//! # Role
//!
//! The crate does NOT own validator state — it is consumed by external
//! runtimes (node, validator, fork-choice) that do. This module exposes
//! the narrow trait surface the crate reads through.
//!
//! Each trait is defined in the single DSL-NNN that introduces its first
//! consumer, with the blanket / concrete impl landing later under the
//! DSL-131..145 Phase 9 tasks.
use PublicKey;
use L2BlockHeader;
use Bytes32;
use crateSlashingError;
use crateInvalidBlockReason;
/// Validator-index → BLS public-key lookup.
///
/// Traces to [SPEC §15.2](../../docs/resources/SPEC.md), catalogue row
/// [DSL-138](../../docs/requirements/domains/).
///
/// # Consumers
///
/// - `IndexedAttestation::verify_signature` (DSL-006) materializes the
/// pubkey set for the aggregate BLS verify by looking up every
/// `attesting_indices[i]`.
/// - `verify_proposer_slashing` / `verify_invalid_block` (DSL-013 /
/// DSL-018) fetch the single proposer pubkey per offense.
///
/// # Return semantics
///
/// `pubkey_of(idx)` returns `None` when `idx` does not correspond to a
/// registered validator — the caller is responsible for translating
/// that to a domain-appropriate error. For BLS verify, a missing
/// pubkey collapses to aggregate-verify failure (DSL-006), which
/// matches the security model: we do not want to distinguish "unknown
/// validator" from "bad signature" at this layer because both are
/// equally invalid evidence.
/// Blanket: any `ValidatorView` is a `PublicKeyLookup`. DSL-138.
///
/// Delegates `pubkey_of(idx)` to `self.get(idx).map(|e|
/// e.public_key())`. Keeps the BLS-aggregate verify path in
/// DSL-006 + DSL-013 from having to pass two trait-object
/// pointers when one suffices.
/// Reward-payout routing surface.
///
/// Traces to [SPEC §12.1](../../docs/resources/SPEC.md), catalogue row
/// [DSL-141](../../docs/requirements/domains/).
///
/// # Consumers
///
/// - `SlashingManager::submit_evidence` (DSL-025) routes the
/// whistleblower + proposer rewards through this trait.
/// - Appeal adjudication (DSL-067 / DSL-068 / DSL-071) credits the
/// winning party's reward account.
///
/// # Semantics
///
/// `pay(ph, amount)` creates-or-credits a pay-to-puzzle-hash account
/// at the consensus layer. `amount == 0` is legal and MUST still be
/// recorded — the call pattern is the protocol-observable side
/// effect (auditors rely on the two-call pattern per admission).
/// Reward clawback surface — reverses a previous `RewardPayout::pay`.
///
/// Traces to [SPEC §12.2](../../docs/resources/SPEC.md), catalogue row
/// [DSL-142](../../docs/requirements/domains/).
///
/// # Consumer
///
/// Sustained-appeal adjudication (DSL-067) pulls the paid rewards
/// back from the reporter + proposer accounts when the base slash is
/// reverted.
/// Collateral-slash reversal surface.
///
/// Traces to [SPEC §15.3](../../docs/resources/SPEC.md), catalogue row
/// [DSL-065](../../docs/requirements/domains/appeal/specs/DSL-065.md).
///
/// # Consumer
///
/// - Appeal adjudication (DSL-065) calls
/// `credit(validator_index, amount_mojos)` per reverted validator
/// when a `CollateralSlasher` is supplied. Semantically a revert of
/// the consensus-layer collateral debit that ran alongside the
/// `ValidatorEntry::slash_absolute` stake debit at admission.
///
/// # Optional wiring
///
/// Light-client deployments may not track collateral at all. The
/// adjudicator accepts `Option<&mut dyn CollateralSlasher>` and
/// no-ops when `None` — collateral revert is a full-node concern.
///
/// # Idempotence
///
/// The trait does not specify idempotence. Callers MUST call
/// `credit` exactly once per reverted validator — the adjudicator
/// does so by construction (one pass over `base_slash_per_validator`).
/// Failure modes for [`CollateralSlasher::slash`].
///
/// Traces to SPEC §15.2. Soft-failure contract: a
/// `NoCollateral` result must NOT abort slashing — stake-side
/// debit proceeds regardless (DSL-022).
/// Block-proposer lookup surface.
///
/// Traces to [SPEC §15.3](../../docs/resources/SPEC.md), catalogue row
/// [DSL-144](../../docs/requirements/domains/).
///
/// # Consumer
///
/// `SlashingManager::submit_evidence` (DSL-025) queries
/// `proposer_at_slot(current_slot())` to identify the proposer whose
/// block includes the evidence, then routes the proposer-inclusion
/// reward to that validator's puzzle hash.
/// Per-validator effective-balance read surface.
///
/// Traces to [SPEC §15.2](../../docs/resources/SPEC.md), catalogue row
/// [DSL-137](../../docs/requirements/domains/).
///
/// # Consumers
///
/// - `SlashingManager::submit_evidence` (DSL-022) reads `get(idx)` per
/// slashable validator to compute `base_slash = max(eff_bal * bps /
/// 10_000, eff_bal / 32)`.
/// - Reward math (DSL-081..085) reads `get` + `total_active` to derive
/// per-epoch base rewards.
///
/// Separate from `ValidatorView` because some impls (light clients)
/// maintain effective balances in a dedicated index without the full
/// per-validator entry state.
/// Validator-set read+write surface consumed by the verifiers and
/// slashing manager.
///
/// Traces to [SPEC §15.1](../../docs/resources/SPEC.md), catalogue row
/// [DSL-136](../../docs/requirements/domains/).
///
/// # Scope
///
/// `ValidatorView` is the narrow surface `dig-slashing` needs to read
/// (and mutate, on slash/appeal) per-validator state owned by the
/// consensus layer. The full trait surface is defined here so every
/// function signature in this crate can accept `&dyn ValidatorView` /
/// `&mut dyn ValidatorView`; concrete impls land in `dig-consensus`
/// and in test fixtures.
///
/// # Consumer list
///
/// - `verify_evidence` (DSL-011..020) — read-only for precondition
/// checks (registered, active, not-already-slashed).
/// - `SlashingManager::submit_evidence` (DSL-022) — mutating for
/// per-validator debit via `ValidatorEntry::slash_absolute`.
/// - `AppealAdjudicator` (DSL-064..067) — mutating for credit /
/// restore_status on sustained appeals.
/// Per-validator state accessor.
///
/// Traces to [SPEC §15.1](../../docs/resources/SPEC.md), catalogue rows
/// [DSL-131..135](../../docs/requirements/domains/).
///
/// # Invariants (enforced by DSL-131..135 when those impls land)
///
/// - `slash_absolute` saturates at effective-balance floor — cannot
/// drive balance negative.
/// - `credit_stake` returns the amount actually credited after any
/// ceiling clamp.
/// - `restore_status` is idempotent — returns `true` only when status
/// actually changed.
/// - `is_active_at_epoch(epoch)` is inclusive on activation, exclusive
/// on exit (DSL-134 boundary behaviour).
/// Block re-execution result used by `InvalidBlockOracle`.
///
/// Traces to [SPEC §15.3](../../docs/resources/SPEC.md), catalogue row
/// [DSL-145](../../docs/requirements/domains/).
/// Full-node block re-execution hook.
///
/// Traces to [SPEC §15.3](../../docs/resources/SPEC.md), catalogue rows
/// [DSL-020](../../docs/requirements/domains/evidence/specs/DSL-020.md)
/// + [DSL-049](../../docs/requirements/domains/) + [DSL-145].
///
/// # Role
///
/// - `verify_invalid_block` (DSL-020) calls `verify_failure` when the
/// caller supplied an oracle; absence means bootstrap mode (the
/// evidence is admitted and defers to the challenge window).
/// - `InvalidBlockAppeal::BlockActuallyValid` (DSL-049) calls
/// `re_execute` to adjudicate whether the accused block really is
/// invalid.
///
/// # Default `verify_failure`
///
/// The default body is `Ok(())` — bootstrap mode where every
/// well-signed evidence envelope is admitted. Real full-node impls
/// override to re-execute the block and cross-check the claimed
/// failure reason.
///
/// # Determinism
///
/// `re_execute` MUST be deterministic — same inputs → same outcome
/// (DSL-145). Non-determinism here would let the same block flip
/// between "valid" and "invalid" across honest nodes, breaking
/// evidence consensus.