A Merkle Tree is a dedication scheme that works equally to a Merkle Tree, however has a a lot smaller variety of witnesses. It really works by changing hashes in Merkle bushes with vector commits, which makes wider department elements extra environment friendly.

Due to Kevundre Wedderburn for responding to the put up.

Overview

For info on how varkl bushes work, see:


The aim of this put up is to elucidate the concrete format of draft work tree eip, It’s geared toward consumer builders who need to implement WorkTree and are in search of an introduction earlier than going deeper into EIP.

Verkle bushes introduce many modifications to the construction of the tree. An important modifications are:

  • the change from 20 byte keys to 32 byte keys (to not be confused with 32 byte addresses, that are a separate change);
  • tries to merge accounts and storage; And eventually
  • Introducing Workal Trie, which makes use of vector commits as a substitute of hashes.

As a vector dedication scheme for the work tree, we use Pedersen Commitments, Pedersen commitments are based mostly on elliptic curves. For an introduction to Pedersen commitments and the best way to use them as polynomial or vector commitments utilizing interior product arguments, see Right here,

the curve we’re utilizing is bandersnatch, This curve was chosen as a result of it’s performant, and in addition as a result of it can permit environment friendly SNARKs in BLS12_381 to purpose about varkl bushes sooner or later. This may be helpful for rollups in addition to permitting an improve the place as soon as sensible all witnesses will be compressed into one SNARK with out the necessity for any additional commit updates.

The form of the curve order/scalar area of Bandersnatch is p = 13108968793781547619861935127046491459309155893440570251786403306729687672801, which is a 253bit prime. Consequently, we are able to solely safely decide to bit strings of at most 252 bits, in any other case the sector overflows. We have now chosen a branching issue (width) of 256 for the work tree, which implies that every commit can commit as much as 256 values ​​(or to be exact, as much as an integer) of 252 bits. P – 1, we write it as commit(v₀, v₁, …, v₂₅₅) decide to record V Size 256 Km.

varkal tree format

One of many design targets of labor tree EIP is to make entry to neighboring areas (eg storage with practically equivalent addresses or neighboring code segments) low cost. To do that, a key consists of a Trunk 31 bytes and a suffix One byte for a complete of 32 bytes. The important thing scheme is designed such that “shut” storage areas are mapped onto the identical stem and a special suffix. for particulars please go to eip draft,

Work tree itself is made up of two sorts of nodes:

  • extension nodeswhich represents 256 values ​​with the identical root however totally different suffixes
  • inside nodesWhich has a most of 256 kids, which will be both different inside nodes or extension nodes.

A dedication to a element node is a dedication to a 4 factor vector; Remaining posts might be 0. it’s:

C₁ and C₂ are two further commits for all values ​​with the identical root Trunk, The explanation we’d like commits is that there are 32 bytes within the values, however we are able to solely retailer 252 bits per area factor. Thus a single commit wouldn’t be adequate to retailer 256 values. So as a substitute C₁ shops values ​​for the suffix 0 to 127, and C₂ shops values ​​from 128 to 255, the place the values ​​are break up in two to suit the sector measurement (We’ll come to that later.)

The extension with commits C₁ and C₂ is named an “extension-and-suffix tree” (abbreviated EaS).


determine 1 Illustration of strolling by means of a varchar tree for keys 0xfe0002abcd..ff04: the trail passes by means of 3 inside nodes with 256 kids (254, 0, 2), representing an growth node abcd..ff and two suffix tree commits, together with the worth 04, V4. notice that Trunk There are in reality the primary 31 bytes of the important thing, together with the trail by means of the inner nodes.

dedication to the values ​​of leaf nodes

Every extension and suffix tree node accommodates 256 values. Since a worth is 256 bits large, and we are able to safely retailer solely 252 bits in a single area factor, 4 bits can be misplaced if we merely tried to retailer a worth in a single area factor.

To keep away from this downside, we selected to separate the set of 256 values ​​into two units of 128 values. Every 32-byte worth within the group is split into two 16-byte values. So a worth vᵢ∈ ᵔ₃₂ is reworked into v⁽ˡᵒʷᵉʳ⁾ᵢ ∈ ᵖ₁₆ and v⁽ᵘᵖᵖᵉʳ⁾ᵢ∈ ᵔ₁₆ such that v⁽ˡᵒʷᵉʳ⁾ ᵢ++ v⁽ᵘᵖᵖᵉʳ⁾ᵢ= vᵢ.

A “leaf marker” is added to v⁽ˡᵒʷᵉʳ⁾ᵢ, to differentiate between a leaf that has by no means been accessed and a leaf that has been overwritten with 0s. no worth is ever faraway from the work tree, That is wanted for upcoming state termination plans. That marker is ready to the 129th bit, i.e. v⁽ˡᵒʷᵉʳ ᵐᵒᵈⁱᶠⁱᵉᵈ⁾ᵢ = v⁽ˡᵒʷᵉʳ⁾ᵢ + 2¹²⁸ if vᵢ has been accessed earlier than, and v⁽ˡᵒʷᵉʳ ᵐᵒᵈⁱᶠᵉⁱᵈ⁾ᵢ ​​= 0 if vᵢ has by no means been accessed. .

Then the 2 commitments C₁ and C₂ are outlined as

dedication of extension nodes

A dedication to an extension node is made up of an “extension marker”, which is solely the #1, two subtree commitments C₁ and C₂, and Trunk Keys resulting in this extension node.

In contrast to extension nodes in a Merkle–Patricia tree, which comprise solely the portion of the important thing that connects the father or mother inside node to a baby inside node, the stem covers your complete key as much as that time. It’s because varchar bushes are designed with stateless proofs in thoughts: if a brand new secret’s inserted that “splits” the extension in two, there is no such thing as a have to replace the outdated sibling, which Permits for a shorter proof.

dedication of inside nodes

Inside nodes have a easy enumeration methodology for his or her commitments: a node is considered as a vector of 256 values, which is the father or mother dedication (a area illustration) of every of its 256 subtrees. The commit for an empty subtree is 0. If the subtree will not be empty, then the commit for the inner node is

the place Cᵢ are the kids of the inner node, and 0 if any little one is empty.

tree insertion

Determine 2 is an instance of the method of inserting a brand new worth into the tree, which turns into attention-grabbing when the tree collides at a number of preliminary bytes.

Determine 2 The worth is inserted on the place v₁₉₂ 0000010000…0000 The one worth v₁₂₇ at place in a verticle tree is 0000000000…0000, As a result of the stems differ on the third byte, the 2 inside nodes are added as much as the totally different byte. Then one other “expansion-and-suffix” tree is inserted, containing the complete 31-byte stem. The beginning node is untouched, and the worth of C²₀ is identical as C⁰₀ earlier than the insertion.

Shallow Tree, Little Proof

The varkal tree construction produces shallower bushes, which reduces the quantity of information saved. Nonetheless, its actual energy comes from its capability to current little proof, ie witnesses. This might be defined within the subsequent article.

Recommended Posts