Skip to content

feat: x/precisebank module #69

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

Draft
wants to merge 23 commits into
base: feat/precisebank
Choose a base branch
from

Conversation

dudong2
Copy link

@dudong2 dudong2 commented Apr 13, 2025

Description

TL;DR: Introduces x/precisebank to address EVM ↔ SDK precision mismatch and integrates it with x/vm and precompiles.


Problem

  • Cosmos SDK assumes a 6-decimal denomination across all modules.
  • EVM uses 18 decimals, causing precision loss when transferring values or paying gas.
  • Sub-6-decimal values are floored, which can lead to:
    • Loss of small token amounts
    • Arbitrage vulnerabilities in DEXs like Uniswap v2 navite coin -> erc20 senarios due to mismatched balance handling

Purpose

  • Enable precise handling of fractional balances in EVM-related modules.
  • Preserve and manage sub-integer values (e.g., 0.0000001 (= 10^-7) tokens) without loss.
  • Seamlessly integrate precise value tracking into x/vm and precompiles.

Implemented Changes

  • Introduced a new x/precisebank module based on Kava’s implementation.
  • Generalized to support 1~17 decimal assets, not just 6↔18.
  • Added carry/borrow mechanics for converting fractional to integer coins.
  • Replaced direct use of BankKeeper with PreciseBankKeeper in:
    • x/vm
    • precompiles
  • Added invariant check for total supply
  • Added CLI queries for fractional balances and remainder state.
  • Added tests:
    • Edge case handling
    • Fuzz tests (Mint, Burn, Send, Genesis validation)

Notes

  • For tokens with exactly 18 decimals, use x/bank instead of x/precisebank.
  • This module is designed to manage fractional precision below 6 decimals, not full 18-decimal coins.
  • Staking, slashing, distribution, and other Cosmos SDK modules remain unchanged:
    • They all assume 6 decimals and are out of scope for this PR.

Closes: #48


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

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

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

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

@dudong2 dudong2 self-assigned this Apr 13, 2025
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