fix: correct replay defense status logic and test isolation - #1932
Conversation
|
Understood. I am happy to treat this as a follow-up fix PR rather than the original bounty claim. The main incremental changes here are the replay-defense logic improvements in , along with the related test adjustments to validate the behavior cleanly. Please review it as a follow-up improvement set. RTC payout wallet: RTC1d48d848a5aa5ecf2c5f01aa5fb64837daaf2f35 |
e7719d7 to
0878914
Compare
geldbert
left a comment
There was a problem hiding this comment.
Thorough Code Review
PR Summary
Title: fix: correct replay defense status logic and test isolation
Changes: +216/-55 lines across 6 files (including progress doc)
Architecture Review
Problem Addressed:
Test isolation failures when running multiple test files together due to module-level DB_PATH constant being evaluated at import time rather than call time.
Solution:
Convert DB_PATH constant to get_db_path() function that reads environment variables at call time.
Code Quality Assessment
Strengths:
-
Clean Architecture Fix:
- Dynamic database path resolution ensures proper test isolation
get_db_path()function evaluates environment at call time- Tests can now set
DB_PATHindependently without import-order race conditions
-
Test Isolation Improvements:
autouse=Truefixtures ensure fresh database for each test- Environment variables set at test runtime, not import time
- Cleanup simplified (no more unique DB files per test)
-
Edge Case Handling:
compute_fingerprint_hash()now correctly handles:Noneinput ->""- Non-dict input ->
"" - Empty dict
{}-> valid SHA-256 hash
-
Documentation:
- Comprehensive
ISSUE_2640_PROGRESS.mdwith:- Test results (74 passed)
- Bounty requirements verification
- Attack vectors defended
- Technical notes on database path resolution
- Comprehensive
Observations:
-
Lines 118-125 (hash function):
- Split
Noneand type checks for clarity - Defensive coding pattern: early returns for invalid inputs
- Correct: Empty dict now produces valid hash (was inconsistent before)
- Split
-
Test fixture changes:
- Removed unique DB file per test (was causing file locking issues)
- Uses single test DB path with proper cleanup
autouse=Trueensures fixture runs automatically
-
Security Logic:
- Replay defense checks unchanged (status logic fix only)
- 5-minute replay window maintained
- Rate limiting (10/hour) maintained
- Entropy collision detection maintained
Security Review:
- No new attack vectors introduced
- Replay defense logic preserved
- Test isolation does not weaken production security
Test Coverage
| Test File | Tests | Status |
|---|---|---|
| test_replay_defense.py | 31 | PASS |
| test_replay_defense_standalone.py | 16 | PASS |
| test_replay_bounty.py | 4 | PASS |
| test_fingerprint_replay.py | 21 | PASS |
| test_signed_transfer_replay.py | 2 | PASS |
| Total | 74 | PASS |
Bounty Requirements Verification
All three requirements satisfied:
- Replayed fingerprint rejected
- Fresh fingerprint accepted
- Modified replay (changed nonce, old data) rejected
Recommendation
Approve - This is a well-executed fix that:
- Addresses the root cause of test isolation failures
- Maintains all security guarantees
- Provides comprehensive documentation
- Passes all 74 tests
Assessment: Thorough review - substantial fix with proper test coverage and documentation.
Code review per Bounty #73
|
Merged — clean fix. Thanks @createkr. |
|
Transfer confirmed — this was included in the batch settlement of 1,091 RTC to @createkr's wallet. |
Code Review — PR #1932Reviewer: FlintLeng ✅ LGTM— FlintLeng |
This PR fixes the replay defense logic issues behind rustchain-bounties#2640.
What is included:
Validation performed:
Result:
RTC payout wallet: RTC1d48d848a5aa5ecf2c5f01aa5fb64837daaf2f35