Fix blockchain chain continuity: cross-check previous_integrity_hash against DB predecessor#520
Draft
Copilot wants to merge 2 commits into
Conversation
…h against DB predecessor Co-authored-by: RohanExploit <178623867+RohanExploit@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] WIP address feedback on Blockchain Integrity and Admin Stats
Fix blockchain chain continuity: cross-check previous_integrity_hash against DB predecessor
Mar 8, 2026
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.
verify_blockchain_integritytrusted theprevious_integrity_hashstored on the Issue record without verifying it against the actual predecessor in the DB. A tampered or cache-staleprevious_integrity_hashcould cause the endpoint to reportis_valid=Trueeven when the chain was broken.Changes
backend/routers/issues.py— Whenprevious_integrity_hashis non-NULL, perform an additional scalar query for the actual predecessor'sintegrity_hash(max id < issue_id). A mismatch setschain_link_valid = False, short-circuitingis_validbefore the hash recomputation matters:tests/test_blockchain.py— Addedtest_blockchain_verification_tampered_previous_hash: creates a record with a forgedprevious_integrity_hash(correct computed hash, wrong chain link) and assertsis_valid=False.Type of Change
Related Issue
Testing Done
Screenshots (if applicable)
Checklist
Co-Authors
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.
Summary by cubic
Strengthens blockchain checks by comparing each block’s
previous_integrity_hashto the real predecessor in the DB and failing on mismatches. Adds a test for tampered links and fixes admin stats windows to avoid double counting with consistent UTC boundaries.Written for commit 5b28643. Summary will update on new commits.