[BUG]: Validate persisted account state against the latest block's state root
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 12
- Fork
- 27
- Merge trung bình
- 2 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của StabilityNexus/MiniChain
-
[BUG]: Handle JSON-RPC notifications and empty batches correctlyCó thể đã có người làm @Muneerali199 đã nhận 10 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
StabilityNexus/MiniChain#177 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
automatic-copyright-year: keep README copyright currentCó thể đã có người làm @anshulchikhale30-p đã nhận 7 ngày trước. Đang mởdocumentation enhancement
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 35/100
StabilityNexus/MiniChain#189 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Difficulty: bound per-block EMA moves, add a difficulty floor, and preserve state across restartsCó thể đã có người làm @anshulchikhale30-p đã nhận 7 ngày trước. Đang mởbug documentation enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
StabilityNexus/MiniChain#187 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: Blocks on a different parent are classified INVALID and get the sender bannedCó thể đã có người làm @kansalakshat đã nhận 7 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
StabilityNexus/MiniChain#185 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: P2P sync downloads full 500-block chunks without headers-first validationCó thể đã có người làm @anshulchikhale30-p đã nhận 14 ngày trước. Đang mởbug documentation enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
StabilityNexus/MiniChain#178 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của StabilityNexus/MiniChain
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
huggingface/datasets#9128 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:low ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
OpenHands/extensions#975 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Function/dict state handlers can't supply provider-state injected values (`generate.provider_state`)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pact-foundation/pact-python#1789 ·
Maintainer thường phản hồi trong vòng 9 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
juandresrodca/AdminForge#66 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày