[BUG]: Validate persisted account state against the latest block's state root

未關閉
#175 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@JANAKIRAM218 已經在處理了。

開始於 2026年11月11日。

  • #182 來自 @JANAKIRAM218 —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
backend, databases

研究方向

Read minichain/persistence.py and trace how load() restores account data for SQLite and legacy JSON, then inspect State.state_root() in minichain/state.py and the latest block in minichain/chain.py. Start with the persistence tests in tests/test_persistence.py and check existing genesis-only coverage. Done means mismatched restored account state raises a clear ValueError while valid SQLite and JSON snapshots still load.

由索引模型根據 Issue 內容生成。

描述

bug
Bug Description

Problem Description

The persistence loading process validates the integrity of the stored blockchain, including block hashes and block linkage. However, after restoring account data from SQLite or a legacy JSON snapshot, it does not verify whether the restored account state matches the state_root committed in the latest block.

As a result, modified or inconsistent persisted account data could potentially be restored even when the stored blockchain passes the existing integrity checks.

Current Behavior

In minichain/persistence.py, the load() function:

  1. Loads persisted blocks and account data.
  2. Validates the blockchain's integrity using _verify_chain_integrity().
  3. Normalizes the restored account data.
  4. Assigns the restored data directly to blockchain.state.accounts.

However, it does not compare the calculated state root of the restored accounts against the latest block's committed state_root.

Expected Behavior

After restoring the account data, the loader should:

  1. Calculate the state root using the existing State.state_root() implementation.
  2. Retrieve the expected state root from the latest block.
  3. Compare both roots.
  4. Reject the persisted snapshot with a clear ValueError if they do not match.

Valid persisted snapshots should continue to load normally.

Proposed Solution

Extend the existing integrity verification in minichain/persistence.py to validate the restored account state against the latest block's state root.

The implementation should reuse the existing state-root calculation rather than introduce a separate hashing mechanism.

Both SQLite persistence and legacy JSON restoration should retain their existing supported behavior.

Suggested Test Cases

  • Valid persisted account state loads successfully.
  • Modified account balance causes restoration to fail.
  • Modified account nonce causes restoration to fail.
  • Modified contract storage causes restoration to fail.
  • Missing or modified account data is rejected when it changes the calculated state root.
  • Valid genesis-only chain restoration continues to work.
  • Valid legacy JSON snapshots continue to load successfully.

Expected Outcome

  • Improved persistence integrity.
  • Detection of inconsistent or corrupted account data during restoration.
  • Consistency between the restored account state and the latest block's commitment.
  • Better reliability when restarting blockchain nodes.

Additional Context

Relevant implementation files:

  • minichain/persistence.py
  • minichain/state.py
  • minichain/chain.py
  • tests/test_persistence.py

I would like to work on this issue after maintainer confirmation and follow the existing architecture and testing conventions.

Steps to Reproduce
  1. Create a MiniChain blockchain instance.
  2. Create an account and execute a transaction that changes the account's balance or nonce.
  3. Save the blockchain using the existing persistence mechanism (SQLite or JSON snapshot).
  4. Directly modify the persisted account data (for example, change the account balance) without modifying the stored blocks.
  5. Attempt to reload the blockchain using persistence.load().
  6. Observe whether the modified account state is successfully restored despite not matching the latest block's committed state root.
Logs and Screenshots

No response

Environment Details

No response

Impact

Medium - Feature works but has issues

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
主要語言
Python
星號
12
分支
27
平均合併
2 分鐘
30 天內合併 PR
1

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

StabilityNexus/MiniChain 的其他 Issue

查看 StabilityNexus/MiniChain 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。