feat: Add Ethereum-style timestamp validation and PoW hash check#117
feat: Add Ethereum-style timestamp validation and PoW hash check#117SIDDHANTCOOKIE wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughBlock validation in chain.py now enforces Proof-of-Work difficulty (leading-zero hash prefix) and timestamp rules (strict increase from previous block, bounded future tolerance of 15,000 ms), with ValueErrors mapped to INVALID or FAILED status. Persistence tests updated to use deterministic incrementing timestamps. ChangesBlock Validation Rules
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Addressed Issues:
This PR introduces critical security and consensus fixes to the Blockchain class to prevent difficulty manipulation and secure the Proof-of-Work validation loop.
The Vulnerability Fixed: Previously, validate_block_link_and_hash verified that a block's hash mathematically matched its contents, but it never checked if the hash actually satisfied the target difficulty. A malicious actor could broadcast a block with nonce=0 and as long as they set the difficulty integer to the required target, the network would accept it instantly without any actual PoW being performed.
Screenshots/Recordings:
TODO: If applicable, add screenshots or recordings that demonstrate the interface before and after the changes.
Additional Notes:
AI Usage Disclosure:
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.
Check one of the checkboxes below:
I have used the following AI models and tools: TODO
Checklist
Summary by CodeRabbit
Bug Fixes
Tests