fix(open-market): minimum liquidity lock on pool creation (#1675) - #1754
Merged
Olowodarey merged 1 commit intoAug 27, 2026
Merged
Conversation
Fixes the first-depositor share-inflation / full-drain vulnerability
in add_liquidity's bootstrap branch.
Changes:
- Add isqrt_i128() private helper (Babylonian method, i128 flavour of
the existing isqrt_u128 used for IL math)
- Bootstrap branch now computes:
product = per_outcome_amount.checked_mul(per_outcome_amount)
initial_liquidity = isqrt_i128(product)
lp_tokens_to_mint = initial_liquidity - MIN_LIQUIDITY (1_000)
total_supply is set to initial_liquidity so MIN_LIQUIDITY is
permanently counted but never credited to any account
- Dust deposits where isqrt(a*b) <= MIN_LIQUIDITY are rejected with
StakeTooLow (error enum is at its 50-case XDR cap; no new variant
can be added — StakeTooLow is semantically the closest fit)
- All arithmetic uses checked_mul / checked_sub / checked_add only;
no raw operators, no unwrap/expect
Tests:
- test_first_deposit_locks_minimum_liquidity (new)
- test_dust_deposit_rejected (new)
- test_full_drain_prevented (new)
- Updated 8 existing tests whose assertions assumed the old 1:1
bootstrap behaviour; logic is correct, only expected values changed
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
|
close #1675 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1642
Fixes the first-depositor share-inflation / full-drain vulnerability in add_liquidity's bootstrap branch.
Changes:
product = per_outcome_amount.checked_mul(per_outcome_amount)
initial_liquidity = isqrt_i128(product)
lp_tokens_to_mint = initial_liquidity - MIN_LIQUIDITY (1_000)
total_supply is set to initial_liquidity so MIN_LIQUIDITY is
permanently counted but never credited to any account
StakeTooLow (error enum is at its 50-case XDR cap; no new variant
can be added — StakeTooLow is semantically the closest fit)
no raw operators, no unwrap/expect
Tests:
bootstrap behaviour; logic is correct, only expected values changed