# ChainID 138 Bridge Configuration Resolution

**Date**: 2025-01-18  
**Status**: 🔍 **INVESTIGATION IN PROGRESS**

## Problem Summary

ChainID 138 → Mainnet bridge configuration is failing with "Execution reverted" errors when attempting to:
- Call `getDestinationChains()` 
- Call `addDestination(uint64,address)`
- Call `ccipRouter()`, `weth9()`, `feeToken()` (immutable variables)

However:
- `admin()` call **works successfully**
- Admin address matches: `0x4A666F96fC8764181194447A7dFdb7d471b301C8`

## Investigation Findings

### Function Call Results

| Function | Status | Result |
|----------|--------|--------|
| `admin()` | ✅ Works | Returns: `0x4A666F96fC8764181194447A7dFdb7d471b301C8` |
| `ccipRouter()` | ❌ Reverts | Empty revert data |
| `weth9()` | ❌ Reverts | Empty revert data |
| `feeToken()` | ❌ Reverts | Empty revert data |
| `getDestinationChains()` | ❌ Reverts | Empty revert data |
| `addDestination()` | ❌ Reverts | Empty revert data (gas estimation) |

### Contract Analysis

- **Code Size**: 1310 bytes (not a minimal proxy)
- **Deployment**: Direct deployment (not via proxy pattern per deployment script)
- **Contract Source**: `CCIPWETH9Bridge.sol` / `CCIPWETH10Bridge.sol`

### Key Observations

1. **Only `admin()` works**: This is the only mutable variable that succeeds
2. **All immutable variables revert**: Suggests bytecode mismatch or different deployment
3. **Empty revert data**: Indicates `revert()` without message, or `require(false)`
4. **Possible causes**:
   - Contract was deployed with different/older version
   - Bytecode doesn't match source code
   - Contract interface changed after deployment
   - Storage layout mismatch

## Resolution Strategies

### Strategy 1: Verify Contract Bytecode

**Action**: Compare deployed bytecode with expected bytecode from source code

```bash
# Get deployed bytecode
cast code 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6 --rpc-url http://192.168.11.211:8545 > deployed.bin

# Compile source and compare
forge build
cast code <compiled_bytecode> > expected.bin

# Compare
diff deployed.bin expected.bin
```

### Strategy 2: Check Deployment History

**Action**: Search for deployment transactions and verify contract version

```bash
# Search for contract creation transaction
cast logs --from-block 0 --address 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6 \
  --rpc-url http://192.168.11.211:8545 | head -50

# Check transaction that created the contract
cast tx <deployment_tx_hash> --rpc-url http://192.168.11.211:8545
```

### Strategy 3: Check if Destinations Already Exist

**Action**: Search for `DestinationAdded` events

```bash
# Event signature: DestinationAdded(uint64,address)
cast logs --from-block 0 \
  --address 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6 \
  --topic 0x4db4426797acc64f4ffbac3f974c24bcf6fa22cc979a57405f1026a98b755db3 \
  --rpc-url http://192.168.11.211:8545
```

If events found, destinations may already be configured (explaining why `addDestination` reverts with "destination already exists").

### Strategy 4: Use Alternative Interface

**Action**: If contract uses different interface, find actual function selectors

```bash
# Check contract bytecode for function selectors
cast code 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6 --rpc-url http://192.168.11.211:8545 | grep -i "addDestination\|getDestination"
```

### Strategy 5: Direct Storage Access

**Action**: If contract uses standard storage layout, check storage directly

```bash
# Check destinationChains array length (storage slot for array length)
# Solidity arrays store length at slot 0x...
# Would need to calculate based on storage layout
```

### Strategy 6: Check for Upgrade Pattern

**Action**: Verify if contract was upgraded and check implementation

```bash
# Check for EIP-1967 implementation slot
IMPL_SLOT="0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
cast storage 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6 $IMPL_SLOT \
  --rpc-url http://192.168.11.211:8545
```

## Recommended Next Steps

1. ✅ **Check for existing DestinationAdded events** (Strategy 3)
2. ⏳ **Verify contract bytecode matches source** (Strategy 1)
3. ⏳ **Check deployment transaction history** (Strategy 2)
4. ⏳ **Attempt alternative function signatures** (Strategy 4)

## Current Status

- ✅ Investigation scripts created
- ✅ Function testing complete
- ⏳ Event log search in progress
- ⏳ Bytecode verification pending

---

**Next Action**: Complete event log search to determine if destinations already exist.
