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: store ciphernode in an incremental merkle tree #44

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

auryn-macmillan
Copy link
Member

@auryn-macmillan auryn-macmillan commented Sep 5, 2024

This PR:

  1. adds some additional parameters to the CiphernodeAdded() and CiphernodeRemoved() events, to make it simpler for the node software to track the current state of the registry.
  2. accumulates registered ciphernodes in an incremental merkle tree to efficiently enable some proving and sorition methods.

Summary by CodeRabbit

  • New Features

    • Enhanced events for added and removed ciphernodes, now providing additional context such as index, number of nodes, and size of the registry.
    • Introduced a new public function to check if a ciphernode exists within the registry.
    • Updated methods for adding and removing ciphernodes to improve dynamic management.
  • Bug Fixes

    • Removed redundant tracking mechanism for ciphernode status, streamlining management functions.

Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Walkthrough

The updates to the ICiphernodeRegistry interface and the CiphernodeRegistryOwnable contract involve significant modifications to event emissions and function definitions. The events now include additional parameters for better context, while the contract has introduced a new structure for managing ciphernodes, removed the previous isEnabled mapping, and updated functions to enhance management and clarity.

Changes

File Path Change Summary
packages/evm/contracts/interfaces/ICiphernodeRegistry.sol Expanded CiphernodeAdded and CiphernodeRemoved events to include index, numNodes, and size parameters.
packages/evm/contracts/registry/CiphernodeRegistryOwnable.sol Removed isEnabled mapping, introduced LeanIMTData structure, updated addCiphernode and removeCiphernode functions with new parameters, and replaced eligibility check with isEnabled function.

Sequence Diagram(s)

sequenceDiagram
    participant Owner
    participant CiphernodeRegistry
    participant LeanIMTData

    Owner->>CiphernodeRegistry: addCiphernode(node)
    CiphernodeRegistry->>LeanIMTData: insert(node)
    LeanIMTData-->>CiphernodeRegistry: success
    CiphernodeRegistry-->>Owner: emit CiphernodeAdded(node, index, numNodes, size)

    Owner->>CiphernodeRegistry: removeCiphernode(node, siblingNodes)
    CiphernodeRegistry->>LeanIMTData: remove(node, siblingNodes)
    LeanIMTData-->>CiphernodeRegistry: success
    CiphernodeRegistry-->>Owner: emit CiphernodeRemoved(node, index, numNodes, size)
Loading

Poem

🐰 In the meadow where ciphernodes play,
A new structure blooms, brightening the day.
With events that now tell more than before,
We hop with delight, oh, what fun's in store!
So gather 'round, friends, let’s cheer and rejoice,
For changes have come, and we all have a voice! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2104514 and 6305380.

Files selected for processing (2)
  • packages/evm/contracts/interfaces/ICiphernodeRegistry.sol (1 hunks)
  • packages/evm/contracts/registry/CiphernodeRegistryOwnable.sol (4 hunks)
Additional comments not posted (6)
packages/evm/contracts/registry/CiphernodeRegistryOwnable.sol (6)

9-13: Refactor: Import and use of new libraries.

The new libraries InternalLeanIMT, LeanIMTData, and PoseidonT3 are imported and used to manage the cipher nodes with an incremental Merkle tree. This change aligns with the PR objectives to enhance node management efficiency.


16-16: Best Practice: Use of library functions on data types.

The using statement for InternalLeanIMT on LeanIMTData is a good practice in Solidity, enabling more readable and maintainable code by attaching library functions directly to the data type.


117-125: Enhancement: Updated addCiphernode function.

The function now converts the node address to a uint256 and uses the _insert method from InternalLeanIMT to manage the cipher nodes. This is a significant improvement over the previous boolean tracking mechanism, enhancing both performance and scalability.


128-142: Refactor: Updated removeCiphernode function.

This function now accepts an additional parameter siblingNodes which is necessary for the removal process in the incremental Merkle tree. The function also correctly updates the numCiphernodes counter and emits detailed events about the state changes, which improves transparency and traceability.


146-146: Refactor: Renamed function to isEnabled.

The function isCiphernodeEligible has been renamed to isEnabled to better reflect its functionality, which checks if a node is enabled in the ciphernodes structure. This change improves clarity and consistency in the codebase.


162-164: Enhancement: Implementation of isEnabled function.

This new function provides a public interface to check if a ciphernode is present in the Merkle tree, using the _has method from InternalLeanIMT. This is a straightforward and efficient way to check node status, aligning with the PR's goal to enhance node management.

Comment on lines +25 to +34
/// @param node Address of the ciphernode.
/// @param index Index of the ciphernode in the registry.
/// @param numNodes Number of ciphernodes in the registry.
/// @param size Size of the registry.
event CiphernodeAdded(
address indexed node,
uint256 index,
uint256 numNodes,
uint256 size
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhanced event parameters for CiphernodeAdded.

The addition of index, numNodes, and size parameters to the CiphernodeAdded event is a positive change that aligns with the PR objectives of enhancing node management. These parameters provide valuable context about the registry's state when a node is added, which can be crucial for listeners tracking changes.

Suggestion: Improve parameter documentation.
While the parameters are well-named, adding a brief description in the comments for each parameter could improve clarity and developer experience.

Comment on lines +37 to +46
/// @param node Address of the ciphernode.
/// @param index Index of the ciphernode in the registry.
/// @param numNodes Number of ciphernodes in the registry.
/// @param size Size of the registry.
event CiphernodeRemoved(
address indexed node,
uint256 index,
uint256 numNodes,
uint256 size
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhanced event parameters for CiphernodeRemoved.

The addition of index, numNodes, and size parameters to the CiphernodeRemoved event mirrors the changes made to the CiphernodeAdded event, maintaining consistency and enhancing the utility of these events. This change allows listeners to better understand the impact of a node's removal on the registry.

Suggestion: Improve parameter documentation.
As with the CiphernodeAdded event, enhancing the documentation for these new parameters would further improve clarity and usability.

@auryn-macmillan auryn-macmillan mentioned this pull request Sep 5, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6305380 and 01a7b6b.

Files selected for processing (1)
  • packages/evm/contracts/registry/CiphernodeRegistryOwnable.sol (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/evm/contracts/registry/CiphernodeRegistryOwnable.sol

@auryn-macmillan auryn-macmillan merged commit 5a27c0e into main Sep 5, 2024
1 check failed
@auryn-macmillan auryn-macmillan deleted the auryn/ciphernode-merkle-tree branch September 5, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant