Skip to content

fix: replace random with secrets for cryptographically secure validator selection#4189

Closed
BossChaos wants to merge 2 commits intoScottcjn:mainfrom
BossChaos:fix-consensus-validator-selection
Closed

fix: replace random with secrets for cryptographically secure validator selection#4189
BossChaos wants to merge 2 commits intoScottcjn:mainfrom
BossChaos:fix-consensus-validator-selection

Conversation

@BossChaos
Copy link
Copy Markdown
Contributor

Summary

Wallet: RTC6d1f27d28961279f1034d9561c2403697eb55602

Vulnerability Fixed

Non-Cryptographic Random in Validator Selection (HIGH)

File: rips/rustchain-core/consensus/poa.py, select_validator()

Bug: Uses random.uniform() and random.choice() for consensus validator selection. Python's random module is NOT cryptographically secure — the Mersenne Twister sequence is predictable after observing ~624 outputs.

Attack: An attacker monitoring block production can:

  1. Observe validator selections over multiple blocks
  2. Reconstruct the random seed/state
  3. Predict which validator will be selected next
  4. Target that validator for DoS, censorship, or MEV extraction

Fix: Replace random with secrets module (cryptographically secure):

  • random.uniform(0, total_as)secrets.randbelow(int(total_as * 1_000_000)) / 1_000_000
  • random.choice(proofs)proofs[secrets.randbelow(len(proofs))]

Local Testing

python test_poa_consensus_security.py
# PASS: Validator selection uses cryptographically secure randomness (secrets)

Related

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes size/S PR: 11-50 lines labels May 10, 2026
@Scottcjn
Copy link
Copy Markdown
Owner

Closing per first-poster ruling (2026-05-10).

@508704820 submitted the same finding class earlier today:

Per the Self-Audit Credit Check policy, the earliest poster of a finding earns the bounty. @508704820 has been paid 40 RTC for both.

Your implementation work is real, but not first. If your fix is materially better (more complete, better tests, edge cases the first-poster missed), please comment on @508704820 PR with the specific delta — that earns review-credit if it adds value.

— auto-triage 2026-05-10

@Scottcjn Scottcjn closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants