mcpField
B
blockchain-basics

blockchain-basics

github.com/pluginagentmarketplace开发154 次安装42 周前更新
代码仓库

关于 blockchain-basics

面向开发者的区块链基础学习技能,涵盖共识、密码学、网络架构和交易生命周期,并配有代码示例、故障排查及分阶段学习路径。

主要功能

  1. 01共识机制与最终性
  2. 02密码学原语与 Merkle 证明
  3. 03P2P 网络与节点类型
  4. 04交易生命周期与内存池
  5. 05代码示例与故障排查
  6. 06循序渐进的学习路径

适用场景

  1. 01学习 PoW、PoS 和 BFT 概念
  2. 02练习验证 Merkle 证明
  3. 03跟踪交易从内存池到确认的过程

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/pluginagentmarketplace/custom-plugin-blockchain --skill blockchain-basics

安装后在 Claude Code 中输入/blockchain-basics确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/
config.yaml
schema.json
references/
GUIDE.md
PATTERNS.md
scripts/
validate.py

详细介绍

区块链基础技能

掌握区块链基础知识,包括共识机制、密码学原语和分布式系统架构。

快速开始

# Invoke this skill for blockchain fundamentals
Skill("blockchain-basics", topic="consensus", depth="intermediate")

涵盖主题

1. 共识机制

了解分布式网络如何达成一致:

  • 工作量证明:挖矿、算力、难度调整
  • 权益证明:验证者、罚没、最终性
  • 拜占庭容错:领导者选举、视图变更
2. 密码学基础

了解安全原语:

  • 哈希函数:SHA-256、Keccak-256、特性
  • 数字签名:ECDSA、Ed25519、验证
  • Merkle 树:证明构建、验证
3. 网络架构

探索分布式系统:

  • P2P 网络:Gossip 协议、节点发现
  • 节点类型:全节点、轻客户端、归档节点
  • 区块传播:紧凑区块、中继网络
4. 交易生命周期

跟踪数据在链上的流转:

  • 交易结构:输入、输出、签名
  • 内存池:手续费市场、排序、优先级
  • 确认:最终性、重组

代码示例

验证 Merkle 证明
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
计算区块哈希
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]

常见陷阱

陷阱问题解决方案
对最终性的误解PoW 具有概率性等待 6 次以上确认
混淆哈希与加密哈希是单向的使用适当的加密方式保护机密
信任时间戳矿工可以操纵时间戳使用区块高度以获得精确值

故障排除

“为什么我的交易还未确认?”
  1. 检查交易手续费与当前内存池的情况
  2. 确认 nonce 连续(没有间隔)
  3. 确保余额足以支付金额和 gas
“如何验证签名?”
from eth_account import Account
from eth_account.messages import encode_defunct

message = encode_defunct(text="Hello")
address = Account.recover_message(message, signature=sig)

学习路径

[Beginner] → Hash Functions → Digital Signatures → Transactions
    ↓
[Intermediate] → Merkle Trees → Consensus → Network Layer
    ↓
[Advanced] → BFT Protocols → Sharding → Cross-chain

自我测试

# 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)

交叉引用

  • 绑定的 Agent:01-blockchain-fundamentals
  • 相关技能:ethereum-development、smart-contract-security

版本历史

版本日期变更
2.0.02025-01生产级版本,包含验证和示例
1.0.02024-12初始版本

评论

支持 Markdown