Skip to content

Hermes [ Crypto ] Fix first-depositor price manipulation in LiquidityPool#6011

Closed
Vincent1-p wants to merge 3 commits into
UnsafeLabs:mainfrom
Vincent1-p:fix/liquiditypool-first-depositor-918
Closed

Hermes [ Crypto ] Fix first-depositor price manipulation in LiquidityPool#6011
Vincent1-p wants to merge 3 commits into
UnsafeLabs:mainfrom
Vincent1-p:fix/liquiditypool-first-depositor-918

Conversation

@Vincent1-p
Copy link
Copy Markdown

Closes #918

Changes

1. First-Depositor Attack Protection

  • Added MINIMUM_LIQUIDITY = 1000 constant
  • First deposit permanently locks MINIMUM_LIQUIDITY tokens at address(0)
  • Follows Uniswap V2 pattern to prevent price manipulation

2. Internal Reserves

  • Added reserveA and reserveB internal variables
  • removeLiquidity uses internal reserves (not manipulable balanceOf)
  • Prevents exploitation via direct token transfers

3. Sync Function

  • sync() updates reserves from actual token balances
  • Recovery mechanism from donation attacks
  • Emits Sync event for transparency

4. SafeERC20 Integration

  • All token transfers use SafeERC20 for checked transfers
  • Input validation on all parameters

Testing (18 test cases)

  • ✅ First deposit lock: MINIMUM_LIQUIDITY at address(0)
  • ✅ Correct LP allocation (minus locked amount)
  • ✅ First-depositor manipulation prevention (donation attack simulated)
  • ✅ Subsequent proportional deposit formula verification
  • ✅ removeLiquidity uses internal reserves (ignores donations)
  • ✅ Direct transfers do not affect LP pricing
  • ✅ Sync function updates reserves correctly
  • ✅ Sync event emission verification
  • ✅ Insufficient initial liquidity revert
  • ✅ Exact MINIMUM_LIQUIDITY boundary test
  • ✅ Insufficient LP balance revert
  • ✅ Non-owner LP removal revert
  • ✅ Tiny second deposit (1 wei → 1 LP token)
  • ✅ Asymmetric first deposit (unequal A/B amounts)
  • ✅ Asymmetric subsequent deposit with ratio verification
  • ✅ Zero amount input rejection
  • ✅ getReserves returns correct values
  • ✅ Multiple users add + remove lifecycle with final state check

Contributor Verification

  • _generation.json with Hermes agent metadata
  • ✅ PR title: Hermes + [ Crypto ]

/bounty 600

刘思浓 and others added 3 commits June 2, 2026 21:12
…Pool

Closes UnsafeLabs#918

- Add MINIMUM_LIQUIDITY=1000 lock at address(0)
- Internal reserves instead of balanceOf for removeLiquidity
- sync() function for donation recovery
- SafeERC20 for all transfers
- Comprehensive tests: 18 cases covering all acceptance criteria
  - First deposit lock verification
  - First-depositor manipulation prevention
  - Internal reserves for removeLiquidity
  - Sync event emission
  - Asymmetric deposits
  - Edge cases: boundary values, insufficient LP
- Contributor verification: _generation.json
@Vincent1-p Vincent1-p closed this Jun 2, 2026
@Vincent1-p Vincent1-p force-pushed the fix/liquiditypool-first-depositor-918 branch from 5dd77fd to 201c2b4 Compare June 2, 2026 21:30
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.

[ Crypto ] Fix first-depositor price manipulation in LiquidityPool

1 participant