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

chore: update math package #8857

Merged
merged 1 commit into from
Dec 2, 2024
Merged

chore: update math package #8857

merged 1 commit into from
Dec 2, 2024

Conversation

PaddyMc
Copy link
Collaborator

@PaddyMc PaddyMc commented Dec 2, 2024

What is the purpose of the change

Updating math in osmosis math package

Copy link
Contributor

github-actions bot commented Dec 2, 2024

Important Notice

This PR modifies an in-repo Go module. It is one of:

  • osmomath
  • osmoutils
  • x/ibc-hooks
  • x/epochs

The dependent Go modules, especially the root one, will have to be
updated to reflect the changes. Failing to do so might cause e2e to fail.

Please follow the instructions below:

  1. Open https://github.com/osmosis-labs/osmosis/actions/workflows/go-mod-auto-bump.yml
  2. Provide the current branch name
  3. On success, confirm if an automated commit corretly updated the go.mod and go.sum files

Please let us know if you need any help.

@PaddyMc PaddyMc added A:no-changelog V:state/breaking State machine breaking PR labels Dec 2, 2024
Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in the pull request primarily focus on enhancing the CustomMessenger struct within the wasmbinding/message_plugin.go file. Key modifications include the addition of error checks in the mintTokens method to prevent minting tokens to module accounts, improving the validation process. Furthermore, error handling across several methods has been standardized to use errorsmod.Wrap, providing clearer context in error messages. The overall control flow remains stable, but the updates ensure that token management operations are more robust and traceable.

Changes

File Path Change Summary
wasmbinding/message_plugin.go - Updated mintTokens method to include error check for module accounts.
- Standardized error handling in createDenom, mintTokens, changeAdmin, and burnTokens.
- Modified PerformMint function to include new module account check.
- Updated method signatures for mintTokens and PerformMint to reflect changes.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CustomMessenger
    participant TokenFactoryKeeper
    participant BankKeeper

    Client->>CustomMessenger: Request to mint tokens
    CustomMessenger->>TokenFactoryKeeper: PerformMint check
    TokenFactoryKeeper->>CustomMessenger: Validate recipient address
    alt If recipient is a module account
        CustomMessenger-->>Client: Error: Cannot mint to module account
    else
        CustomMessenger->>BankKeeper: Mint tokens
        BankKeeper-->>CustomMessenger: Tokens minted successfully
        CustomMessenger-->>Client: Success: Tokens minted
    end
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7935b3e and 3cdb554.

⛔ Files ignored due to path filters (2)
  • osmomath/go.mod is excluded by !**/*.mod
  • osmomath/go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (1)
  • wasmbinding/message_plugin.go (1 hunks)
🔇 Additional comments (1)
wasmbinding/message_plugin.go (1)

128-130: 🛠️ Refactor suggestion

Consider adding module account check before minting

While the added validation prevents sending minted tokens to module accounts, the current implementation performs the check after minting but before transfer. This could lead to tokens being minted and stuck in the contract address if the recipient is a module account.

Consider moving the module account check before the mint operation to prevent unnecessary state changes:

 func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) error {
     if mint == nil {
         return wasmvmtypes.InvalidRequest{Err: "mint token null mint"}
     }
     rcpt, err := parseAddress(mint.MintToAddress)
     if err != nil {
         return err
     }
+    if f.IsModuleAcc(ctx, rcpt) {
+        return tokenfactorytypes.ErrMintToModuleAccount
+    }
 
     coin := sdk.Coin{Denom: mint.Denom, Amount: mint.Amount}
     sdkMsg := tokenfactorytypes.NewMsgMint(contractAddr.String(), coin)
     if err = sdkMsg.ValidateBasic(); err != nil {
         return err
     }
 
     // Mint through token factory / message server
     msgServer := tokenfactorykeeper.NewMsgServerImpl(*f)
     _, err = msgServer.Mint(ctx, sdkMsg)
     if err != nil {
         return errorsmod.Wrap(err, "minting coins from message")
     }
-    if f.IsModuleAcc(ctx, rcpt) {
-        return tokenfactorytypes.ErrMintToModuleAccount
-    }
     err = b.SendCoins(ctx, contractAddr, rcpt, sdk.NewCoins(coin))
     if err != nil {
         return errorsmod.Wrap(err, "sending newly minted coins from message")
     }
     return nil
 }

Let's verify if there are any existing module account checks in other token factory implementations:

✅ Verification successful

Let me analyze the search results. The key findings from the codebase search are:

  1. The IsModuleAcc check is used in multiple places in the token factory module:

    • In x/tokenfactory/keeper/bankactions.go for both minting and burning operations
    • In x/tokenfactory/keeper/before_send.go for transfer operations
  2. The check is consistently placed before the actual operation in other instances:

    • Before burning in msg_server.go
    • Before transfers in before_send.go
    • Before minting in bankactions.go

This confirms that the review comment's suggestion to move the module account check before minting is consistent with the existing patterns in the codebase.

Consider moving module account check before minting to maintain consistency

The module account check should be performed before minting to:

  1. Follow the consistent pattern used throughout the token factory module
  2. Prevent unnecessary state changes and gas consumption
  3. Maintain a cleaner control flow
 func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) error {
     if mint == nil {
         return wasmvmtypes.InvalidRequest{Err: "mint token null mint"}
     }
     rcpt, err := parseAddress(mint.MintToAddress)
     if err != nil {
         return err
     }
+    if f.IsModuleAcc(ctx, rcpt) {
+        return tokenfactorytypes.ErrMintToModuleAccount
+    }
 
     coin := sdk.Coin{Denom: mint.Denom, Amount: mint.Amount}
     sdkMsg := tokenfactorytypes.NewMsgMint(contractAddr.String(), coin)
     if err = sdkMsg.ValidateBasic(); err != nil {
         return err
     }
 
     // Mint through token factory / message server
     msgServer := tokenfactorykeeper.NewMsgServerImpl(*f)
     _, err = msgServer.Mint(ctx, sdkMsg)
     if err != nil {
         return errorsmod.Wrap(err, "minting coins from message")
     }
-    if f.IsModuleAcc(ctx, rcpt) {
-        return tokenfactorytypes.ErrMintToModuleAccount
-    }
     err = b.SendCoins(ctx, contractAddr, rcpt, sdk.NewCoins(coin))
     if err != nil {
         return errorsmod.Wrap(err, "sending newly minted coins from message")
     }
     return nil
 }
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar module account validation patterns in token factory implementations
rg -A 2 "IsModuleAcc|ModuleAccount" 

Length of output: 114465


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

@PaddyMc PaddyMc merged commit b4eba83 into main Dec 2, 2024
1 check passed
@PaddyMc PaddyMc deleted the chore/update-math-in-osmomath branch December 2, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:no-changelog V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants