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

Registry Spec #2

Merged
merged 7 commits into from
Jun 27, 2024
Merged

Registry Spec #2

merged 7 commits into from
Jun 27, 2024

Conversation

auryn-macmillan
Copy link
Member

@auryn-macmillan auryn-macmillan commented Jun 7, 2024

This PR is a first attempt at specifying the interface for the cyphernode registry, along with its components. It incides mainly in the Committee Selection Pahse

Its main focus is the two-step asynchronous committee selection phase that utilizes a pluggable entity called IRegistryFilter.

Key Points

  • Committee Request: When a committee is requested, the registry signals the IRegistryFilter to initiate the selection of the committee.
  • Committee Publishing: Later, the filter reports back to the registry, publishing the sharedPublickKey and the list of nodes.
  • Time Limit: There is a specified time limit for the transition to occur. If the transition does not happen within this time frame, the process is declared stale and unfit to proceed to the activation stage.

Security Considerations

  • The registry provides each filter with a function to determine if a node is fit for inclusion. This allows the filter to implement its sortition function with minimal knowledge of protocol internals (e.g., slashing, availability, duties).
  • The registry is responsible for validating each node to be included in the committee. Only enabled and fit nodes are allowed. This extra validation is done inside the publish function. This step becomes necessary because we are for handling adding a filter as permissionless action

Implementation Considerations

  • The key generation process is treated as a black box. Currently, it is modeled as a centralized entity responsible for correctly generating and posting the key. Or in other words, some centralized actor will own a the IRegistryFilter contract used for the sortition.

Cyphernode State

  • This concerns staking, slashing, and outstanding duties per node.
  • It will be addressed in a subsequent branch, which will introduce the initial interface for the contract managing Cyphernode deposits.

Summary by CodeRabbit

  • New Features

    • Updated committee selection to use a single address filter instead of an array for more streamlined operations.
    • Introduced functionality to manage Cyphernode eligibility and public key publishing.
    • Added new event-driven capabilities for better monitoring and tracking of committee-related activities.
  • Bug Fixes

    • Simplified input validation process to ensure consistent data handling.
  • Tests

    • Enhanced test cases to reflect changes in request filtering and input publication mechanisms.

/// @param node Address of the node.
event NodeAdded(uint256 indexed nodeId, address indexed node);
/// @notice This event MUST be emitted when a filter is added to the registry.
event FilterAdded(address indexed filter);
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if additing filters is necessary?

Given that we talked about making this feature permissionless, it seems that the only real benefit here is that it might make it easier for applications/fontends to know and display available filters?

Copy link
Contributor

@cristovaoth cristovaoth Jun 7, 2024

Choose a reason for hiding this comment

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

Right. Yeah we should keep it permissionless. Explicitly adding and emitting the event feels right somehow. What you point out is one scenario scenario.

You have any concrete thoughts on whether include/remove?

bool eligible;
// Number of duties the node has not yet completed.
// Incremented each time a duty is added, decremented each time a duty is completed.
uint256 outstandingDuties;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a core component of the protocol that will dictate whether or not a node can currently be decomissioned.

This counter was my first attempt at solving for this, however it implies a lot of onchain state management, since it would need to be incremented/decemented for each node in each committee both when the committee is formed and when the committee's duties expire.

My guess is that there is a more storage efficient route to this, probably something like a nullifier proof to verify that a given node is not the list of nodes with currently active duties.

Copy link
Member Author

Choose a reason for hiding this comment

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

In either case though, I don't think this can live in the filter contracts. It probably needs to be a core feature of the registry.

Copy link
Contributor

Choose a reason for hiding this comment

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

Initially, I took this comment as a major flaw in the direction of this PR. However, upon revisiting it, I think this is only partially the case.

One thing is certain: the commissioning and decommissioning of nodes do not belong in the filter logic. There’s no question about that, you comment is correct.

However, the Registry already maintains a state indicating whether a Cyphernode is active. For the registry, the only important factor is whether a node can be included in a committee selection. It doesn’t matter whether the node hasn’t been added yet, is serving too many duties, or has been slashed and its bond no longer suffices.

So, the relevant question for the registry is whether a node is fit to be included in an upcoming commission. This is a simple boolean value.

What seems to be missing is a new entity to handle the logic for staking, entering commissions, leaving commissions with prizes, and leaving commissions with slashes.

I'm going to push a couple more commits and summarize the current status of the phase design in a consolidated PR comment. I'll try to incorporate this idea there.

Let me know if you have any immediate feedback on this

Copy link
Member Author

@auryn-macmillan auryn-macmillan Jun 13, 2024

Choose a reason for hiding this comment

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

So what you're suggesting here is essentially breaking the registry up into a multiple components, one that is the canonical source of truth for whether or not a given node is currently eligible to be selected for committee and one that is responsible for maintaining the list of eligible nodes (along with slashing conditions, etc)?

This seems reasonable to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

It appears to me that ICommitteeCoordinator is actually acting as the registry, which seems to be conflating the role of the registry and the filers.

The registry is a core component to the protocol. Global node membership is not something that should be defined by the requestor. Rather, requestors should be able to define the filters that they want to apply to the global registry.

Copy link
Member Author

Choose a reason for hiding this comment

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

Put another way, the ICyphernodeRegistry should handle node registration and decommissioning (currently permissioned by an owner address, in future permissionless via staking). Regardless of the filters applied, every node selected for a computation must be a member of the global list of eligible nodes to ensure that they are staked and the system maintains economic security.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is a good point, and it's what I meant when I mentioned in the DMs that I hadn't given any thought to the slashing logic and mechanism. Let me think it through

Copy link
Contributor

coderabbitai bot commented Jun 11, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

The changes introduce significant updates in the Enclave contract and related interfaces to refine the functionality around committee selection and input handling. Specifically, the request function now accepts a single address filter instead of an array, simplifying the logic. New functions and events were added in various interfaces to support these changes, and two new contracts (IRegistryFilter.sol and NaiveRegistryFilter.sol) were introduced to handle registry filters more effectively.

Changes

File/Path Change Summary
packages/evm/contracts/Enclave.sol Modified request function to accept a single address, updated related logic and event emissions, and added logic to accumulate inputs in publishInput.
packages/evm/contracts/interfaces/.../ICyphernodeRegistry.sol Updated event parameters, renamed and added functions, introduced new event CommitteePublished.
packages/evm/contracts/interfaces/IE3.sol Expanded E3 struct to include a new field bytes[] inputs.
packages/evm/contracts/interfaces/IEnclave.sol Updated parameter names and types in the E3Requested event and request function.
packages/evm/contracts/interfaces/IRegistryFilter.sol New interface defining requestCommittee function.
packages/evm/contracts/registry/CyphernodeRegistryOwnable.sol Restructured storage variables, introduced new mappings and error handling, added functionality for Cyphernode management.
packages/evm/contracts/registry/NaiveRegistryFilter.sol New contract implementing IRegistryFilter, managing committees, registry configuration and publishing committees.
packages/evm/contracts/test/MockCyphernodeRegistry.sol Updated function names and parameters, added new functions publishCommittee and isCyphernodeEligible.
packages/evm/contracts/test/MockInputValidator.sol Simplified input assignment by removing abi.decode.
packages/evm/contracts/test/MockRegistryFilter.sol New mock contract implementing IRegistryFilter, similar to NaiveRegistryFilter.
packages/evm/test/Enclave.spec.ts Updated tests to reflect changes, added new constants and replaced request.pool with request.filter.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Enclave
    participant CyphernodeRegistry
    participant RegistryFilter

    User ->> Enclave: request(filter, threshold, ...)
    Enclave ->> CyphernodeRegistry: requestCommittee(e3Id, filter, threshold)
    CyphernodeRegistry ->> RegistryFilter: requestCommittee(e3Id, threshold)
    RegistryFilter -->> CyphernodeRegistry: success or failure
    CyphernodeRegistry -->> Enclave: Emit CommitteeRequested
    Enclave -->> User: Emit E3Requested
    User ->> Enclave: publishInput(e3Id, input)
    Enclave -->> Enclave: Accumulate Inputs
Loading

Poem

In the world of code so bright,
The Enclave finds a way to light,
With single filter, pure and tight,
The committees form through day and night.
Cyphernodes now eligible, swift as a kite,
Smart contracts dance, with sheer delight.
Coding wonders in their flight. 🚀


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@auryn-macmillan auryn-macmillan marked this pull request as ready for review June 27, 2024 19:43
@auryn-macmillan auryn-macmillan merged commit cd44ea1 into main Jun 27, 2024
1 check failed
@auryn-macmillan auryn-macmillan deleted the committee-flow branch June 27, 2024 19:43
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.

2 participants