Blockchain Basics Skill
Master blockchain fundamentals including consensus mechanisms, cryptographic primitives, and distributed systems architecture.
Quick Start
# Invoke this skill for blockchain fundamentals
Skill("blockchain-basics", topic="consensus", depth="intermediate")
Topics Covered
1. Consensus Mechanisms
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
2. Cryptographic Foundations
Understand the security primitives:
- Hash Functions: SHA-256, Keccak-256, properties
- Digital Signatures: ECDSA, Ed25519, verification
- Merkle Trees: Proof construction, verification
3. Network Architecture
Explore distributed systems:
- P2P Networks: Gossip protocols, peer discovery
- Node Types: Full nodes, light clients, archives
- Block Propagation: Compact blocks, relay networks
4. Transaction Lifecycle
Follow data through the chain:
- Transaction Structure: Inputs, outputs, signatures
- Mempool: Fee markets, ordering, priority
- Confirmation: Finality, reorganization
Code Examples
Verify Merkle Proof
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
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 |
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
"How do I verify a signature?"
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
Test Yourself
# 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)
Cross-References
- Bonded Agent:
01-blockchain-fundamentals
- Related Skills:
ethereum-development, smart-contract-security
Version History
| Version |
Date |
Changes |
| 2.0.0 |
2025-01 |
Production-grade with validation, examples |
| 1.0.0 |
2024-12 |
Initial release |
1---
2name: blockchain-basics
3description: Master blockchain fundamentals including consensus, cryptography, and distributed systems
4sasmp_version: "1.3.0"
5version: "2.0.0"
6updated: "2025-01"
7bonded_agent: 01-blockchain-fundamentals
8bond_type: PRIMARY_BOND
9
10# Skill Configuration
11atomic: true
12single_responsibility: blockchain_education
13
14# Parameter Validation
15parameters:
16 topic:
17 type: string
18 required: true
19 enum: [consensus, cryptography, networks, transactions, blocks]
20 depth:
21 type: string
22 default: intermediate
23 enum: [basic, intermediate, advanced, expert]
24
25# Retry & Error Handling
26retry_config:
27 max_attempts: 3
28 backoff: exponential
29 initial_delay_ms: 1000
30
31# Logging & Observability
32logging:
33 level: info
34 include_timestamps: true
35 track_usage: true
36metadata:
37 source: https://skillmd.com/skills/aibot88/blockchain-basics
38---
39
40# Blockchain Basics Skill
41
42> Master blockchain fundamentals including consensus mechanisms, cryptographic primitives, and distributed systems architecture.
43
44## Quick Start
45
46```python
47# Invoke this skill for blockchain fundamentals
48Skill("blockchain-basics", topic="consensus", depth="intermediate")
49```
50
51## Topics Covered
52
53### 1. Consensus Mechanisms
54Learn how distributed networks achieve agreement:
55- **Proof of Work**: Mining, hashrate, difficulty adjustment
56- **Proof of Stake**: Validators, slashing, finality
57- **Byzantine Fault Tolerance**: Leader election, view changes
58
59### 2. Cryptographic Foundations
60Understand the security primitives:
61- **Hash Functions**: SHA-256, Keccak-256, properties
62- **Digital Signatures**: ECDSA, Ed25519, verification
63- **Merkle Trees**: Proof construction, verification
64
65### 3. Network Architecture
66Explore distributed systems:
67- **P2P Networks**: Gossip protocols, peer discovery
68- **Node Types**: Full nodes, light clients, archives
69- **Block Propagation**: Compact blocks, relay networks
70
71### 4. Transaction Lifecycle
72Follow data through the chain:
73- **Transaction Structure**: Inputs, outputs, signatures
74- **Mempool**: Fee markets, ordering, priority
75- **Confirmation**: Finality, reorganization
76
77## Code Examples
78
79### Verify Merkle Proof
80```python
81import hashlib
82
83def verify_merkle_proof(leaf: bytes, proof: list, root: bytes) -> bool:
84 """Verify a Merkle proof for inclusion"""
85 current = leaf
86 for sibling, is_left in proof:
87 if is_left:
88 current = hashlib.sha256(sibling + current).digest()
89 else:
90 current = hashlib.sha256(current + sibling).digest()
91 return current == root
92```
93
94### Calculate Block Hash
95```python
96import hashlib
97import struct
98
99def calculate_block_hash(header: dict) -> bytes:
100 """Calculate Bitcoin-style block hash"""
101 data = struct.pack(
102 '<I32s32sIII',
103 header['version'],
104 bytes.fromhex(header['prev_block']),
105 bytes.fromhex(header['merkle_root']),
106 header['timestamp'],
107 header['bits'],
108 header['nonce']
109 )
110 return hashlib.sha256(hashlib.sha256(data).digest()).digest()[::-1]
111```
112
113## Common Pitfalls
114
115| Pitfall | Issue | Solution |
116|---------|-------|----------|
117| Finality confusion | PoW is probabilistic | Wait for 6+ confirmations |
118| Hash vs encryption | Hashes are one-way | Use proper encryption for secrets |
119| Timestamp trust | Miners can manipulate | Use block height for precision |
120
121## Troubleshooting
122
123### "Why is my transaction not confirming?"
1241. Check transaction fee vs current mempool
1252. Verify nonce is sequential (no gaps)
1263. Ensure sufficient balance for amount + gas
127
128### "How do I verify a signature?"
129```python
130from eth_account import Account
131from eth_account.messages import encode_defunct
132
133message = encode_defunct(text="Hello")
134address = Account.recover_message(message, signature=sig)
135```
136
137## Learning Path
138
139```
140[Beginner] → Hash Functions → Digital Signatures → Transactions
141 ↓
142[Intermediate] → Merkle Trees → Consensus → Network Layer
143 ↓
144[Advanced] → BFT Protocols → Sharding → Cross-chain
145```
146
147## Test Yourself
148
149```python
150# Unit test template
151def test_merkle_root():
152 txs = [b"tx1", b"tx2", b"tx3", b"tx4"]
153 root = build_merkle_root(txs)
154 assert len(root) == 32
155 assert verify_merkle_proof(txs[0], get_proof(0), root)
156```
157
158## Cross-References
159
160- **Bonded Agent**: `01-blockchain-fundamentals`
161- **Related Skills**: `ethereum-development`, `smart-contract-security`
162
163## Version History
164
165| Version | Date | Changes |
166|---------|------|---------|
167| 2.0.0 | 2025-01 | Production-grade with validation, examples |
168| 1.0.0 | 2024-12 | Initial release |