Преглед изворни кода

spec: add missing merkle tree section

zero пре 2 година
родитељ
комит
059dd47523

+ 322 - 0
doc/src/assets/incremental-merkle-tree.svg

@@ -0,0 +1,322 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   width="196.43642mm"
+   height="78.213806mm"
+   viewBox="0 0 196.43642 78.213806"
+   version="1.1"
+   id="svg1"
+   xml:space="preserve"
+   inkscape:version="1.3.2 (091e20ef0f, 2023-11-25)"
+   sodipodi:docname="drawing.svg"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
+     id="namedview1"
+     pagecolor="#000000"
+     bordercolor="#000000"
+     borderopacity="0.25"
+     inkscape:showpageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     inkscape:deskcolor="#d1d1d1"
+     inkscape:document-units="mm"
+     showguides="false"
+     inkscape:zoom="2.6129421"
+     inkscape:cx="433.22812"
+     inkscape:cy="232.49654"
+     inkscape:window-width="3838"
+     inkscape:window-height="2158"
+     inkscape:window-x="0"
+     inkscape:window-y="0"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="layer1" /><defs
+     id="defs1"><marker
+       style="overflow:visible"
+       id="marker8"
+       refX="0"
+       refY="0"
+       orient="auto-start-reverse"
+       inkscape:stockid="Wide, heavy arrow"
+       markerWidth="1"
+       markerHeight="1"
+       viewBox="0 0 1 1"
+       inkscape:isstock="true"
+       inkscape:collect="always"
+       preserveAspectRatio="xMidYMid"><path
+         style="fill:context-stroke;fill-rule:evenodd;stroke:none"
+         d="m 1,0 -3,3 h -2 l 3,-3 -3,-3 h 2 z"
+         id="path8" /></marker><marker
+       style="overflow:visible"
+       id="marker6"
+       refX="0"
+       refY="0"
+       orient="auto-start-reverse"
+       inkscape:stockid="Wide, heavy arrow"
+       markerWidth="1"
+       markerHeight="1"
+       viewBox="0 0 1 1"
+       inkscape:isstock="true"
+       inkscape:collect="always"
+       preserveAspectRatio="xMidYMid"><path
+         style="fill:context-stroke;fill-rule:evenodd;stroke:none"
+         d="m 1,0 -3,3 h -2 l 3,-3 -3,-3 h 2 z"
+         id="path6" /></marker><marker
+       style="overflow:visible"
+       id="ArrowWideHeavy"
+       refX="0"
+       refY="0"
+       orient="auto-start-reverse"
+       inkscape:stockid="Wide, heavy arrow"
+       markerWidth="1"
+       markerHeight="1"
+       viewBox="0 0 1 1"
+       inkscape:isstock="true"
+       inkscape:collect="always"
+       preserveAspectRatio="xMidYMid"><path
+         style="fill:context-stroke;fill-rule:evenodd;stroke:none"
+         d="m 1,0 -3,3 h -2 l 3,-3 -3,-3 h 2 z"
+         id="path4" /></marker></defs><g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(-6.7407855,-68.507975)"><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1"
+       width="21.546761"
+       height="14.978389"
+       x="6.8730769"
+       y="131.6111" /><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="11.791407"
+       y="140.89558"
+       id="text1"><tspan
+         sodipodi:role="line"
+         id="tspan1"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="11.791407"
+         y="140.89558">coin1</tspan></text><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-7"
+       width="21.546761"
+       height="14.978389"
+       x="20.102242"
+       y="112.03194" /><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-7-0"
+       width="21.546761"
+       height="14.978389"
+       x="74.077248"
+       y="112.03194" /><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-7-0-9"
+       width="21.546761"
+       height="14.978389"
+       x="128.05228"
+       y="112.03194" /><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-7-1"
+       width="21.546761"
+       height="14.978389"
+       x="47.089745"
+       y="90.865265" /><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-7-1-9"
+       width="21.546761"
+       height="14.978389"
+       x="100.00642"
+       y="68.640266" /><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-7-1-6"
+       width="21.546761"
+       height="14.978389"
+       x="155.03979"
+       y="90.865265" /><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-3"
+       width="21.546761"
+       height="14.978389"
+       x="33.860577"
+       y="131.6111" /><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="38.778908"
+       y="140.89558"
+       id="text1-2"><tspan
+         sodipodi:role="line"
+         id="tspan1-0"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="38.778908"
+         y="140.89558">coin2</tspan></text><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-3-5"
+       width="21.546761"
+       height="14.978389"
+       x="60.318913"
+       y="131.6111" /><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="65.237244"
+       y="140.89558"
+       id="text1-2-2"><tspan
+         sodipodi:role="line"
+         id="tspan1-0-5"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="65.237244"
+         y="140.89558">coin3</tspan></text><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-3-5-0"
+       width="21.546761"
+       height="14.978389"
+       x="87.306412"
+       y="131.6111" /><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="92.224747"
+       y="140.89558"
+       id="text1-2-2-7"><tspan
+         sodipodi:role="line"
+         id="tspan1-0-5-8"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="92.224747"
+         y="140.89558">coin4</tspan></text><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-3-5-0-1"
+       width="21.546761"
+       height="14.978389"
+       x="114.29392"
+       y="131.6111" /><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="119.21225"
+       y="140.89558"
+       id="text1-2-2-7-4"><tspan
+         sodipodi:role="line"
+         id="tspan1-0-5-8-9"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="119.21225"
+         y="140.89558">coin5</tspan></text><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="105.77425"
+       y="77.732132"
+       id="text1-2-2-7-4-63"><tspan
+         sodipodi:role="line"
+         id="tspan1-0-5-8-9-1"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="105.77425"
+         y="77.732132">root</tspan></text><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-3-5-0-1-2"
+       width="21.546761"
+       height="14.978389"
+       x="141.28146"
+       y="131.6111" /><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="151.01767"
+       y="140.89558"
+       id="text1-2-2-7-4-6"><tspan
+         sodipodi:role="line"
+         id="tspan1-0-5-8-9-6"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="151.01767"
+         y="140.89558">?</tspan></text><rect
+       style="fill:#a099e3;fill-opacity:1;stroke:#ffffff;stroke-width:0.264583;stroke-opacity:1"
+       id="rect1-7-0-9-3"
+       width="21.546761"
+       height="14.978389"
+       x="181.49815"
+       y="112.03194" /><text
+       xml:space="preserve"
+       style="font-size:3.175px;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+       x="191.23436"
+       y="121.27444"
+       id="text1-2-2-7-4-6-0"><tspan
+         sodipodi:role="line"
+         id="tspan1-0-5-8-9-6-4"
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, ';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-dasharray:none;stroke-opacity:1"
+         x="191.23436"
+         y="121.27444">?</tspan></text><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#ArrowWideHeavy)"
+       d="m 22.706724,131.6111 3.108631,-4.60077"
+       id="path3"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-end="#rect1-7" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker6)"
+       d="m 39.371278,131.6111 -3.232977,-4.60077"
+       id="path5"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-end="#rect1-7" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 40.424343,112.03194 7.89006,-6.18829"
+       id="path7"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect1-7"
+       inkscape:connection-end="#rect1-7-1" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 76.354972,131.6111 3.232977,-4.60077"
+       id="path9"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-end="#rect1-7-0" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 93.019527,131.6111 -3.108632,-4.60077"
+       id="path10"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-end="#rect1-7-0" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 75.301906,112.03194 -7.89006,-6.18829"
+       id="path11"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect1-7-0"
+       inkscape:connection-end="#rect1-7-1" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 130.32998,131.6111 3.23299,-4.60077"
+       id="path12"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-end="#rect1-7-0-9" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 146.99457,131.6111 -3.10864,-4.60077"
+       id="path13"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect1-3-5-0-1-2"
+       inkscape:connection-end="#rect1-7-0-9" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 148.37438,112.03194 7.89007,-6.18829"
+       id="path14"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect1-7-0-9"
+       inkscape:connection-end="#rect1-7-1-6" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="m 182.91003,112.03194 -7.73536,-6.18829"
+       id="path15"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect1-7-0-9-3"
+       inkscape:connection-end="#rect1-7-1-6" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="M 68.636505,93.82964 100.00642,80.65428"
+       id="path16"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect1-7-1"
+       inkscape:connection-end="#rect1-7-1-9" /><path
+       style="fill:none;fill-rule:evenodd;stroke:#c7c7c7;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#marker8)"
+       d="M 155.03979,94.003675 121.55318,80.480245"
+       id="path17"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect1-7-1-6"
+       inkscape:connection-end="#rect1-7-1-9" /></g></svg>

+ 0 - 5
doc/src/spec/contract/dao/scheme.md

@@ -10,11 +10,6 @@ Let $\t{PedersenCommit}$ be defined as in the section [Homomorphic Pedersen Comm
 
 Let $\t{Params}_\t{DAO}, \t{Bulla}_\t{DAO}, \t{Params}_\t{Proposal}, \t{Bulla}_\t{Proposal}$ be defined as in [DAO Model](model.md).
 
-TODO: add merkle section to crypto-schemes with merklepos, merklepath,
-MerkleRoot
-
-TODO: rename slot to block_height
-
 ## Mint
 
 ### Function Params

+ 25 - 0
doc/src/spec/crypto-schemes.md

@@ -127,3 +127,28 @@ $$ \t{PedersenCommit}(v, b) = \t{Lift}ᵥ(v) G_V + b G_B $$
 
 This scheme is a computationally binding and perfectly hiding commitment scheme.
 
+## Incremental Merkle Tree
+
+![incremental merkle tree](../assets/incremental-merkle-tree.svg)
+
+Let $ℓᴹ = 32$ be the merkle depth.
+
+The incremental merkle tree is fixed depth of $ℓᴹ$ used to store $𝔽ₚ$ items.
+It is an append-only set for which items can be proved to be inside within
+ZK. The root value is a commitment to the entire tree.
+
+Denote combining two nodes to produce a parent by the operator
+$⊕ : 𝔽ₚ × 𝔽ₚ → 𝔽ₚ$. Denote by $⊕_b$ where $b ∈ ℤ₂$, the function which
+swaps both arguments before calling $⊕$, that is
+$$ ⊕_b(X₁, X₂) = \begin{cases}
+⊕(X₁, X₂) & \text{if } b = 0 \\
+⊕(X₁, X₂) & \text{if } b = 1 \\
+\end{cases} $$
+
+We correspondingly define the types
+$$ \t{MerklePos} = ℤ₂^{ℓᴹ} $$
+$$ \t{MerklePath} = 𝔽ₚ^{ℓᴹ} $$
+and a function to calculate the root given a leaf, its position and the path,
+$$ \t{MerkleRoot} : \t{MerklePos} × \t{MerklePath} × 𝔽ₚ → 𝔽ₚ $$
+$$ \t{MerkleRoot}(𝐩, \mathbf{Π}, ℬ ) = ⊕_{p_{ℓᴹ}}(…, ⊕_{p₂}(π₂, ⊕_{p₁}(π₁, ℬ ))…) $$
+

+ 2 - 0
doc/src/spec/notation.md

@@ -6,5 +6,7 @@ corresponding to `u64` in Rust of $[0, 2⁶⁴)$.
 $𝔹$ denotes a single byte $[0, 2⁸)$ corresponding to `u8` in Rust.
 We use $𝔹^*$ for an arbitrary sequence of bytes.
 
+$ℤ₂$ refers to binary bits.
+
 $\t{im}(f)$ denotes the image of a function $f$.