fix: keep p2p entropy scores monotonic on attestation sync#2131
Merged
Scottcjn merged 1 commit intoScottcjn:mainfrom Apr 6, 2026
Merged
fix: keep p2p entropy scores monotonic on attestation sync#2131Scottcjn merged 1 commit intoScottcjn:mainfrom
Scottcjn merged 1 commit intoScottcjn:mainfrom
Conversation
Contributor
Author
|
For bounty payout, please use RTC wallet: RTC1d48d848a5aa5ecf2c5f01aa5fb64837daaf2f35. |
Owner
|
Reviewed. Two-part fix: (1) Payment: 75 RTC — P2P entropy monotonicity + epoch validation (High severity) Merging. Thank you createkr. |
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.
fix(p2p): prevent entropy_score downgrade via P2P attestation sync
Problem
_save_attestation_to_dbin the P2P gossip layer unconditionally overwroteentropy_scoreon conflict (entropy_score = excluded.entropy_score), allowingany authenticated P2P peer to erase a legitimately-measured high entropy score
by sending a crafted attestation with
entropy_score: 0.entropy_scoreis used as the primary tiebreaker in anti-double-mining canonicalminer selection (
ORDER BY entropy_score DESC). Downgrading it to 0 allows aspoofed miner ID with even a low score to become canonical, undermining the
double-mining defense.
Fix
Apply
MAX()monotonicity protection — same pattern already used forfingerprint_passed:Changes
node/rustchain_p2p_gossip.py —
_save_attestation_to_db: replaceunconditional
entropy_score = excluded.entropy_scorewithMAX(COALESCE(miner_attest_recent.entropy_score, 0), excluded.entropy_score).Updated comment to document both protected fields.
node/tests/test_p2p_entropy_score_downgrade.py — new test file, 9 tests:
test_old_p2p_downgrade_zero_erases_high_entropy— demonstrates bugtest_old_p2p_partial_downgrade— demonstrates partial downgradetest_old_behaviour_downgrade_changes_canonical_miner— end-to-end attacktest_fixed_p2p_zero_cannot_downgrade— verifies fixtest_fixed_p2p_lower_score_cannot_downgrade— verifies fixtest_fixed_p2p_higher_score_allowed_to_upgrade— monotonic increase OKtest_fixed_p2p_first_attestation_still_works— no regressiontest_fixed_p2p_null_entropy_treated_as_zero— NULL handlingtest_fixed_behaviour_canonical_miner_preserved— end-to-end fix verifyTesting
Compatibility
No breaking changes.
MAX()is monotonic — higher scores from honest peers arestill accepted. No schema changes, no migration needed. Backward compatible with
nodes running older code.