区块链中的哈希
通过哈希实现不可篡改
区块链中的哈希 是 CoddyKit 上的免费 Web3 & DApp Development Fundamentals 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web3 & DApp Development Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What Is a Hash Function?
A hash function takes any input and produces a fixed-size output called a digest or hash.
Blockchains rely on cryptographic hash functions like SHA-256 (Bitcoin) and Keccak-256 (Ethereum).
sha256("hello") =
2cf24dba5fb0a30e26e83b2ac5b9e29e
1b161e5c1fa7425e73043362938b9824Deterministic Output
Hashing is deterministic: the same input always yields the same output.
This lets any node independently verify a hash and arrive at the identical result — essential for distributed agreement.
The Avalanche Effect
A tiny change in the input produces a completely different hash. This is the avalanche effect.
Notice how changing one letter changes the entire digest:
sha256("blockchain") -> ef7797e13d3a...
sha256("Blockchain") -> 3f1d8b9c2a04...
(totally different)Fixed Output Size
No matter how large the input, the output is always the same length. SHA-256 always returns 256 bits (64 hex characters).
This makes hashes convenient, compact identifiers for blocks, transactions, and state.
Preimage Resistance
A good hash function is one-way: given a hash, you cannot feasibly find the input that produced it.
This preimage resistance is why hashes can safely commit to data without revealing it.
Collision Resistance
Collision resistance means it is infeasible to find two different inputs with the same hash.
If collisions were easy, an attacker could swap one block or transaction for another that shares the same hash — destroying the chain's integrity.
Hashes Create the Chain Link
Recall that each block stores the hash of the previous block. Because hashing is deterministic and collision-resistant, this link is secure.
Altering an old block changes its hash, breaking the chain at that point.
block.hash = keccak256(
block.previousHash +
block.merkleRoot +
block.timestamp +
block.nonce
)Immutability Through Hashing
Immutability emerges from chained hashes. To change block 100, you must recompute block 100's hash, then 101, 102, and every block after it.
In a proof-of-work chain, that also means redoing all of their mining — practically impossible.
Hash Pointers
A hash pointer is a reference to data plus the hash of that data. If the data is tampered with, the stored hash no longer matches.
Blockchains are essentially linked lists built from hash pointers.
struct HashPointer {
location: address-of-block
hash: expected-hash-of-block
}Addresses and Hashing
Hashing also generates account addresses. An Ethereum address is derived by hashing the public key with Keccak-256 and keeping the last 20 bytes.
So hashing is woven through identity as well as integrity.
address = last20bytes(
keccak256(publicKey)
)Putting It Together
Cryptographic hashing gives blockchains their core guarantees: deterministic verification, tamper-evidence, compact identifiers, and immutability.
Every block link, Merkle root, and address depends on it.
Quick Check
Test your hashing knowledge.
Recap: Hashing in Blockchain
You learned that:
- Hash functions are deterministic and produce fixed-size output
- The avalanche effect means tiny changes alter the whole hash
- Preimage and collision resistance secure the chain
- Chained hashes create immutability
Next: how this data is shared across a distributed ledger.
用 AI 导师学习 Web3 & DApp Development Fundamentals — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 29
- 课程
- 105
常见问题解答
「区块链中的哈希」课时是免费的吗?
是的 — 「区块链中的哈希」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web3 & DApp Development Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。
「区块链中的哈希」这节课中我会学到什么?
通过哈希实现不可篡改 你通过在浏览器中直接运行的动手代码来练习 Web3 & DApp Development Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Web3 & DApp Development Fundamentals 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Web3 & DApp Development Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。
「区块链中的哈希」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Web3 & DApp Development Fundamentals 课中编写并运行代码吗?
能。每节 Web3 & DApp Development Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。