Add concentrated liquidity AMM properties (Uniswap V3 style)#86
Open
omarinuwa wants to merge 1 commit intocrytic:mainfrom
Open
Add concentrated liquidity AMM properties (Uniswap V3 style)#86omarinuwa wants to merge 1 commit intocrytic:mainfrom
omarinuwa wants to merge 1 commit intocrytic:mainfrom
Conversation
Implements 13 comprehensive property tests for concentrated liquidity AMMs addressing GitHub issue crytic#50. These properties detect critical vulnerabilities including the KyberSwap Elastic hack ($50M exploit from November 2023). ## Properties Implemented ### Tick Math Properties (5 properties) - CL-TICK-001: Tick direction matches price direction (monotonicity) - CL-TICK-002: No price overshoot past tick boundaries (KyberSwap fix) - CL-TICK-003: Tick spacing alignment requirements The price overshoot property directly addresses the KyberSwap vulnerability where using inequality (!=) instead of directional comparison (<, >) allowed price to exceed the next tick boundary, causing liquidity to be double-counted. ### Liquidity Conservation Properties (3 properties) - CL-LIQUIDITY-001: LiquidityNet sums to zero (conservation law) - CL-LIQUIDITY-002: Current liquidity equals sum of deltas ≤ currentTick - CL-LIQUIDITY-003: Liquidity values cannot be negative These verify the fundamental conservation laws of the asymmetric liquidity accounting system where every position adds +L at tickLower and -L at tickUpper. ### Mint/Burn Properties (4 properties) - CL-MINT-001: Mint increases current liquidity only when in range - CL-MINT-002: Mint always increases liquidityGross at both ticks - CL-MINT-003: Mint updates liquidityNet asymmetrically (+L/-L) - CL-BURN-001: Burn exactly reverses mint state changes The asymmetric update pattern is critical - using symmetric updates would cause positions to never deactivate or incorrectly accumulate liquidity. ### Swap Properties (4 properties) - CL-SWAP-001: Price moves in correct direction based on trade side - CL-SWAP-002: Swap respects sqrtPriceLimitX96 (slippage protection) - CL-SWAP-003: Liquidity updated when crossing tick boundaries - CL-SWAP-004: Price stays within valid bounds [MIN_SQRT_RATIO, MAX_SQRT_RATIO] ## Files Added **Core Property Contracts:** - contracts/ConcentratedLiquidity/internal/properties/TickMathProperties.sol - contracts/ConcentratedLiquidity/internal/properties/LiquidityProperties.sol - contracts/ConcentratedLiquidity/internal/properties/MintBurnProperties.sol - contracts/ConcentratedLiquidity/internal/properties/SwapProperties.sol **Utilities and Base Contracts:** - contracts/ConcentratedLiquidity/util/IConcentratedLiquidityPool.sol - contracts/ConcentratedLiquidity/util/TickMath.sol (from Uniswap V3) - contracts/ConcentratedLiquidity/internal/util/ConcentratedLiquidityTestBase.sol **Documentation and Tests:** - contracts/ConcentratedLiquidity/README.md (comprehensive guide) - tests/ConcentratedLiquidity/foundry/src/SimpleMockPool.sol - tests/ConcentratedLiquidity/foundry/test/CryticConcentratedLiquidityTest.sol **Updated:** - CLAUDE.md (added ConcentratedLiquidity to project overview) ## Key Features 1. **Comprehensive NatSpec Documentation**: Each property includes: - WHY THIS MUST BE TRUE explanation - Mathematical proof or detailed example - WHAT BUG THIS CATCHES section - Real-world vulnerability references (KyberSwap) 2. **Real Vulnerability Detection**: Properties specifically target: - KyberSwap Elastic hack (price overshoot, liquidity double-counting) - Conservation law violations (liquidity leaks) - Asymmetric update errors (positions not deactivating) - Tick spacing violations (orphaned liquidity) 3. **Production-Ready TickMath Library**: Complete Uniswap V3 implementation for accurate tick-price conversions in property tests. 4. **Example Test Harness**: SimpleMockPool with complete harness demonstrating how to combine properties with pool implementations. 5. **Extensive README**: Includes usage examples, vulnerability explanations, integration patterns, and resources. ## Testing Approach These properties support internal testing mode (test contract inherits from pool). External testing mode can be added following the same pattern as ERC20/ERC721. ## Integration Properties can be combined with existing ERC20 properties since pools typically use ERC20 tokens: ```solidity contract CombinedTest is CryticERC20BasicProperties, CryticTickMathProperties { ... } ``` Resolves crytic#50
|
Omar Inuwa seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
Implements 13 comprehensive property tests for concentrated liquidity AMMs addressing GitHub issue #50. These properties detect critical vulnerabilities including the KyberSwap Elastic hack ($50M exploit from November 2023).
Properties Implemented
Tick Math Properties (5 properties)
The price overshoot property directly addresses the KyberSwap vulnerability where using inequality (!=) instead of directional comparison (<, >) allowed price to exceed the next tick boundary, causing liquidity to be double-counted.
Liquidity Conservation Properties (3 properties)
These verify the fundamental conservation laws of the asymmetric liquidity accounting system where every position adds +L at tickLower and -L at tickUpper.
Mint/Burn Properties (4 properties)
The asymmetric update pattern is critical - using symmetric updates would cause positions to never deactivate or incorrectly accumulate liquidity.
Swap Properties (4 properties)
Resolves #50