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: wrong denom check at RegisterCoin #78

Merged
merged 2 commits into from
Jul 27, 2024

Conversation

zsystm
Copy link

@zsystm zsystm commented Jul 25, 2024

Description

Problem:

  • coinMetadata.Base is used as the denom for the token pair.
  • However, the check is incorrectly performed using coinMetadata.Name, so it fails to detect if the denom is already registered.

Solution:

  • Check using coinMetadata.Base, not .Name.

Proof of Work:

  • Test Case
    • Running the test case with the code before the fix will fail, indicating that multiple token pairs for the same denom are created.
    • The test case passes with the changes in this PR.

Test Code Refactoring:

  • I modified the test code to better match real cases. Previously, the test code incorrectly used the same value for the Base and Name fields in banktypes.BaseMetadata, which never happens in reality.
  • This mistake prevented the test from catching the implementation error in the denom already registered check. By using different values for Base and Name, as in real scenarios, the implementation error would have been detected.

More Context:

  • Unfortunately, there is already one case on the mainnet where multiple token pairs exist for the same denom (ibc/13B6057538B93225F6EBACCB64574C49B2C1568C5AE6CCFE0A039D7DAC02BF29).
  • However, this is not a major issue because only the latest token pair registered in the denom index is actually used.
  • With this patch, such cases will no longer occur.

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • included the necessary unit and integration tests
  • reviewed "Files changed" and left comments if necessary

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

zsystm added 2 commits July 25, 2024 14:42
problem:
- `coinMetadata.Base` is used as the denom for the token pair
- However, the check is incorrectly performed using `coinMetadata.Name`, so it fails to detect if the denom is already registered

solution: check using `coinMetadata.Base`, not `.Name`

more context:
Unfortunately, there is already one case on the mainnet where multiple token pairs exist for the same denom(= ibc/13B6057538B93225F6EBACCB64574C49B2C1568C5AE6CCFE0A039D7DAC02BF29). However, this is not a major issue because only the latest token pair registered in the denom index is actually used.

 With this patch, such cases will no longer occur.
@zsystm zsystm self-assigned this Jul 25, 2024
@zsystm zsystm requested review from dongsam, dudong2 and poorphd July 25, 2024 06:23
@zsystm zsystm marked this pull request as ready for review July 25, 2024 06:23
Copy link

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

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

@tkkwon1998 tkkwon1998 left a comment

Choose a reason for hiding this comment

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

lgtm!

@zsystm zsystm merged commit 0b18ceb into v8/develop Jul 27, 2024
8 checks passed
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