# Hello --- # I'm Jakub Trąd --- # How are # Merkle Trees? --- ## What's in this presentation? ---- ## 1. A small & visual theoretical introduction ---- ## 2. Semi-live coding implementation session ---- ## What's in it for you? --- # What is a # Merkle Tree ---- ![](https://hackmd.io/_uploads/r1_kNvY-T.png) ---- ![](https://hackmd.io/_uploads/rJkbVDtWa.png) ---- ![](https://hackmd.io/_uploads/B1hfEDtWT.png) ---- ![](https://hackmd.io/_uploads/rkL4EDt-p.png) ---- ![](https://hackmd.io/_uploads/BJmLVPYWT.png) --- ### Applications of Merkle Trees 1. Blockchain 2. Smart contracts 3. Consistency verification (DynamoDB) 4. Efficient delta calculation (git) --- I just think they're cool! --- ### How is that different from just concatenating and hashing everything together? --- # Inclusion Proofs ---- ![](https://hackmd.io/_uploads/Sy7towtWp.png) ---- ![](https://hackmd.io/_uploads/H199sPt-T.png) ---- ![](https://hackmd.io/_uploads/ByVx3DtbT.png) ---- ![](https://hackmd.io/_uploads/rJuWnPFW6.png) ---- ![](https://hackmd.io/_uploads/BkDG2PFb6.png) ---- # Merkle Proof ![](https://hackmd.io/_uploads/SkN7nDY-T.png) --- # Efficient updates! ---- ![](https://hackmd.io/_uploads/BykD6_F-p.png) ---- ![](https://hackmd.io/_uploads/rJE_TdYZT.png) ---- ![](https://hackmd.io/_uploads/rJpYpdYb6.png) ---- ![](https://hackmd.io/_uploads/BJ1sp_Y-p.png) --- # Ok, but how efficient? ## Let's talk numbers! ---- # Depth & logarithms ---- ## Let's measure the tree ![](https://hackmd.io/_uploads/SJWebyjWa.png) ---- ## $\text{depth} = 0$ ![](https://hackmd.io/_uploads/SkZjxJo-6.png) ## $n_{\text{leaves}} = 1$ ## $n_{\text{nodes}} = 1$ ---- ## $\text{depth} = 1$ ![](https://hackmd.io/_uploads/BkXnxyjZ6.png) ## $n_{leaves} = 2$ ## $n_{nodes} = 3$ ---- ## $\text{depth} = 2$ ![](https://hackmd.io/_uploads/Sk3TlJoWp.png) ## $n_{leaves} = 4 \text{ } n_{nodes} = 7$ ---- ## $n_{\text{leaves}} = 2^{\text{depth}}$ ## $n_{\text{nodes}} = 2^{(\text{depth} + 1)} - 1$ --- ## How efficient is an update? ![](https://hackmd.io/_uploads/BJ1sp_Y-p.png) ---- ## We only need to update ## $n = depth + 1$ nodes ---- ## Let's take a tree of depth 20 ---- ## $n_{\text{leaves}} = 2^{\text{depth}} = 524288$ ## $n_{\text{nodes}} = 2^{\text{depth} + 1} - 1 = 2097151$ ---- # $21$ ---- ## $O(\log_2(n))$ --- ### How efficient is an inclusion proof? ---- # Merkle Proof ![](https://hackmd.io/_uploads/SkN7nDY-T.png) ---- ## $O(\log_2(n))$ --- # Implementation ---- ## Memory layout ---- ![](https://hackmd.io/_uploads/SyLUE1jZa.png) ---- ![](https://hackmd.io/_uploads/HkzO4kiWa.png) ---- ![](https://hackmd.io/_uploads/B1BbPJjb6.png) ---- ![](https://hackmd.io/_uploads/H1gxVvJiZT.png) ---- ![](https://hackmd.io/_uploads/ry7Hv0j-6.png) --- ## Index Calculus ---- ## Index of parent? ---- ![](https://hackmd.io/_uploads/ry7Hv0j-6.png) ---- ## $i_{p} = \frac{i}{2}$ ---- ## Index of sibling? ---- ![](https://hackmd.io/_uploads/ry7Hv0j-6.png) ---- ### $i_s = \begin{cases} i + 1,& \text{if } x \mod 2 = 0 \\ i - 1, & \text{otherwise} \end{cases}$ ---- ## Depth at index? ---- ![](https://hackmd.io/_uploads/ry7Hv0j-6.png) ---- ![](https://hackmd.io/_uploads/SJE9bhT-T.png) ---- ## Depth at index? ### $d = \log_2(i)$ ---- ## Won't somebody please ## think of the children?!? ---- ![](https://hackmd.io/_uploads/ry7Hv0j-6.png) ---- ## Index of left child ## $i_{l} = 2n$ ## Index of right child ## $i_{l} = 2n +1$ --- # Coding time! --- ![](https://hackmd.io/_uploads/rJ12_h6Zp.png) --- ![](https://hackmd.io/_uploads/rJ31F3ab6.png) --- ![](https://hackmd.io/_uploads/HJamF2pZT.png) --- For a tree of depth 20, we have $n_{\text{nodes}} = 2^{21} = 2097152$ $n_{\text{leaves}} = 2^{20} = 1048576$ And $1048576$ hashes! --- Or do we? --- We're hiring*** --- `~fin~`
{"title":"Merkle Trees","description":"Something here","contributors":"[{\"id\":\"d4015b97-02fa-4f6f-8da5-643ad4011396\",\"add\":5459,\"del\":1537}]"}
    126 views