> For the complete documentation index, see [llms.txt](https://docs.optimumsec.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.optimumsec.xyz/design/funds-isolation.md).

# Design for Funds Isolation

Pooling user funds in a single contract is a common approach in decentralized applications. While efficient, this design introduces significant risk—if a vulnerability exists in the accounting logic, attackers can potentially compromise the entire pool.

To mitigate this risk, designing smart contracts with **funds isolation** in mind is a critical security best practice. By isolating funds at the contract level, you can minimize the impact of potential exploits.

***

## Benefits of Funds Isolation

* **Reduced Attack Surface:** Exploits affecting one contract cannot spread to others.
* **Enhanced Security:** Logical isolation ensures that vulnerabilities in one part of the system don't jeopardize the entire protocol.
* **Improved Risk Management:** Limits the scale of financial losses in case of an exploit.

***

## Examples of Funds Isolation

### 1. **Vesting Allocations**

Instead of pooling all recipients' allocations in a single contract:

* **Isolated Design:** Create a unique contract instance for each recipient with their pre-allocated amount.
* **Security Benefit:** If a vulnerability exists in the vesting logic, it will only affect one recipient's contract, not the entire pool.

To implement funds isolation in vesting contracts, you can use **reference implementations** such as [OpenZeppelin's finance contracts](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/finance) as a foundation.

### 2. **Separated Liquidity Pools**

In decentralized exchanges (DEXs):

* **Isolated Design:** Deploy a separate contract for each token pair (e.g., ETH/USDC or DAI/USDT).
* **Security Benefit:** If an exploit occurs, only the affected pair's liquidity is at risk, limiting the impact on the rest of the protocol.

***

## Trade-Offs of Isolation

While funds isolation provides strong security benefits, it introduces additional complexities:

* **Maintenance Overhead:** Each isolated contract may need individual updates, increasing administrative effort.
* **Higher Gas Costs:** Deploying multiple contracts can lead to higher deployment and operational costs.
