feat: Validator Stake Slashing Condition Verification with Fraud Proofs #135 - #167
Merged
JamesEjembi merged 7 commits intoAug 23, 2026
Conversation
…sizing (VeriNode-Labs#134) What was changed: - Added src/pg_pool/mod.rs: new pure-Rust module implementing the full PostgreSQL connection-pool health probe with adaptive sizing as required by issue VeriNode-Labs#134. Provides: * ConnectionPoolState - point-in-time snapshot (utilisation, P99 latency, pending requests, idle/active connection counts). * PoolHealthProbe - stateless probe classifying pools as Healthy / Warning / Degraded / Unavailable using saturation threshold (90%), P99 latency target (100 ms), and consecutive-unhealthy probe counter. * PoolAdaptiveSizer - stateful sizer tracking resize history and consecutive unhealthy probes; enforces cooldown window (30 s), min/max pool-size bounds (2..128), and canary release gate. * PoolCanaryAnalysis - blue-green / canary gate (99.99% success rate, 100 ms P99, security review required). * ConnectionPoolRegistry - multi-service registry with upsert, probe_all, dashboard_snapshot, and 512-pool capacity limit. * System-wide PoolMetricsSnapshot for dashboards and alerting pipelines. * Comprehensive unit tests (39 cases) co-located in the module. * All operational constants derived from issue VeriNode-Labs#134 technical bounds: P99 < 100 ms, 99.99% availability target. - Added tests/pg_pool_health_probe_test.rs: standalone integration-test suite (39 additional cases) covering every public type and all edge cases: utilisation arithmetic, health-state transitions, resize decisions, cooldown enforcement, canary gate boundary conditions, registry upsert / probe-all / capacity limits, and technical-invariant assertions. - Modified src/lib.rs: registered pub mod pg_pool with doc-comment matching the style of every other module in the file. - Modified Cargo.toml: added [[test]] entry for pg_pool_health_probe_test so cargo test discovers and runs the integration tests.
- fix(consensus): replace non-existent u64::saturating_shl with checked_shl in timeout_leader.rs (E0599 compile error on stable) - fix(fmt): apply rustfmt to bls_aggregator.rs, view_change/mod.rs, view_change/resolver.rs, db/mod.rs, db/slashing-store.rs, slashing/accumulator.rs, slashing/condition-engine.rs, slashing/mod.rs, slashing/types.rs, tests/consensus/view_change_partition_test.rs
…y_fragmentation_test - pub mod mem added to lib.rs so sorosusu_contracts::mem::buddy_allocator is reachable from integration tests (E0433: cannot find mem) - pool/mod.rs: declare shard_allocator, shard_defragmenter, tenant_registry sub-modules and re-export all symbols the test imports: ShardAllocator, ShardDefragmenter, TenantRegistry, ShardAllocResult, PoolFragmentationGauge, DefragEvent, bulk_allocate, bulk_free, SHARD_SIZE_BYTES, FRAGMENTATION_ALARM_RATIO, COALESCING_WINDOW_MS (E0432: unresolved imports)
- consensus_engine.rs: move DEADLOCK_VIEW_THRESHOLD import into #[cfg(test)] block (unused-imports in production compilation unit) - consensus_engine.rs: box EquivocationProof in EquivocationDetected variant to fix large-enum-variant (384 vs 40 bytes) - bls_aggregator.rs: replace chunks_exact(4) with as_chunks::<4>().0 to satisfy chunks-exact-to-as-chunks lint - slashing-store.rs: remove redundant & refs in slice comparison (op_ref lint: use bytes[0..8] != SLASHING_STORE_MAGIC directly)
VeriNode-Labs#135 Implements the full slashing pipeline under src/consensus/slashing/: - detector.rs: SlashingConditionDetector scans for equivocation (two conflicting blocks at the same height), unavailability (missed >100 attestations in 24h rolling window), and invalid proposals. Returns SlashingViolation with encoded evidence bytes on detection. - evidence.rs: EvidenceStore accepts (validator_id, offense_type, evidence, bond) submissions from any party. Cryptographically verifies fraud proofs before accepting: equivocation evidence must prove two distinct block hashes at the same height (72-byte layout); unavailability evidence must show missed_count > UNAVAILABILITY_THRESHOLD (16-byte layout); invalid-proposal evidence requires a non-zero height (72 bytes). - challenge.rs: ChallengeManager opens a 7-day challenge window for each submission. The accused validator may submit counter-evidence before the deadline; if valid, the challenge is resolved DefenderWon and the challenger's bond is returned for slashing. After the deadline without successful rebuttal the record transitions to Expired. - executor.rs: SlashingExecutor applies stake penalties after a challenge expires. Slashing amounts: equivocation = 100% of stake; unavailability = 0.1% per missed attestation capped at 10%; invalid proposal = 2%. Slashed funds: 50% burned, 50% distributed equally to active validators. Idempotency guard prevents double-slashing. - mod.rs: wires the four sub-modules and re-exports the public API. - src/consensus/mod.rs: adds pub mod slashing. - Cargo.toml: registers tests/consensus/slashing_fraud_proof_test.rs. - tests/consensus/slashing_fraud_proof_test.rs: integration test covering the full pipeline (equivocation detect -> submit evidence -> open challenge -> fast-forward 7 days -> slashing execution -> verify 50/50 burn/distribute split), plus unavailability and invalid-proposal scenarios, counter-evidence winning path, and detector edge cases. All files compile with zero warnings and zero errors under cargo check and cargo clippy.
Run cargo fmt --all to bring all new files in src/consensus/slashing/ and tests/consensus/slashing_fraud_proof_test.rs into compliance with the project rustfmt style (line-length, trailing commas, newline style). All changes are formatting-only; no logic was altered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #135
Summary of changes
Implements the complete four-module slashing pipeline under src/consensus/slashing/:
detector.rs — Slashing condition detector
�vidence.rs — Evidence submission and verification
challenge.rs — 7-day challenge period and counter-evidence
�xecutor.rs — Stake slashing and fund distribution
mod.rs — Module wiring and re-exports
src/consensus/mod.rs — Added pub mod slashing
Cargo.toml — Registered slashing_fraud_proof_test
Integration test ( ests/consensus/slashing_fraud_proof_test.rs)
Testing / validation performed
Note: linking tests to a final binary is blocked by a pre-existing environment-level constraint (Windows SDK libs missing for MSVC toolchain; GNU toolchain export-ordinal overflow on the large project binary). These are repo-wide issues that pre-date this PR and are unrelated to the new code.