# Impossible to open a position with a large marginTo

ParticlePositionManager.openPosition underflows when marginTo exceeds collateralTo minus borrowed amount, reverting and blocking large-margin positions.

- Payout: Contest reward
- Severity: medium
- Program: Particle Protocol
- Credited: immeas
- Disclosed: 2024-01-26
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2023-12-particle-findings/issues/44
- Library page: https://bugbountylibrary.com/r/c4%3A2023-12-particle%3AM-07
- Tags: domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:business-logic

**Target:** ParticlePositionManager.openPosition swap minimum-amount calculation
**Root cause:** The minimum swap output is computed as collateralTo - amountToBorrowed - marginTo; when marginTo exceeds collateralTo - amountToBorrowed the subtraction underflows and reverts.
**Steps:**
1. Call `openPosition` with `marginTo = requiredEth - amount1ToBorrow + 1` (i.e. greater than collateralTo - amountToBorrowed)
2. Approve USDC and WETH to particlePositionManager
3. Observe revert with arithmetic underflow at line 212 before reaching the swap
**How found:** Code reading of the amountToMinimum calculation in openPosition; noticed marginTo is subtracted from collateralTo - amountToBorrowed, implying an upper bound, then wrote a Foundry test supplying marginTo one wei above that bound to confirm the underflow revert.
**Insight:** When a parameter is subtracted inside a minimum-output/requirement formula, check whether it is actually part of the swap input; a premium/safety margin should not reduce expected swap output, and values above the remaining collateral will underflow.
