Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement incremental merkle tree #9

Closed

Conversation

YashBit
Copy link
Contributor

@YashBit YashBit commented Jul 31, 2024

Important:

  1. Creating a simple PR for just a feedback loop, code not ready yet. Will update the description, etc when I have made all the commits.
  2. Want to check if I am on the correct path and implementing all the necessary components.

Description

@YashBit
Copy link
Contributor Author

YashBit commented Jul 31, 2024

@cedoor I have created a DynamicCalculator trait which will works the same way but with the depth as a parameter now. This basically controls the loop.

In -> packages/merkle-trees/src/incremental_merkle/tree.nr

Questions:

  1. Please let me know if this is the correct direction of implementation with a simple new modified trait that I have completed.

  2. After which I will focus on the MembershipProver, etc methods. Then write the Poseidon Hash tests.

For the tests, how would you like me to test the dynamic depth function? So I should create a tree (let's say of depth 4), and then calculate the results for depth 1, 2, 3?

@cedoor cedoor added the feature 🚀 This is enhancing something existing or creating something new label Aug 5, 2024
Copy link
Member

@cedoor cedoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YashBit there's code which is not related to this PR (e.g. ecdh). I think you need to open a PR for the binary merkle tree by forking the main branch of zk-kit.noir.

packages/merkle-trees/src/incremental_merkle.nr Outdated Show resolved Hide resolved
packages/merkle-trees/src/lib.nr Outdated Show resolved Hide resolved
@cedoor
Copy link
Member

cedoor commented Aug 9, 2024

@YashBit

  1. Please let me know if this is the correct direction of implementation with a simple new modified trait that I have completed.

The trait seems to be fine, I added other comments for some files that are actually just a copy of the current Merkle tree. You should be able to re-use that code.

  1. After which I will focus on the MembershipProver, etc methods. Then write the Poseidon Hash tests.

Yes, those functions still need to be implemented I guess.

For the tests, how would you like me to test the dynamic depth function? So I should create a tree (let's say of depth 4), and then calculate the results for depth 1, 2, 3?

Exactly, sounds like a good way to test them. Please, take a look at these tests here: https://github.com/privacy-scaling-explorations/zk-kit.circom/blob/326cef9fdb9a2f845b890cffea0594975768be1f/packages/binary-merkle-root/tests/binary-merkle-root.test.ts#L98. You should have the same tests in Noir here.

Also, be aware that this is not an incremental Merkle tree. It works as a general binary Merkle tree with an addition feature: dynamic depth, i.e. the ability to generate a proof with an arbitrary depth even if there's a maximum depth in the circuit (which must be static by design).

s

re s
@signorecello signorecello marked this pull request as draft August 12, 2024 10:13
@signorecello
Copy link
Collaborator

Converting to draft while not ready to merge

refactor: test1 works for incremental
package.json Show resolved Hide resolved
@YashBit
Copy link
Contributor Author

YashBit commented Aug 26, 2024

@signorecello Please can you change this back from the draft? The core logic is complete, adding a few tests now.

@signorecello signorecello marked this pull request as ready for review August 26, 2024 15:27
@YashBit
Copy link
Contributor Author

YashBit commented Aug 26, 2024

@signorecello

Could you please comment on the algorithm? Most of it should remain the same, it is just the calculate_root_dynamic
function in now a new trait called DynamicCalculator which should be able to handle the depth function dynamically.

Thank you again.

@sripwoud
Copy link
Member

@YashBit CI is (style check ) is failing. Can you please address this issue? I think you should be familiar with that situation given what you've learnt by working on #8

@YashBit YashBit changed the title Incrementle merkle Tree (Dynamic Depth Feature for Binary Merkle Tree) feat: implement incremental merkle tree Aug 27, 2024
@YashBit YashBit requested a review from cedoor August 30, 2024 05:38
@YashBit YashBit requested a review from sripwoud August 30, 2024 05:38
Copy link
Member

@sripwoud sripwoud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YashBit I think you need to rebase your branch on main. This PR shows up changes related to eg mocha dependencies while you added these in #8 already.

And formatting CI check is still failing

@YashBit
Copy link
Contributor Author

YashBit commented Aug 30, 2024

@sripwoud I will make those changes.

I am mainly concerned with the logic of the incremental tree. That is the most important, since after that I will be done with unit the tests as well.

Copy link
Collaborator

@signorecello signorecello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @YashBit I don't understand the goal here. When you use this library in a circuit, you won't be able to pass anything other than an array into its main circuit.

I don't believe we should merge this PR without a bin circuit that would show its usage

@cedoor
Copy link
Member

cedoor commented Sep 2, 2024

@YashBit can we close this PR in favor of #16 ?

@YashBit
Copy link
Contributor Author

YashBit commented Sep 2, 2024

@cedoor Yes, please close this one!

@cedoor cedoor closed this Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🚀 This is enhancing something existing or creating something new
Projects
Status: ✔️ Done
Development

Successfully merging this pull request may close these issues.

4 participants