# Error Handling Guide

## Overview

This guide explains common errors in the trustless bridge system and how to resolve them.

## Common Errors

### Deposit Errors

#### ZeroAmount
**Error**: `ZeroAmount()`
**Cause**: Attempting to deposit zero amount
**Solution**: Ensure deposit amount > 0

#### ZeroRecipient
**Error**: `ZeroRecipient()`
**Cause**: Recipient address is zero
**Solution**: Provide valid recipient address

#### DepositAlreadyProcessed
**Error**: `DepositAlreadyProcessed()`
**Cause**: Deposit ID already used
**Solution**: Use unique nonce for each deposit

### Claim Errors

#### InsufficientBond
**Error**: `InsufficientBond()`
**Cause**: Bond amount less than required
**Solution**: Calculate required bond: `max(depositAmount * 1.1, 1 ETH)`

#### ClaimAlreadyExists
**Error**: `ClaimAlreadyExists()`
**Cause**: Claim already submitted for deposit ID
**Solution**: Deposit ID can only be claimed once

#### ClaimNotFound
**Error**: `ClaimNotFound()`
**Cause**: Attempting to access non-existent claim
**Solution**: Verify deposit ID is correct

### Challenge Errors

#### ChallengeWindowExpired
**Error**: `ChallengeWindowExpired()`
**Cause**: Challenge window has passed
**Solution**: Submit challenge within 30 minutes

#### InvalidFraudProof
**Error**: `InvalidFraudProof()`
**Cause**: Fraud proof is invalid
**Solution**: Verify proof format and data

### Liquidity Pool Errors

#### InsufficientLiquidity
**Error**: `InsufficientLiquidity()`
**Cause**: Not enough liquidity in pool
**Solution**: Wait for more liquidity or provide liquidity

#### WithdrawalBlockedByLiquidityRatio
**Error**: `WithdrawalBlockedByLiquidityRatio()`
**Cause**: Withdrawal would violate minimum ratio (110%)
**Solution**: Wait for claims to finalize or reduce withdrawal amount

#### UnauthorizedRelease
**Error**: `UnauthorizedRelease()`
**Cause**: Contract not authorized to release funds
**Solution**: Only authorized contracts can release

## Error Codes Reference

| Error | Code | Severity | Action |
|-------|------|----------|--------|
| ZeroAmount | 0x01 | Low | Check amount |
| ZeroRecipient | 0x02 | Low | Provide recipient |
| InsufficientBond | 0x03 | Medium | Increase bond |
| ClaimNotFound | 0x04 | Medium | Verify deposit ID |
| ChallengeWindowExpired | 0x05 | Medium | Submit earlier |
| InvalidFraudProof | 0x06 | High | Verify proof |
| InsufficientLiquidity | 0x07 | High | Wait or add liquidity |
| WithdrawalBlocked | 0x08 | Medium | Wait or reduce amount |

## Recovery Procedures

### Failed Deposit

1. Check error message
2. Verify parameters
3. Retry with correct parameters
4. Contact support if persistent

### Failed Claim

1. Verify bond amount
2. Check claim doesn't exist
3. Retry with correct parameters
4. Monitor for relayer submission

### Failed Challenge

1. Verify challenge window
2. Check fraud proof format
3. Verify proof data
4. Retry if within window

## Support

- **Documentation**: `docs/bridge/trustless/`
- **Operations**: `docs/operations/`
- **Support**: [Contact Information]

## References

- Contracts: `contracts/bridge/trustless/`
- Architecture: `docs/bridge/trustless/ARCHITECTURE.md`

