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(x/precisebank): Ensure exact reserve balance on integer carry when minting #1932

Merged
merged 10 commits into from
Jun 20, 2024

Conversation

drklee3
Copy link
Member

@drklee3 drklee3 commented Jun 4, 2024

Description

  • Fix reserve minting an extra coin when the recipient module both carries fractional over to integer balance AND remainder is insufficient.
  • Adjusts fractional carry to simply send from reserve, instead of doing an additional mint.
  • Add invariant to ensure reserve matches exactly with fractional balances + remainder, failing on both insufficient and excess funds.

@drklee3 drklee3 marked this pull request as ready for review June 4, 2024 22:16
Copy link
Member

@pirtleshell pirtleshell left a comment

Choose a reason for hiding this comment

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

great bug catch by @nddeluca & fix by you @drklee3 ! 👍

added some nits and a question but LGTM

x/precisebank/keeper/invariants.go Outdated Show resolved Hide resolved
x/precisebank/keeper/invariants.go Outdated Show resolved Hide resolved
Comment on lines +172 to +179
// Mint an additional reserve integer coin if remainder is insufficient.
// The remainder is the amount of fractional coins that can be minted and
// still be fully backed by reserve. If the remainder is less than the
// minted fractional amount, then the reserve needs to be increased to
// back the additional fractional amount.
// Optimization: This is only done when the integer amount does NOT carry,
// as a direct account mint is done instead of integer carry transfer +
// insufficient remainder reserve mint.
Copy link
Member

Choose a reason for hiding this comment

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

appreciate this detailed explanation 👍

@drklee3 drklee3 force-pushed the dl-precisebank/mint-reserves-fix branch from f09ef1d to b071b0e Compare June 20, 2024 18:06
@drklee3 drklee3 merged commit 1743cf5 into master Jun 20, 2024
12 checks passed
@drklee3 drklee3 deleted the dl-precisebank/mint-reserves-fix branch June 20, 2024 22:20
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.

3 participants