<!-- canonical: https://0xsimao.com/findings/trestle-initialize-revert-already-exists -->

# createAmmPairWith() in initialize() will revert if the pair already exists

Medium · Three Sigma · Modular blockchain infrastructure · 27th January 2024

Finding 3S-TR-M04 of the Trestle wTIA Bridge security review.

- Report: /reports/trestle-wtia-bridge
- Source: https://github.com/0xsimao/audits/blob/main/Three%20Sigma/2024-01-27-trestle.pdf

---

### Description

[createAmmPairWith()](https://github.com/TrestleProtocol/Audit-Contracts/blob/main/src/Trestle.sol#L435) in initialize() reverts if the pair exists, which means that the
contract could be DoSed.

### Recommendation

Check if the pair already exists and skip creating if it does. However, this would make
[addLiquidityETH()](https://github.com/TrestleProtocol/Audit-Contracts/blob/main/src/Trestle.sol#L441) vulnerable to slippage, so introduce slippage control arguments.

### Status

Protocol already deployed.

Disclosed by 0xSimao (https://0xsimao.com/).

---

Related findings:

- [BasicVaultFactory::createVault() inconsistent already existing vault check](https://0xsimao.com/findings/mitosis-create-inconsistent-already-existing): Mitosis
- [updateGroupCollateral() should revert if the _pairIndex does not exist](https://0xsimao.com/findings/ostium-collateral-revert-index-exist): Ostium
- [Setting note commitments, nullifiers and note footers used should revert if they are already set to prevent exploits](https://0xsimao.com/findings/singularity-commitments-nullifiers-footers-revert): Singularity
- [Notional difference in AmmRouter:removeLiquidty() may revert in certain cases](https://0xsimao.com/findings/nftperp-ii-notional-difference-liquidty-revert): Nftperp Matching Engine
