Skip to content

security: fix Rust unwrap() DoS vectors + dispute resolution coverage#14

Merged
agentmecz merged 5 commits intomainfrom
security/unwrap-fixes-and-dispute-coverage
Feb 17, 2026
Merged

security: fix Rust unwrap() DoS vectors + dispute resolution coverage#14
agentmecz merged 5 commits intomainfrom
security/unwrap-fixes-and-dispute-coverage

Conversation

@agentmecz
Copy link
Owner

Security Fixes

1. Rust unwrap() → proper error handling

  • 8 files fixed: message_handler, persistence, circuit_breaker, rate_limit, arbitration, embedding, multichain, error
  • RwLock poisoning → recovery instead of panic
  • SystemTime unwrap → map_err/?
  • All 608 tests pass ✅

2. TieredDisputeResolution test coverage

  • Functions: 51% → 87.5%
  • Lines: 83% → 98%
  • Statements: 87% → 100%
  • +55 new test cases (971 lines)
  • Covers: withdrawFees, registerArbiter, getArbiters, appeal, autoResolution, etc.

Motivation

Security audit identified 546× unwrap() in Rust node as DoS vector (malformed P2P messages could crash the node). TieredDisputeResolution had only 51% function coverage — critical dispute logic was untested.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Lada and others added 5 commits February 17, 2026 16:04
Replace all unwrap() calls in production Rust code that could cause
panics from malformed P2P messages or poisoned locks (DoS vectors).

- message_handler.rs: Replace 5 SystemTime unwrap() with map_err/?
- persistence.rs: Replace 6 RwLock unwrap() with map_err/? returning
  Persistence errors
- circuit_breaker.rs: Replace 9 RwLock unwrap() with
  unwrap_or_else(|e| e.into_inner()) to recover from poison
- rate_limit.rs: Replace NonZeroU32 unwrap() with expect() (guarded),
  header parse unwrap() with if-let, Response builder with expect()
- arbitration.rs: Replace SystemTime unwrap() with map_err/?
- embedding.rs: Replace NonZeroUsize unwrap() with ok_or_else/?
- multichain.rs: Replace errors.next().unwrap() with expect() (guarded)
- error.rs: Add Internal variant for system-level failures

All 608 tests pass (556 unit + 21 integration + 21 API + 10 load).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add 55 new test cases covering previously untested functions and paths:

Newly tested functions (zero coverage before):
- withdrawFees: admin withdrawal, empty pool revert, access control
- registerArbiter: success, zero address, duplicate, access control
- unregisterArbiter: success, swap-and-pop, non-existent noop, access
- getEligibleArbiters: full list, empty after removal
- getDispute: correct data, non-existent returns zero
- getVotes: empty before voting, correct vote details
- getArbiters: before/after selection, no duplicates, parties excluded

Additional coverage for partially-tested functions:
- createDispute: tier 3, duplicate revert, provider creation, fee pool
- submitEvidence: non-party revert, both parties submit
- submitAIAnalysis: invalid share, evidence period, tier 1 revert
- castVote: already voted, invalid split share
- finalizeRuling: provider majority, split averaging, tie 50/50,
  wrong state, voting not ended
- appeal: wrong state, non-party, client appeal, clears votes/arbiters
- executeSettlement: wrong state revert
- checkAutoResolution: non-existent, non-tier1, during evidence,
  both evidence 50/50, no client evidence
- executeAutoResolution: provider executes, not tier 1, not ended,
  not party
- getArbiterCount: rounds 2/3/4+
- calculateFee/determineTier: edge cases

Coverage results (94 tests, all passing):
- Functions: 51.25% -> 87.50% (41/80 -> 70/80)
- Lines: 82.52% -> 97.97% (203/246 -> 241/246)
- Branches: 82.76% -> 96.55% (240/290 -> 280/290)
- Statements: 86.96% -> 100.00% (20/23 -> 23/23)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@agentmecz agentmecz force-pushed the security/unwrap-fixes-and-dispute-coverage branch from 69dd6d6 to 75f45d2 Compare February 17, 2026 16:04
@agentmecz agentmecz merged commit 2d42b9f into main Feb 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments