[BUG]: Validate persisted account state against the latest block's state root
维护者通常 1 天内回复
评估
调研方向
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 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:
- Loads persisted blocks and account data.
- Validates the blockchain's integrity using
_verify_chain_integrity(). - Normalizes the restored account data.
- 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:
- Calculate the state root using the existing
State.state_root()implementation. - Retrieve the expected state root from the latest block.
- Compare both roots.
- Reject the persisted snapshot with a clear
ValueErrorif 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.pyminichain/state.pyminichain/chain.pytests/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
- Create a MiniChain blockchain instance.
- Create an account and execute a transaction that changes the account's balance or nonce.
- Save the blockchain using the existing persistence mechanism (SQLite or JSON snapshot).
- Directly modify the persisted account data (for example, change the account balance) without modifying the stored blocks.
- Attempt to reload the blockchain using
persistence.load(). - 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
StabilityNexus/MiniChain 的其他 Issue
-
[BUG]: Handle JSON-RPC notifications and empty batches correctly可能已有人在做 @Muneerali199 于 10 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
StabilityNexus/MiniChain#177 · 2 条评论 ·
维护者通常 1 天内回复
-
automatic-copyright-year: keep README copyright current可能已有人在做 @anshulchikhale30-p 于 7 天前认领。 未关闭documentation enhancement
难度 3/5 半天 新手友好度 35/100
StabilityNexus/MiniChain#189 ·
维护者通常 1 天内回复
-
Difficulty: bound per-block EMA moves, add a difficulty floor, and preserve state across restarts可能已有人在做 @anshulchikhale30-p 于 7 天前认领。 未关闭bug documentation enhancement
难度 4/5 3-5 天 新手友好度 25/100
StabilityNexus/MiniChain#187 ·
维护者通常 1 天内回复
-
[BUG]: Blocks on a different parent are classified INVALID and get the sender banned可能已有人在做 @kansalakshat 于 7 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 35/100
StabilityNexus/MiniChain#185 ·
维护者通常 1 天内回复
-
[BUG]: P2P sync downloads full 500-block chunks without headers-first validation可能已有人在做 @anshulchikhale30-p 于 14 天前认领。 未关闭bug documentation enhancement
难度 5/5 一周以上 新手友好度 25/100
StabilityNexus/MiniChain#178 ·
维护者通常 1 天内回复
查看 StabilityNexus/MiniChain 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
huggingface/datasets#9128 ·
维护者通常 1 天内回复
-
priority:low ready-for-dev
难度 2/5 1-3 小时 新手友好度 68/100
OpenHands/extensions#975 ·
维护者通常 1 天内回复
-
Function/dict state handlers can't supply provider-state injected values (`generate.provider_state`)未关闭
难度 2/5 1-3 小时 新手友好度 78/100
pact-foundation/pact-python#1789 ·
维护者通常 9 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 82/100
juandresrodca/AdminForge#66 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复