Coder Social home page Coder Social logo

Comments (4)

hackaugusto avatar hackaugusto commented on June 15, 2024

One possible design is to have the target position of the element on stack and the Merkle tree root:

Stack: [el_pos, tree_root ...]

And the decorator would push the leaf position to the advice stack.

The Advantage of the above is that a single decorator supports not only the first/last position, but also arbitrary values in-between. The disadvantage is that to get the position of the last element either the number of elements must be known, or a magic value needs to be used.

from miden-vm.

bobbinth avatar bobbinth commented on June 15, 2024

I'd probably go for the simpler approach for now as figuring out the correct position will be quite complicating, I think.

A couple things to clarify:

  • We probably want to return both the index and the depth as zero nodes could theoretically be located at different depths in different parts of the tree.
  • What should we return if there are no zero nodes in the tree?

from miden-vm.

hackaugusto avatar hackaugusto commented on June 15, 2024

correct position will be quite complicating, I think

It should be easy:

container.inner_nodes().filter(|n| n.is_leaf()).nth(index)

The complexity is basically O(n) where n is the number of leaves.

What should we return if there are no zero nodes in the tree?

Undefined? We can easily check if the tree is empty by looking at the root value.

from miden-vm.

bobbinth avatar bobbinth commented on June 15, 2024

It should be easy:

container.inner_nodes().filter(|n| n.is_leaf()).nth(index)

Not sure this will work as in the MerkleStore the order of nodes is not defined.

What should we return if there are no zero nodes in the tree?

Undefined? We can easily check if the tree is empty by looking at the root value.

Comparing against empty tree root in MASM would require comparing words. I think we we return a well-defined value for empty trees we can make it more efficient (i.e., need to compare only single element).

Assuming, this decorator puts (depth, index) on the top of advice stack, we could say that (0, 0) means that the tree is empty. Or maybe just returning depth=0 is good enough.

from miden-vm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.