moeen-shahid/blockchain-security
GitHub: moeen-shahid/blockchain-security
一个从第一性原理出发的区块链与智能合约安全学习仓库,涵盖密码学基础、Solidity 开发、DeFi 安全及审计实战的完整路径。
Stars: 0 | Forks: 0
# blockchain-security
从第一性原理出发深入探讨智能合约安全 —— 从 Bitcoin 白皮书开始,逐步深入到 Ethereum、Solidity 和 DeFi 安全。
## 进度
### ✅ 阶段 1 — 为什么需要区块链
- [x] Bitcoin 白皮书 (Satoshi Nakamoto, 2008)
- [x] 《Mastering Bitcoin》第 1–2 章 (Andreas Antonopoulos)
### ✅ 阶段 2 — 密码学基础
- [x] SHA-256 和哈希函数(概念性)
- [x] Merkle 树 —— 使用 Python 从零开始实现 (`foundations/merkle.py`)
### 🔄 阶段 3 — 区块链核心机制与 Ethereum
- [ ] 《Mastering Ethereum》第 1–2 章
- [ ] 《Mastering Ethereum》第 3–6 章(EVM、交易、gas、智能合约)
- [ ] ethereum.org 开发者文档
### ⬜ 阶段 4 — 智能合约 (Solidity)
- [ ] CryptoZombies
- [ ] Solidity by Example
- [ ] OpenZeppelin Contracts —— 阅读生产级别的 Solidity
### ⬜ 阶段 5 — DeFi 概念
- [ ] 《Mastering Ethereum》DeFi 部分
- [ ] Uniswap V2 白皮书
### ⬜ 阶段 6 — 安全基础
- [ ] SWC Registry (智能合约弱点分类)
- [ ] rekt.news —— 10–20 篇黑客攻击事件复盘
- [ ] Immunefi bug bounty 分析报告
- [ ] Solodit Checklist + Cyfrin 的“Solodit Checklist Explained”
### ⬜ 阶段 7 — 动手实践 CTF
- [ ] Ethernaut —— 所有挑战
- [ ] Damn Vulnerable DeFi —— 所有挑战
- [ ] Capture the Ether —— 所有挑战
### ⬜ 阶段 8 — 工具
- [ ] Foundry
- [ ] Slither(+ 阅读检测器源码)
- [ ] Echidna
- [ ] Mythril
### ⬜ 阶段 9 — 系统化课程
- [ ] Cyfrin Updraft
- [ ] Secureum 101/201 系列
- [ ] Solodit —— 实时审计发现
## 仓库结构
```
blockchain-security/
├── foundations/
│ └── merkle.py # Merkle tree from scratch — build_tree, get_branch, verify_proof
├── ctf-solutions/
│ ├── ethernaut/
│ └── damn-vulnerable-defi/
├── audit-notes/ # rekt.news post-mortems, vulnerability patterns
└── notes/
└── ethereum.md # running notes while reading Mastering Ethereum
```
## 实现
### `foundations/merkle.py`
仅使用 Python 的 `hashlib.sha256` 作为黑盒,从零开始构建的 Merkle 树。实现了以下功能:
- `hash_leaf` / `hash_pair` —— 构建整个树的两个基础操作
- `build_tree` —— 自底向上构建所有层,通过 Bitcoin 的复制约定处理奇数长度的层
- `get_root` —— 返回唯一的根哈希
- `get_branch` —— 返回证明一笔交易被包含所需的最小兄弟哈希集(即全节点发送给 SPV 客户端的内容)
- `verify_proof` —— 在无法访问完整树的情况下,根据一笔交易和分支重新计算出根哈希(即 SPV 客户端在本地运行的内容)
自测涵盖了篡改检测和奇数交易的边缘情况。
*github.com/moeen-shahid*
标签:Solidity, Web3安全, 区块链, 学习笔记, 密码学基础, 智能合约, 逆向工具