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

Fix MarkerTransferAuthorization validation. #1856

Merged
merged 5 commits into from Mar 1, 2024

Conversation

SpicyLemon
Copy link
Contributor

@SpicyLemon SpicyLemon commented Feb 23, 2024

Description

The MarkerTransferAuthorization.ValidateBasic() method now ensures that the TransferLimit is valid Coins (and still can't be zero), and also ensures that the AllowList entries are all valid bech32 addresses.

The change to TransferLimit validation is the primary fix here. What was happening is that a person could create a grant with a MarkerTransferAuthorization in it that had an unsorted TransferLimit. Later, when that grant is used, the SafeSub (in DecreaseTransferLimit) panics because the TransferLimit isn't sorted.

The extra limitation on the AllowList is merely a nicety to help prevent people from accidentally having a worthless/incorrect entry in the list. Having a non-bech32 entry in there doesn't cause a panic or any other errors, but the value they're being checked against will always be a bech32 address string, so we might as well not allow these authorizations to have non-bech32 entries in it.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced validation for marker transfer authorizations to provide more detailed error messages.
    • Ensure allow list entries are bech32 address strings to help prevent unusable or accidental entries.
  • Bug Fixes

    • Fixed issues with transfer limits not being correctly validated.
  • Tests

    • Updated and added test cases to cover new validation logic and scenarios for marker transfer limits and allow lists.

…valid Coins and the addresses in the allow list are valid.
@SpicyLemon SpicyLemon requested a review from a team as a code owner February 23, 2024 21:46
@SpicyLemon SpicyLemon changed the title Fix MarkerTransferAuthorization validation Fix MarkerTransferAuthorization validation. Feb 23, 2024
Copy link
Contributor

coderabbitai bot commented Feb 23, 2024

Walkthrough

The updates focus on enhancing the MarkerTransferAuthorization struct within a blockchain framework. These enhancements include refining the validation process for transfer limits and allow lists, incorporating more precise error messaging, and adding a new field to manage allowed addresses. The changes aim to improve security and usability by ensuring only valid transactions are processed and providing clearer feedback during validation failures.

Changes

Files Change Summary
.../types/authz.go,
.../types/authz_test.go
Updated MarkerTransferAuthorization struct; refined validation logic; added AllowList field. Enhanced test cases for new validation logic and struct changes.

"In the realm of code, where logic does play,
A rabbit hopped in, making changes today.
🐇 With a hop and a skip, the code did transform,
Ensuring transfers, within safe norms.
Allow lists refined, with a meticulous gaze,
In this digital burrow, only clarity stays."
🌟📝🚀

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 887ed40 and a9ebbfc.
Files selected for processing (2)
  • x/marker/types/authz.go (1 hunks)
  • x/marker/types/authz_test.go (2 hunks)
Additional comments: 4
x/marker/types/authz.go (2)
  • 63-67: The addition of TransferLimit.Validate() and the zero-value check enhances the robustness of the MarkerTransferAuthorization validation by ensuring that the TransferLimit is not only valid but also non-zero. This is a critical improvement for preventing potential issues related to invalid or zero TransferLimit values.
  • 71-78: The updated validation logic for the AllowList significantly improves the security and integrity of the MarkerTransferAuthorization. By ensuring all addresses in the AllowList are valid bech32 addresses and checking for duplicates, the changes mitigate the risk of including invalid or duplicate addresses. The use of detailed error messages for each scenario is a good practice, as it aids in debugging and issue resolution.
x/marker/types/authz_test.go (2)
  • 10-15: The addition of imports for sdkmath and assertions is necessary for the updated test cases. The sdkmath import is used for creating Coin instances with specific amounts, and assertions is utilized for asserting error messages in test cases. These additions support the new test scenarios introduced by the changes in validation logic.
  • 62-139: The updated and new test cases in TestMarkerTransferAuthorizationValidateBasic effectively cover a wide range of scenarios for both TransferLimit and AllowList validations. This includes tests for nil and empty TransferLimit, invalid denominations, zero and negative coin amounts, unsorted TransferLimit, and various AllowList scenarios such as invalid entries and duplicates. The use of detailed error messages in assertions is commendable, as it ensures that the validation logic behaves as expected in each scenario.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a9ebbfc and 6630cda.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 2
CHANGELOG.md (2)
  • 42-42: The link provided in the bug fix entry for MarkerTransferAuthorization validation correctly points to a GitHub pull request, which is expected in a changelog. This allows readers to explore the specific changes made in more detail.
  • 42-42: The categorization of the change related to MarkerTransferAuthorization validation under "Bug Fixes" is appropriate, as it addresses a specific issue that was corrected. This helps readers quickly identify the nature of the change.

CHANGELOG.md Show resolved Hide resolved
iramiller
iramiller previously approved these changes Feb 23, 2024
@SpicyLemon SpicyLemon enabled auto-merge (squash) February 23, 2024 21:55
Taztingo
Taztingo previously approved these changes Feb 25, 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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6630cda and 1ba06df.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@SpicyLemon SpicyLemon merged commit abd2da1 into main Mar 1, 2024
35 checks passed
@SpicyLemon SpicyLemon deleted the dwedul/fix-marker-authz-validation branch March 1, 2024 15:40
SpicyLemon added a commit that referenced this pull request Mar 18, 2024
* Fix MarkerTransferAuthorization validation to make sure the limit is valid Coins and the addresses in the allow list are valid.

* Add changelog entry.
SpicyLemon added a commit that referenced this pull request Mar 18, 2024
* Fix MarkerTransferAuthorization validation to make sure the limit is valid Coins and the addresses in the allow list are valid.

* Add changelog entry.
SpicyLemon added a commit that referenced this pull request Mar 18, 2024
…fer authz validation). (#1876)

* Allow force transfers from marker and market accounts. (#1855)

* Allow force transfers out of marker and market accounts.

* Add some test cases for marker and market accounts with canForceTransferFrom.

* Add changelog entry.

* Tweak TestCanForceTransferFrom a little based on coderabbit feedback. Namely, have the account creators take in a string to use for the addr instead of the full address that it's going to just turn around and return.

* Lint fix (needed extra empty line in keeper/marker.go).

* Fix MarkerTransferAuthorization validation. (#1856)

* Fix MarkerTransferAuthorization validation to make sure the limit is valid Coins and the addresses in the allow list are valid.

* Add changelog entry.

* Fix one of the changelog lines.
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.

None yet

4 participants