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

Splitter config lock #757

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Splitter config lock #757

wants to merge 3 commits into from

Conversation

joemonem
Copy link
Contributor

@joemonem joemonem commented Jan 10, 2025

Motivation

The splitter contracts' locks could be bypassed by providing a config during Send.

Implementation

Added this check whenever a config is provided:

ensure!(
            splitter.lock.is_expired(&ctx.env.block),
            ContractError::ContractLocked {
                msg: Some("Config isn't allowed while the splitter is locked".to_string())
            }
        );

Testing

None

Version Changes

splitter: 2.3.0-b.2 -> 2.3.0-b.3
fixed-amount-splitter: 1.2.0-b.1 -> 1.2.0-b.2
weighted-distribution-splitter: 2.1.0-b.2 -> 2.1.0-b.3

Notes

None

Future work

None

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling for contract lock states across multiple finance-related contracts
    • Standardized ContractLocked error to include optional message field
  • Chores

    • Version updates for several splitter contracts:
      • Fixed Amount Splitter: 1.2.0-b.11.2.0-b.2
      • Splitter: 2.3.0-b.22.3.0-b.3
      • Weighted Distribution Splitter: 2.1.0-b.22.1.0-b.3
  • Refactor

    • Improved validation checks for contract lock expiration
    • Updated error handling mechanisms in contract execution functions

@joemonem joemonem requested a review from crnbarr93 January 10, 2025 19:26
Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

This pull request introduces a standardized approach to error handling across multiple Andromeda finance and kernel contracts, specifically focusing on the ContractLocked error variant. The changes modify the error structure to include an optional message field, allowing for more flexible and descriptive error reporting. The modifications span several contracts, including conditional splitter, fixed-amount splitter, weighted distribution splitter, and the Andromeda kernel, with corresponding updates to package versions and error type definitions.

Changes

File Change Summary
contracts/finance/*/Cargo.toml Version updates for splitter packages
packages/std/src/error.rs ContractLocked error variant modified to include optional message
contracts/finance/*/src/contract.rs Updated error handling for contract lock scenarios
contracts/finance/*/src/testing/tests.rs Updated error assertions to match new error structure
contracts/os/andromeda-kernel/src/execute.rs Import statement modifications
contracts/os/andromeda-kernel/src/query.rs Removed Ics20PacketInfo import

Suggested labels

ci: skip-changelog

Suggested reviewers

  • crnbarr93

Poem

🐰 Locks and errors, a rabbit's delight,
Code refactored with precision so bright
Optional messages now take their flight
Standardizing errors with all of our might
A contract's story told with clearer sight! 🔒✨

Possibly related PRs


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
contracts/finance/andromeda-conditional-splitter/src/contract.rs (1)

232-232: Consider adding descriptive error messages for lock-related errors.

The error messages are currently set to None. Adding descriptive messages would improve the user experience by clearly indicating why the operation failed.

-        ContractError::ContractLocked { msg: None }
+        ContractError::ContractLocked {
+            msg: Some("Cannot update thresholds while the splitter is locked".to_string())
+        }

Also applies to: 264-264

contracts/finance/andromeda-splitter/src/contract.rs (1)

Line range hint 250-250: Standardize error message handling across functions.

For consistency with execute_send_cw20, consider adding descriptive error messages to other lock-related errors.

-        ContractError::ContractLocked { msg: None }
+        ContractError::ContractLocked {
+            msg: Some("Cannot perform this operation while the splitter is locked".to_string())
+        }

Also applies to: 338-338, 369-369, 404-404

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 106b2fc and 115c8cb.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • contracts/finance/andromeda-conditional-splitter/src/contract.rs (2 hunks)
  • contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs (1 hunks)
  • contracts/finance/andromeda-fixed-amount-splitter/Cargo.toml (1 hunks)
  • contracts/finance/andromeda-fixed-amount-splitter/src/contract.rs (5 hunks)
  • contracts/finance/andromeda-splitter/Cargo.toml (1 hunks)
  • contracts/finance/andromeda-splitter/src/contract.rs (4 hunks)
  • contracts/finance/andromeda-weighted-distribution-splitter/Cargo.toml (1 hunks)
  • contracts/finance/andromeda-weighted-distribution-splitter/src/contract.rs (7 hunks)
  • contracts/finance/andromeda-weighted-distribution-splitter/src/testing/tests.rs (5 hunks)
  • contracts/os/andromeda-kernel/src/execute.rs (1 hunks)
  • contracts/os/andromeda-kernel/src/query.rs (1 hunks)
  • packages/std/src/error.rs (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • contracts/finance/andromeda-fixed-amount-splitter/Cargo.toml
  • contracts/finance/andromeda-splitter/Cargo.toml
  • contracts/finance/andromeda-weighted-distribution-splitter/Cargo.toml
  • contracts/os/andromeda-kernel/src/query.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Contracts
  • GitHub Check: Schemas
  • GitHub Check: Linting
  • GitHub Check: Summary
🔇 Additional comments (13)
contracts/finance/andromeda-splitter/src/contract.rs (1)

Line range hint 167-172: LGTM! Good security enhancement.

The added check prevents configuration changes while the splitter is locked, addressing the security concern mentioned in the PR objectives. The descriptive error message is helpful for users.

contracts/finance/andromeda-fixed-amount-splitter/src/contract.rs (1)

167-172: LGTM! Security check properly implemented.

The lock validation is correctly placed before any state modifications, preventing configuration changes while the contract is locked.

Also applies to: 303-308

contracts/finance/andromeda-weighted-distribution-splitter/src/contract.rs (3)

279-284: LGTM! Security check properly implemented.

The lock validation is correctly placed and includes a descriptive error message.


137-137: Add test coverage for lock-related error cases.

While the lock validation is implemented correctly, it would be beneficial to add test cases that verify the behavior when attempting to modify locked contracts.

Also applies to: 179-179, 225-225, 389-389, 427-427, 464-464


Line range hint 257-262: Security Review: Lock Validation Implementation

The implementation effectively addresses the security concern by:

  1. Adding lock validation before processing configurations
  2. Preventing unauthorized modifications during locked states
  3. Using descriptive error messages in critical paths

Recommendations for improvement:

  1. Standardize error message handling across all lock-related errors
  2. Add comprehensive test coverage for lock-related scenarios
  3. Consider adding logging for security-relevant events

Also applies to: 167-172, 303-308, 279-284

packages/std/src/error.rs (1)

46-47: LGTM! Enhanced error reporting for contract locks.

The addition of an optional message field to the ContractLocked variant improves error reporting by allowing contracts to provide context-specific details about why an operation was rejected due to a lock.

contracts/finance/andromeda-conditional-splitter/src/testing/tests.rs (1)

223-223: LGTM! Updated test assertion to match new error structure.

The test assertion has been correctly updated to match the new ContractLocked error variant that includes an optional message field.

contracts/os/andromeda-kernel/src/execute.rs (1)

7-7: LGTM! Improved fund validation strategy.

Replacing merge_coins with has_coins_merged shifts the focus from merging operations to validation, which is a safer approach for handling funds.

contracts/finance/andromeda-weighted-distribution-splitter/src/testing/tests.rs (5)

330-330: LGTM! Updated test assertion in test_execute_update_lock_already_locked.

Test assertion correctly updated to match the new ContractLocked error variant structure.


604-604: LGTM! Updated test assertion in test_execute_remove_recipient_contract_locked.

Test assertion correctly updated to match the new ContractLocked error variant structure.


827-827: LGTM! Updated test assertion in test_update_recipient_weight_locked_contract.

Test assertion correctly updated to match the new ContractLocked error variant structure.


1280-1283: LGTM! Updated test assertion in test_execute_add_recipient_locked_contract.

Test assertion correctly updated to match the new ContractLocked error variant structure.


1498-1498: LGTM! Updated test assertion in test_execute_update_recipients_contract_locked.

Test assertion correctly updated to match the new ContractLocked error variant structure.

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