blockchain-basics

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Blockchain Basics Skill

区块链基础技能

Master blockchain fundamentals including consensus mechanisms, cryptographic primitives, and distributed systems architecture.
掌握区块链基础知识,包括共识机制、密码学原语和分布式系统架构。

Quick Start

快速开始

python
undefined
python
undefined

Invoke this skill for blockchain fundamentals

Invoke this skill for blockchain fundamentals

Skill("blockchain-basics", topic="consensus", depth="intermediate")
undefined
Skill("blockchain-basics", topic="consensus", depth="intermediate")
undefined

Topics 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 == root
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 == root

Calculate 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

常见误区

PitfallIssueSolution
Finality confusionPoW is probabilisticWait for 6+ confirmations
Hash vs encryptionHashes are one-wayUse proper encryption for secrets
Timestamp trustMiners can manipulateUse block height for precision
误区问题解决方案
最终性混淆PoW具有概率性等待6个以上确认
哈希与加密混淆哈希是单向的对机密信息使用适当的加密方式
时间戳信任问题矿工可以操纵时间戳使用区块高度确保精度

Troubleshooting

故障排除

"Why is my transaction not confirming?"

"为什么我的交易没有确认?"

  1. Check transaction fee vs current mempool
  2. Verify nonce is sequential (no gaps)
  3. Ensure sufficient balance for amount + gas
  1. 检查交易手续费与当前内存池情况
  2. 验证随机数(nonce)是连续的(无间隔)
  3. 确保余额足够支付交易金额+手续费

"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-chain

Test Yourself

自我测试

python
undefined
python
undefined

Unit 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)
undefined
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)
undefined

Cross-References

交叉引用

  • Bonded Agent:
    01-blockchain-fundamentals
  • Related Skills:
    ethereum-development
    ,
    smart-contract-security
  • Bonded Agent:
    01-blockchain-fundamentals
  • Related Skills:
    ethereum-development
    ,
    smart-contract-security

Version History

版本历史

VersionDateChanges
2.0.02025-01Production-grade with validation, examples
1.0.02024-12Initial release
版本日期变更
2.0.02025-01生产级版本,包含验证、示例
1.0.02024-12初始版本