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/vip weight vote #38

Merged
merged 13 commits into from
Jun 4, 2024
Merged

Feat/vip weight vote #38

merged 13 commits into from
Jun 4, 2024

Conversation

ALPAC-4
Copy link
Contributor

@ALPAC-4 ALPAC-4 commented May 3, 2024

add vip weight vote contract

  • weight vote

    • submitter submit merkle root of voting powers every stage
    • user can vote for bridge weight with merkle root data
    • voting end timestamp = stage start timestamp + snapshot grace period + voting period
  • proposal

    • proposal vote use voting power of latest stage voting power.
    • quorum = latest stage's total tally * quorum ratio
    • proposal types
      • challenge
        • can make challenge vote if voting in progress or after snapshot grace period
        • if challenge execute, submitter will change to proposer
        • proposal can execute when totally tally is greater than quorum
        • voting end timestamp = execute timestamp + voting period
      • update params

Summary by CodeRabbit

  • New Features

    • Introduced a function to check bridge registration status.
    • Added functionalities for managing weight voting, including structures for votes, proposals, and events.
  • Refactor

    • Refactored the VIP weights update process to improve efficiency.

@ALPAC-4 ALPAC-4 requested a review from a team as a code owner May 3, 2024 06:22
Copy link

coderabbitai bot commented May 3, 2024

Walkthrough

The recent updates introduce new functionalities and optimizations to the initia_stdlib package. Specifically, the vip.move file now includes functions to check bridge registration status and to update VIP weights more efficiently. Additionally, a new module vip_weight_vote has been added to manage weight voting, incorporating structures, events, and functions to support these operations.

Changes

File Path Change Summary
.../initia_stdlib/sources/vip/vip.move Added is_registered and update_vip_weights_for_friend functions; refactored update_vip_weights.
.../initia_stdlib/sources/vip/weight_vote.move Introduced initia_std::vip_weight_vote module with structures, events, and functions for weight voting management.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant VIPModule as VIP Module
    participant WeightVoteModule as Weight Vote Module

    User->>+VIPModule: call is_registered(bridge_id)
    VIPModule-->>-User: returns bool

    User->>+VIPModule: call update_vip_weights(bridge_ids, weights)
    VIPModule->>+WeightVoteModule: call update_vip_weights_for_friend(bridge_ids, weights)
    WeightVoteModule-->>-VIPModule: updates weights
    VIPModule-->>-User: weights updated
Loading

Poem

In the land of code so bright,
VIPs now shine with might,
Bridges check their status clear,
Weight votes cast without fear.
Functions dance in modules new,
Bringing order, fresh and true.
CodeRabbit cheers, hip-hip-hooray,
For updates made this joyous day!


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.

Copy link

@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

Outside diff range and nitpick comments (1)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1)

179-206: Consider adding detailed documentation for the initialize function.

It would be beneficial for maintainability and clarity to include a detailed comment block at the beginning of the initialize function explaining its purpose, parameters, and any side effects.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fef22d7 and 700f84b.
Files selected for processing (1)
  • precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1 hunks)
Additional comments not posted (8)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (8)

679-690: Review the use of inline in remove_former_vote.

As previously commented by sh-cha, consider the necessity of using inline here given the potential performance implications.


292-293: Update tally decrement logic in vote.

As noted by sh-cha, ensure that total_tally is decremented when removing a former vote.


443-446: Use constants for vote options.

As suggested by sh-cha, replace magic numbers with constants VOTE_YES and VOTE_NO to improve code clarity.


784-787: Clarify the purpose of init_metadata.

As noted by sh-cha, consider renaming init_metadata to avoid confusion with 'initialize metadata'.


745-745: Define PROOF_LENGTH more clearly.

As suggested by sh-cha, ensure that PROOF_LENGTH is defined clearly and used consistently throughout the code.


697-699: Consider adding a stage or block height for the voting power hash.

As noted by JSHan94, it might be necessary to include a voting stage or block height in the voting power hash for better traceability and security.


462-462: Review the necessity of the loop in tally adjustment.

As pointed out by sh-cha, the loop might be unnecessary if len is always expected to be 1. Consider simplifying this logic.


90-90: Clarify the purpose of api_uri in WeightVote.

As queried by sh-cha, provide a clear explanation or documentation on the use of api_uri within the WeightVote struct.

Copy link

@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: 5

Outside diff range and nitpick comments (1)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1)

440-491: Consider using constants for VOTE_YES and VOTE_NO in vote_challenge_proposal.

Using constants can improve the readability and maintainability of your code by replacing magic numbers with meaningful names.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 700f84b and f067474.
Files selected for processing (1)
  • precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1 hunks)
Additional comments not posted (3)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (3)

182-209: Ensure proper error handling for the initialize function.

Verification successful

The error handling in the initialize function appears to be consistent with other functions in the codebase. The assert! statements in the initialize function use error codes and messages in a manner similar to other functions, ensuring proper error handling.

  • The initialize function uses assert! statements with specific error codes and messages, such as error::permission_denied(EUNAUTHORIZED) and error::already_exists(EMODULE_STORE_ALREADY_EXISTS).
  • This pattern is consistent with other functions in the codebase, which also use assert! statements with error codes and messages to handle errors.

Based on the gathered information, the error handling in the initialize function is consistent with the rest of the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the error handling in `initialize` is consistent with other functions.

# Test: Search for error handling patterns in other functions. Expect: Consistent usage of error codes and messages.
rg --type move $'assert!\\('

Length of output: 57



Script:

#!/bin/bash
# Description: Verify that the error handling in `initialize` is consistent with other functions.

# Test: Search for error handling patterns in other functions. Expect: Consistent usage of error codes and messages.
rg 'assert!\(' --glob '*.move'

Length of output: 234598


508-541: Ensure that the execute_proposal_internal function handles all edge cases correctly.

Verification successful

The search results show numerous assert! statements across various Move files, indicating that assertions are widely used for error handling and validation. However, to ensure that the execute_proposal_internal function specifically handles all edge cases correctly, we need to focus on the assertions and logic within this function itself.

Given the context, the execute_proposal_internal function already includes several assertions to handle different states and conditions. Here are the key assertions and checks within the function:

  1. Proposal Existence Check:

    assert!(table::contains(&module_store.proposals, key), error::not_found(EPROPOSAL_NOT_FOUND));
  2. Voting End Time or Quorum Check:

    assert!(
        proposal.voting_end_time < timestamp || total_tally >= proposal.quorum,
        error::invalid_state(EPROPOSAL_IN_PROGRESS),
    );
  3. Proposal Execution State Check:

    assert!(!proposal.is_executed, error::invalid_state(EPROPOSAL_ALREADY_EXECUTED));
  4. Quorum Not Met Handling:

    if (total_tally < proposal.quorum) {
        cosmos::fund_community_pool(&object_signer, uinit_metadata(), proposal.deposit_amount);
        proposal.is_executed = true;
        return false;
    }
  5. Proposal Rejection Handling:

    if (no_count > yes_count) {
        return false;
    }
  6. Challenge Execution:

    return challenge(proposal.stage, proposal.new_submitter, proposal.merkle_root, proposal.api_uri, proposal.snapshot_height);

These checks cover various edge cases such as:

  • Ensuring the proposal exists.
  • Ensuring the voting period has ended or the quorum is met.
  • Ensuring the proposal has not already been executed.
  • Handling scenarios where the quorum is not met by refunding the deposit.
  • Handling scenarios where the proposal is rejected by the majority.

Based on the provided code and the assertions present, it appears that the execute_proposal_internal function is designed to handle key edge cases effectively. However, if there are additional specific edge cases or scenarios that need to be verified, further manual review or additional context would be required.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the edge case handling in `execute_proposal_internal`.

# Test: Search for edge case handling patterns in other functions. Expect: Comprehensive handling of various scenarios.
rg --type move $'assert!\\('

Length of output: 57



Script:

#!/bin/bash
# Description: Verify the edge case handling in `execute_proposal_internal`.

# Locate all Move files and search for `assert!` statements within them.
fd -e move -x rg 'assert!\(' {}

Length of output: 122816


354-438: Verify the logic for creating challenge proposals, especially the conditions under which a challenge can be made.

Verification successful

The search results for assert! statements are extensive and include many files unrelated to the create_challenge_proposal function. To focus on the relevant assertions within the create_challenge_proposal function, we should narrow down our search to the specific file precompile/modules/initia_stdlib/sources/vip/weight_vote.move.


The search results show several assert! statements within the precompile/modules/initia_stdlib/sources/vip/weight_vote.move file. These assertions are used to enforce various conditions, including permissions, existence checks, and state validations. Here are some key assertions related to the create_challenge_proposal function:

  • assert!(table::prepare<vector<u8>, WeightVote>(&mut iter), error::not_found(ESTAGE_NOT_FOUND));
  • assert!(weight_vote.voting_end_time < timestamp, error::invalid_state(EVOTING_NOT_END));
  • assert!(table::contains(&module_store.proposals, key), error::not_found(EPROPOSAL_NOT_FOUND));
  • assert!(timestamp < proposal.voting_end_time, error::invalid_state(EVOTING_END));
  • assert!(!proposal.is_executed, error::invalid_state(EPROPOSAL_ALREADY_EXECUTED));

These assertions ensure that:

  1. The weight vote stage is found.
  2. The current weight vote has ended before proceeding.
  3. The proposal exists in the module store.
  4. The proposal's voting period has not ended.
  5. The proposal has not already been executed.

Based on these findings, the logic for creating challenge proposals appears to be well-guarded by these assertions, ensuring that the necessary conditions are met before a challenge proposal can be created.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the conditions for creating challenge proposals.

# Test: Search for the logic used in challenge proposal conditions. Expect: Specific conditions that allow for a challenge.
rg --type move $'assert!\\('

Length of output: 57



Script:

#!/bin/bash
# Description: Verify the conditions for creating challenge proposals.

# Test: Search for the logic used in challenge proposal conditions. Expect: Specific conditions that allow for a challenge.
rg 'assert!\('

Length of output: 248867



Script:

#!/bin/bash
# Description: Verify the conditions for creating challenge proposals in the specific file.

# Test: Search for the logic used in challenge proposal conditions within the specific file.
rg 'assert!\(' precompile/modules/initia_stdlib/sources/vip/weight_vote.move

Length of output: 3369

Copy link

@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: 5

Outside diff range and nitpick comments (2)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (2)

184-213: Consider adding detailed documentation for the initialize function.

The initialize function sets up the module store and initializes various parameters. It would be beneficial for maintainability and clarity to include comments explaining the purpose and effect of each parameter being set, especially for complex blockchain operations.


636-672: Consider using constants for magic numbers.

The function submit_merkle_root_internal uses several numeric values directly in the code. It would improve readability and maintainability to define these as constants at the beginning of the file.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f067474 and 6963ef9.
Files selected for processing (1)
  • precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1 hunks)
Additional comments not posted (1)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1)

596-632: Improve input validation in challenge.

The challenge function modifies the state based on the outcome of a vote. It is critical to ensure that all inputs are validated to prevent issues. Consider adding checks to ensure that the inputs are within expected ranges.

Copy link

@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 6963ef9 and 8591b46.
Files selected for processing (3)
  • precompile/modules/initia_stdlib/sources/object.move (1 hunks)
  • precompile/modules/initia_stdlib/sources/vip/vip.move (5 hunks)
  • precompile/modules/minitia_stdlib/sources/object.move (1 hunks)
Files skipped from review due to trivial changes (2)
  • precompile/modules/initia_stdlib/sources/object.move
  • precompile/modules/minitia_stdlib/sources/object.move
Additional comments not posted (3)
precompile/modules/initia_stdlib/sources/vip/vip.move (3)

631-634: The implementation of is_registered function is correct and follows standard practices for accessing global storage and checking existence in a table.


1002-1011: The update_vip_weight function has been changed to a friend function, restricting its use to friend modules only. This change enhances security by limiting who can call this function, aligning with best practices for sensitive operations like weight updates.


Line range hint 1-1011: The module is well-structured with clear separation of concerns among functions and data structures. The comprehensive use of specific error codes for assertions throughout the module enhances maintainability and debuggability.

Copy link

@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: 7

Outside diff range and nitpick comments (1)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1)

185-214: Consider adding detailed comments to the initialize function to explain the purpose and effect of each parameter and assertion.

Adding comments will improve code readability and maintainability, especially for complex initialization logic.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8591b46 and 2e43568.
Files selected for processing (2)
  • precompile/modules/initia_stdlib/sources/vip/vip.move (39 hunks)
  • precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • precompile/modules/initia_stdlib/sources/vip/vip.move

beer-1 and others added 2 commits June 3, 2024 20:01
* Fix/object max nesting (#56)

* fix: increase count for maximum nesting check

* precompile object

* fix set_error (#57)

* update shared libraries

* update min/max logic (#53)

* update min/max logic

* validate vip weights

* precompile

* add view func for whitelisted bridge ids

* fix object comment; named objects are deletable (#60)

* fix: use roundup for fee calculation (#59)

* use roundup for fee calculation

* refactor to use function

* fix bugs and update tvl logic (#58)

* fix bugs and update tvl logic

* fix typo

---------

Co-authored-by: beer-1 <147697694+beer-1@users.noreply.github.com>

* refactor

---------

Co-authored-by: ALPAC-4 <81249838+ALPAC-4@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Harvey <saw151515@gmail.com>
Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@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: 7

Outside diff range and nitpick comments (1)
precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1)

198-230: Consider adding documentation for the initialize function.

It would be beneficial to include a brief comment describing the purpose and usage of the initialize function to improve code readability and maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2e43568 and 3460dc0.

Files selected for processing (2)
  • precompile/modules/initia_stdlib/sources/vip/vip.move (3 hunks)
  • precompile/modules/initia_stdlib/sources/vip/weight_vote.move (1 hunks)
Additional comments not posted (4)
precompile/modules/initia_stdlib/sources/vip/vip.move (4)

26-26: The addition of initia_std::vip_weight_vote as a friend module is appropriate given the context of the PR, which involves voting mechanisms that likely need access to internal functions of the vip module.


657-660: The function is_registered correctly checks if a bridge is registered by querying the bridges table. This is a straightforward and efficient implementation.


662-676: The function update_vip_weights_for_friend is well-implemented with appropriate error handling for batch operations. The use of assert to ensure the lengths of bridge_ids and weights are equal is crucial for preventing out-of-bounds errors. Additionally, the call to validate_vip_weights at the end ensures that the total weight does not exceed allowed limits after updates, maintaining data integrity.


914-918: The public entry function update_vip_weights simplifies the interface for updating VIP weights by delegating to the update_vip_weights_for_friend function. This is a good use of function abstraction to keep the public API clean while reusing code.

@beer-1 beer-1 merged commit a049470 into main Jun 4, 2024
1 check passed
@beer-1 beer-1 deleted the feat/vip-weight-vote branch June 4, 2024 05:58
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.

4 participants