Skip to content

[BUG FIX] Consensus: hardcoded year, missing block validation, memory leak (3 bugs, Medium-High severity)#1824

Open
AliaksandrNazaruk wants to merge 1 commit intoScottcjn:mainfrom
AliaksandrNazaruk:bugfix/consensus-poa-issues
Open

[BUG FIX] Consensus: hardcoded year, missing block validation, memory leak (3 bugs, Medium-High severity)#1824
AliaksandrNazaruk wants to merge 1 commit intoScottcjn:mainfrom
AliaksandrNazaruk:bugfix/consensus-poa-issues

Conversation

@AliaksandrNazaruk
Copy link
Contributor

Bug Report & Fix — Ref #305

Bug 1: CURRENT_YEAR hardcoded to 2025 (Medium)

File: rips/rustchain-core/config/chain_params.py
Impact: All Antiquity Score calculations are wrong in 2026+. A 1992 CPU gets AS based on 33-year age instead of correct 34. Every miner's score is off by ~3%, affecting reward distribution.
Fix: Replace hardcoded 2025 with datetime.now(timezone.utc).year.

Bug 2: validate_block() skips merkle_root and hash verification (High)

File: rips/rustchain-core/consensus/poa.py
Impact: Blocks with tampered miner data (fake rewards, fake wallets) pass validation because merkle_root and block hash are never checked. An attacker could submit a block claiming higher rewards for their wallet.
Fix: Added merkle root recalculation check and block hash integrity verification.

Bug 3: known_hardware memory leak (Medium)

File: rips/rustchain-core/consensus/poa.py
Impact: known_hardware dict is never cleared between blocks. After N blocks, it holds every hardware hash ever seen. Worse: hardware that mined in block N is permanently blocked from mining in block N+1 (duplicate hardware check always triggers for returning miners).
Fix: Clear known_hardware in _reset_block().

Steps to Reproduce

  1. Bug 1: print(CURRENT_YEAR) → outputs 2025 in 2026
  2. Bug 2: Create a Block, modify miners[0].reward, call validate_block() → returns True
  3. Bug 3: Run submit_proof() for miner A in block 1, call produce_block(), then submit_proof() for miner A in block 2 → rejected as duplicate

RTC Wallet: 0x0 (will update)

— grim-cod-29

…y leak

Bug 1: CURRENT_YEAR hardcoded to 2025, breaks all Antiquity Score
calculations in 2026+. Now uses datetime.now().year dynamically.

Bug 2: validate_block() never verifies merkle_root or block hash,
allowing blocks with tampered miner data or forged hashes to pass
validation. Added merkle root and hash integrity checks.

Bug 3: known_hardware dict never cleared between blocks, causing
unbounded memory growth and preventing hardware from mining in
subsequent blocks after its first submission.

Ref: Scottcjn#305 (Bug Report Bounty)
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/XL PR: 500+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants