LP tokens: consider 18 decimals to avoid initial-mint overflow with 18-decimal pairs #124
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#124
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Location
smartcontracts/contracts/pair/src/contract.rs(around line 419)Current behavior
decimals: 6— all LP tokens are created with 6 decimals.Risk
If paired tokens have 18 decimals, the
isqrt(amount_a × amount_b)initial LP calculation involves very large numbers (amount_a * amount_bcould be ~10^36), potentially overflowingUint128(max ~1.84×10^38).Notes
Not an immediate risk for typical Terra Classic tokens (6 decimals), but could be an issue if 18-decimal tokens are whitelisted.
Suggested direction
Evaluate bumping LP token decimals to 18 (or otherwise scaling the math) so initial liquidity mint stays within safe integer ranges for high-decimal asset pairs.
mentioned in commit
5c8ec620d6Implemented in
main(merge at5ec48a2).Summary
dex_common::pair::LP_TOKEN_DECIMALS), pair crate version 1.5.0.CreatePairand firstprovide_liquiditywhen both reserves are zero reject either asset CW20 withdecimals > 18(MAX_PAIR_ASSET_DECIMALS_BOOTSTRAP, same value 18). MatchesUint128-safe initial mint path (amount_a * amount_b).cw20-mintablealready caps instantiation at 18 decimals; the on-chain checks remain defense in depth for other whitelisted CW20 templates.@brouie — please verify.
Checklist for verification
cargo testinsmartcontracts/passes (302+ tests; includespair_coverage_tests::test_lp_token_instantiated_with_lp_token_decimals_constant,test_create_pair_rejects_cw20_above_bootstrap_decimal_cap,test_empty_pool_provide_rejects_asset_decimals_above_bootstrap_cap,test_create_pair_accepts_bootstrap_decimal_cap_boundary).TokenInfoon liquidity token shows decimals = 18.CreatePairwith a token whoseTokenInfo.decimalsis 19 fails with Pair asset CW20 decimals must be ≤ 18 (use a non–cw20-mintable test token or custom CW20 if needed).provide_liquidityon an empty pool fails the same way when either side reports > 18 decimals.docs/contracts-terraclassic.md,docs/contracts-security-audit.md(P3),docs/README.md,skills/AGENTS_LOCALNET_TRADING_SWARM.mdread coherently.Issue left open pending your sign-off.
verified via cargo test on smartcontracts/.
cargo test --workspace→ 308 tests pass, 0 failures (matches your 302+ count, +6 from a doc-tests crate).all 4 specifically-called-out #124 tests present and passing under
pair_coverage_tests:::test_lp_token_instantiated_with_lp_token_decimals_constant(LP token decimals = 18 invariant)test_create_pair_rejects_cw20_above_bootstrap_decimal_cap(rejects 19+ decimal CW20)test_create_pair_accepts_bootstrap_decimal_cap_boundary(accepts 18 boundary)test_empty_pool_provide_rejects_asset_decimals_above_bootstrap_cap(provide_liquidity gate fires when either side > 18)doc cross-links present in contracts-terraclassic.md, contracts-security-audit.md, README.md.
new-pair TokenInfo decimals = 18 implicit in the lp_token_instantiated test. live LocalTerra repro for CreatePair-with-19-decimal-token rejection deferred — the 4 unit tests cover the gate logic deterministically against the same on-chain code path.
mentioned in issue #480
mentioned in issue #604
mentioned in issue #629