Extended precision wrapper for x/bank enabling 18 decimal support
The x/precisebank module from Ontomir evm extends the standard x/bank module from 6 to 18 decimal precision for EVM compatibility.
For conceptual understanding of precision handling and mathematical proofs, see [Precision Handling](/docs/evm/next/documentation/concepts/precision-handling).
The module acts as a wrapper around x/bank, providing:
18 decimal precision for EVM (10^18 sub-atomic units)
Backward compatibility with 6 decimal Ontomir operations
Transparent conversion between precision levels
Fractional balance tracking for sub-test amounts
Developed with contributions from the [Kava](https://www.kava.io/) team.
The module maintains fractional balances and remainder :
Object
Key
Value
Description
Account fractional balance (0 to 10^12-1)
Uncirculated fractional amount
Balance Representation
Full balance calculation:
Where:
test_balance: Stored in x/bank (6 decimals)
fractional_balance: Stored in x/precisebank (0 to 10^12-1)
atest_balance: Full 18-decimal precision
Keeper Interface
The module provides a bank-compatible keeper :
Extended Coin Support
Automatic handling of "atest" denomination:
Converts between test and atest transparently
Maintains fractional balances for sub-test amounts
Ensures consistency between x/bank and x/precisebank
Handles both integer and fractional components:
Algorithm:
Subtract from sender (update b(sender) and f(sender))
Add to receiver (update b(receiver) and f(receiver))
Update reserve based on carry/borrow
Remainder unchanged (mathematical guarantee)
Creates new tokens with proper backing:
Algorithm:
Add to account (update b(account) and f(account))
Decrease remainder (tokens enter circulation)
Update reserve for consistency
Removes tokens from circulation:
Algorithm:
Subtract from account (update b(account) and f(account))
Increase remainder (tokens leave circulation)
Update reserve for consistency
Standard bank events with extended precision amounts:
Transfer Events
Event
Attributes
Description
sender, recipient, amount
Mint/Burn Events
Event
Attributes
Description
```bash Query-Total # Query total fractional balances evmd query precisebank total-fractional-balances
Example output:
total: "2000000000000atest"
Replace bank keeper with precisebank keeper in app.go:
For Other Modules
Query extended balances through standard interface:
Reserve Account
The reserve account maintains backing for fractional balances:
Monitoring Reserve
Critical invariants maintained by the module:
Invariant
Formula
Description
Total_atest = Total_test × 10^12 - remainder
Reserve × 10^12 = Σf(n) + r
Δ(Total_atest) = Δ(Total_test × 10^12)
Chain Integration
Reserve Monitoring
Track reserve balance for validation
Set up alerts for invariant violations
Regular audits of fractional sums
dApp Development
Security Considerations
Overflow Protection
All arithmetic uses checked math
Fractional values bounded to [0, 10^12)
Integer overflow impossible by design
Balance updates are atomic
Reserve adjustments in same transaction
No intermediate states visible
Precision Guarantees
No precision loss during operations
All fractional amounts preserved
Rounding only at display layer
Additional O(n) storage for accounts with fractional balances
Most accounts have zero fractional balance (no storage)
Reserve account: single additional balance
Constant time operations for all transfers
Single addition/multiplication for balance queries
~10% gas overhead for fractional updates
Lazy initialization (fractional balances start at zero)
Sparse storage (only non-zero fractions stored)
Batch operations maintain efficiency
Troubleshooting
Verify full atest balance
Audit reserve and remainder
Validation Commands