blockchain-basics
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBlockchain Basics Skill
区块链基础技能
Master blockchain fundamentals including consensus mechanisms, cryptographic primitives, and distributed systems architecture.
掌握区块链基础知识,包括共识机制、密码学原语和分布式系统架构。
Quick Start
快速开始
python
undefinedpython
undefinedInvoke this skill for blockchain fundamentals
Invoke this skill for blockchain fundamentals
Skill("blockchain-basics", topic="consensus", depth="intermediate")
undefinedSkill("blockchain-basics", topic="consensus", depth="intermediate")
undefinedTopics Covered
涵盖主题
1. Consensus Mechanisms
1. 共识机制
Learn how distributed networks achieve agreement:
- Proof of Work: Mining, hashrate, difficulty adjustment
- Proof of Stake: Validators, slashing, finality
- Byzantine Fault Tolerance: Leader election, view changes
了解分布式网络如何达成共识:
- Proof of Work:挖矿、哈希率、难度调整
- Proof of Stake:验证者、削减机制、最终性
- Byzantine Fault Tolerance:领导者选举、视图切换
2. Cryptographic Foundations
2. 密码学基础
Understand the security primitives:
- Hash Functions: SHA-256, Keccak-256, properties
- Digital Signatures: ECDSA, Ed25519, verification
- Merkle Trees: Proof construction, verification
理解安全原语:
- Hash Functions:SHA-256、Keccak-256、特性
- Digital Signatures:ECDSA、Ed25519、验证
- Merkle Trees:证明构建、验证
3. Network Architecture
3. 网络架构
Explore distributed systems:
- P2P Networks: Gossip protocols, peer discovery
- Node Types: Full nodes, light clients, archives
- Block Propagation: Compact blocks, relay networks
探索分布式系统:
- P2P Networks:Gossip协议、节点发现
- Node Types:全节点、轻客户端、归档节点
- Block Propagation:紧凑区块、中继网络
4. Transaction Lifecycle
4. 交易生命周期
Follow data through the chain:
- Transaction Structure: Inputs, outputs, signatures
- Mempool: Fee markets, ordering, priority
- Confirmation: Finality, reorganization
追踪链上数据流程:
- Transaction Structure:输入、输出、签名
- Mempool:手续费市场、排序、优先级
- Confirmation:最终性、链重组
Code Examples
代码示例
Verify Merkle Proof
验证默克尔证明
python
import hashlib
def verify_merkle_proof(leaf: bytes, proof: list, root: bytes) -> bool:
"""Verify a Merkle proof for inclusion"""
current = leaf
for sibling, is_left in proof:
if is_left:
current = hashlib.sha256(sibling + current).digest()
else:
current = hashlib.sha256(current + sibling).digest()
return current == rootpython
import hashlib
def verify_merkle_proof(leaf: bytes, proof: list, root: bytes) -> bool:
"""Verify a Merkle proof for inclusion"""
current = leaf
for sibling, is_left in proof:
if is_left:
current = hashlib.sha256(sibling + current).digest()
else:
current = hashlib.sha256(current + sibling).digest()
return current == rootCalculate Block Hash
计算区块哈希
python
import hashlib
import struct
def calculate_block_hash(header: dict) -> bytes:
"""Calculate Bitcoin-style block hash"""
data = struct.pack(
'<I32s32sIII',
header['version'],
bytes.fromhex(header['prev_block']),
bytes.fromhex(header['merkle_root']),
header['timestamp'],
header['bits'],
header['nonce']
)
return hashlib.sha256(hashlib.sha256(data).digest()).digest()[::-1]python
import hashlib
import struct
def calculate_block_hash(header: dict) -> bytes:
"""Calculate Bitcoin-style block hash"""
data = struct.pack(
'<I32s32sIII',
header['version'],
bytes.fromhex(header['prev_block']),
bytes.fromhex(header['merkle_root']),
header['timestamp'],
header['bits'],
header['nonce']
)
return hashlib.sha256(hashlib.sha256(data).digest()).digest()[::-1]Common Pitfalls
常见误区
| Pitfall | Issue | Solution |
|---|---|---|
| Finality confusion | PoW is probabilistic | Wait for 6+ confirmations |
| Hash vs encryption | Hashes are one-way | Use proper encryption for secrets |
| Timestamp trust | Miners can manipulate | Use block height for precision |
| 误区 | 问题 | 解决方案 |
|---|---|---|
| 最终性混淆 | PoW具有概率性 | 等待6个以上确认 |
| 哈希与加密混淆 | 哈希是单向的 | 对机密信息使用适当的加密方式 |
| 时间戳信任问题 | 矿工可以操纵时间戳 | 使用区块高度确保精度 |
Troubleshooting
故障排除
"Why is my transaction not confirming?"
"为什么我的交易没有确认?"
- Check transaction fee vs current mempool
- Verify nonce is sequential (no gaps)
- Ensure sufficient balance for amount + gas
- 检查交易手续费与当前内存池情况
- 验证随机数(nonce)是连续的(无间隔)
- 确保余额足够支付交易金额+手续费
"How do I verify a signature?"
"如何验证签名?"
python
from eth_account import Account
from eth_account.messages import encode_defunct
message = encode_defunct(text="Hello")
address = Account.recover_message(message, signature=sig)python
from eth_account import Account
from eth_account.messages import encode_defunct
message = encode_defunct(text="Hello")
address = Account.recover_message(message, signature=sig)Learning Path
学习路径
[Beginner] → Hash Functions → Digital Signatures → Transactions
↓
[Intermediate] → Merkle Trees → Consensus → Network Layer
↓
[Advanced] → BFT Protocols → Sharding → Cross-chain[Beginner] → Hash Functions → Digital Signatures → Transactions
↓
[Intermediate] → Merkle Trees → Consensus → Network Layer
↓
[Advanced] → BFT Protocols → Sharding → Cross-chainTest Yourself
自我测试
python
undefinedpython
undefinedUnit test template
Unit test template
def test_merkle_root():
txs = [b"tx1", b"tx2", b"tx3", b"tx4"]
root = build_merkle_root(txs)
assert len(root) == 32
assert verify_merkle_proof(txs[0], get_proof(0), root)
undefineddef test_merkle_root():
txs = [b"tx1", b"tx2", b"tx3", b"tx4"]
root = build_merkle_root(txs)
assert len(root) == 32
assert verify_merkle_proof(txs[0], get_proof(0), root)
undefinedCross-References
交叉引用
- Bonded Agent:
01-blockchain-fundamentals - Related Skills: ,
ethereum-developmentsmart-contract-security
- Bonded Agent:
01-blockchain-fundamentals - Related Skills: ,
ethereum-developmentsmart-contract-security
Version History
版本历史
| Version | Date | Changes |
|---|---|---|
| 2.0.0 | 2025-01 | Production-grade with validation, examples |
| 1.0.0 | 2024-12 | Initial release |
| 版本 | 日期 | 变更 |
|---|---|---|
| 2.0.0 | 2025-01 | 生产级版本,包含验证、示例 |
| 1.0.0 | 2024-12 | 初始版本 |