0Pricing
Web3 & DApp Development Fundamentals · درس

أشجار Merkle

تحقق فعّال

أشجار Merkle درس مجاني في Web3 & DApp Development Fundamentals على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web3 & DApp Development Fundamentals، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web3 & DApp Development Fundamentals 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

The Problem Merkle Trees Solve

A block may contain thousands of transactions. How can a lightweight device verify that one specific transaction is included without downloading them all?

The answer is the Merkle tree — a structure that lets you prove membership with just a handful of hashes.

What Is a Merkle Tree?

A Merkle tree (or hash tree) is a binary tree where:

  • Each leaf is the hash of one transaction
  • Each internal node is the hash of its two children combined
  • The single top node is the Merkle root

Building the Tree

Construction works bottom-up. Hash each transaction to form the leaves, then repeatedly hash pairs together until only one hash remains.

Leaves:  H(tx1) H(tx2) H(tx3) H(tx4)
Level 1: H(H(tx1)+H(tx2))  H(H(tx3)+H(tx4))
Root:    H(level1a + level1b)

The Merkle Root

The Merkle root is a single hash that represents every transaction in the block. It is stored in the block header.

If even one transaction changes, the root changes — so the root acts as a compact fingerprint of the entire transaction set.

Handling an Odd Number of Leaves

If a level has an odd number of nodes, the last node is usually duplicated so it can be paired.

This keeps the tree balanced and ensures every node has a sibling to hash with.

Leaves: H(tx1) H(tx2) H(tx3)
-> duplicate last: H(tx3) H(tx3)
Level 1: H(tx1+tx2)  H(tx3+tx3)

Merkle Proofs

A Merkle proof is the small set of sibling hashes needed to recompute the root from a single leaf.

To prove tx2 is included, you only need the siblings along its path — not the other transactions themselves.

Prove tx2 is in the block:
  provide H(tx1) and H(tx3+tx4)
  recompute: H( H(tx1)+H(tx2) )
  then:      H( that + H(tx3+tx4) )
  compare to stored Merkle root

Why Proofs Are Efficient

For N transactions, a Merkle proof needs only about log2(N) hashes.

For one million transactions, that is roughly 20 hashes instead of a million — a massive saving for light clients and mobile wallets.

Light Clients (SPV)

Simplified Payment Verification clients download only block headers, not full blocks.

Using a Merkle proof from a full node, an SPV client can confirm a transaction is in a block without trusting that node blindly.

Tamper Detection

Because every transaction feeds into the Merkle root, altering any transaction produces a different root.

The header's root would no longer match the recomputed root, so the tampering is immediately exposed.

Merkle Trees Beyond Transactions

Merkle trees are used far beyond transaction lists. Ethereum uses a variant called a Merkle Patricia Trie to commit to the entire world state and to receipts.

Git, IPFS, and many databases also rely on Merkle structures for integrity.

Putting It Together

The Merkle tree turns a large set of transactions into a single root hash while still allowing compact, verifiable membership proofs.

It is one of the most elegant data structures behind scalable, trustless verification.

Quick Check

Check your grasp of Merkle proofs.

Recap: Merkle Trees

You learned that:

  • A Merkle tree hashes transactions in pairs up to a single root
  • The Merkle root is a fingerprint stored in the header
  • A Merkle proof needs only ~log2(N) hashes
  • This enables efficient light clients and tamper detection

Next we dig into the hashing that powers all of this.

الأسئلة الشائعة

هل درس «أشجار Merkle» مجاني؟

نعم — نص درس «أشجار Merkle» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web3 & DApp Development Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Web3 & DApp Development Fundamentals 4 دروس في المجموع.

ماذا ستتعلم في «أشجار Merkle»؟

تحقق فعّال تتمرن على Web3 & DApp Development Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Web3 & DApp Development Fundamentals؟

لا تُشترط خبرة سابقة. Web3 & DApp Development Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «أشجار Merkle»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Web3 & DApp Development Fundamentals هذا؟

نعم. كل درس في Web3 & DApp Development Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الكتل والسلاسل
  2. أشجار Merkle
  3. التجزئة في Blockchain
  4. دفاتر الأستاذ الموزعة
← العودة إلى Web3 & DApp Development Fundamentals