Merkle Trees in Arrays

heap 8

Just like binary heaps!

From node i:

  • left child: $2 \ast i$
  • right child: $(2 \ast i)+1$
  • parent: $\lfloor i/2 \rfloor$

Array representation:

h(1‑8)h(1‑4)h(5‑8)h(1‑2)h(3‑4)h(5‑6)h(7‑8)h(1)h(2)h(3)h(4)h(5)h(6)h(7)h(8)
0123456789101112131415

Overview

Execution of the P2PKH Script

 

Stack
stack animation stack animation stack animation stack animation stack animation stack animation stack animation
Script
 
<sig>
<pubKey>
OP_DUP
OP_HASH160
<pubKeyHash>
OP_EQUALVERIFY
OP_CHECKSIG

As the top of the stack has true at the end, the script is verified and the transaction is valid

OP_CHECKMULTISIG Example

If the current key matches the current signature, advance both; otherwise, only advance the key index

(reference)

  • Initial state of the stack with indices
  • Does ikey match isig?
    • If so, advance both indices
  • Back to start...
  • If ikey does not match isig...
    • Only advance ikey
  • Pushes true (1) if all signatures match a public key
    • One possible successful end (assuming pubKey2 matches sig1)
    • Another possible successful end (assuming pubKey1 matches sig1)