# Genesis.json and .env Review: WETH Bridge Configuration

**Date**: 2025-01-27  
**Purpose**: Review genesis.json and .env configuration for WETH contract addresses on ChainID 138

---

## Executive Summary

### Key Finding: Address Confusion Resolved

There is **confusion between WETH contract addresses and Bridge contract addresses**:

1. **WETH9 Contract**: Should be at canonical address `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2` (predeployed in genesis.json)
2. **CCIPWETH9Bridge Contract**: Deployed at `0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6` (this is the BRIDGE, not WETH!)

The `address-mapping.json` file incorrectly maps WETH9 to the bridge address, causing confusion.

---

## Genesis.json Analysis

### File: `smom-dbis-138/config/genesis.json`

#### WETH9 Predeployment ✅

```json
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": {
  "balance": "0x0",
  "code": "0x6060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b9578063095ea7b31461014757806318160ddd146101a157806323b872dd14610243578063313ce5671461026657806370a082311461029557806395d89b41146102e2578063a9059cbb14610370578063d0e30db0146103ca578063dd62ed3e146103d4575b6100b7610440565b005b..."
}
```

**Status**: ✅ **WETH9 IS predeployed at canonical address**
- **Address**: `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`
- **Bytecode**: Present (runtime bytecode included)
- **Balance**: `0x0` (no initial ETH balance)

#### WETH10 Predeployment ✅

```json
"0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f": {
  "balance": "0x0",
  "code": " ..."
}
```

**Status**: ✅ **WETH10 IS predeployed at canonical address**
- **Address**: `0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f`
- **Bytecode**: Present (runtime bytecode included)
- **Balance**: `0x0` (no initial ETH balance)

---

## .env Configuration Analysis

### File: `smom-dbis-138/terraform/phases/phase1/config/env.chain138.template`

```bash
# Tokens (deterministic same addresses as mainnet)
WETH9_ADDRESS=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
WETH10_ADDRESS=0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f

# Bridges on Chain 138 (same addresses as mainnet, but different deployment)
CCIPWETH9_BRIDGE_CHAIN138=0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6
CCIPWETH10_BRIDGE_CHAIN138=0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e
```

**Status**: ✅ **Configuration is CORRECT**
- WETH9 address matches canonical address from genesis.json
- Bridge addresses are separate (correctly identified as bridges)

---

## Address Mapping Analysis

### File: `smom-dbis-138/config/address-mapping.json`

```json
{
  "WETH9": {
    "genesisAddress": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    "deployedAddress": "0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6",
    "reason": "Genesis address is Ethereum mainnet WETH9 (deployed with CREATE, not CREATE2). Cannot recreate with CREATE2.",
    "status": "mapped"
  }
}
```

**⚠️ ISSUE FOUND**: This mapping is **INCORRECT**

**Problem**: The `deployedAddress` (`0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6`) is actually the **CCIPWETH9Bridge** contract address, NOT the WETH9 contract address!

**Evidence**:
- From `env.chain138.template`: `CCIPWETH9_BRIDGE_CHAIN138=0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6`
- From `genesis.json`: WETH9 is predeployed at `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2` with bytecode

**Correct Mapping Should Be**:
```json
{
  "WETH9": {
    "genesisAddress": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    "deployedAddress": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",  // Same - predeployed in genesis
    "reason": "Predeployed in genesis.json at canonical address",
    "status": "predeployed"
  },
  "CCIPWETH9Bridge": {
    "genesisAddress": "0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6",
    "deployedAddress": "0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6",
    "reason": "Bridge contract deployed separately",
    "status": "deployed"
  }
}
```

---

## Verification Results

### WETH9 at Canonical Address

| Check | Status | Details |
|-------|--------|---------|
| Genesis predeployment | ✅ | Bytecode present in genesis.json |
| Address | ✅ | `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2` |
| .env configuration | ✅ | Correctly configured |
| Address mapping | ⚠️ | Incorrectly maps to bridge address |

### WETH10 at Canonical Address

| Check | Status | Details |
|-------|--------|---------|
| Genesis predeployment | ✅ | Bytecode present in genesis.json |
| Address | ✅ | `0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f` |
| .env configuration | ✅ | Correctly configured |

### Bridge Contracts

| Contract | Address | Status |
|----------|---------|--------|
| CCIPWETH9Bridge | `0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6` | ✅ Deployed (separate from WETH) |
| CCIPWETH10Bridge | `0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e` | ✅ Deployed (separate from WETH) |

---

## Corrected Understanding

### WETH Contracts

**WETH9**:
- **Canonical Address**: `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`
- **Status**: ✅ **Predeployed in genesis.json**
- **Bytecode**: ✅ Present in genesis.json
- **Should exist on-chain**: ✅ Yes

**WETH10**:
- **Canonical Address**: `0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f`
- **Status**: ✅ **Predeployed in genesis.json**
- **Bytecode**: ✅ Present in genesis.json
- **Should exist on-chain**: ✅ Yes

### Bridge Contracts

**CCIPWETH9Bridge**:
- **Address**: `0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6`
- **Status**: ✅ Deployed separately (not in genesis)
- **Purpose**: Bridge contract for WETH9 cross-chain transfers

**CCIPWETH10Bridge**:
- **Address**: `0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e`
- **Status**: ✅ Deployed separately (not in genesis)
- **Purpose**: Bridge contract for WETH10 cross-chain transfers

---

## Recommendations

### 1. Fix address-mapping.json

The `address-mapping.json` file incorrectly maps WETH9 to the bridge address. It should be updated to reflect that:

- WETH9 is predeployed at the canonical address (same as genesis)
- The bridge address is a separate contract

### 2. Verify On-Chain Status

Since genesis.json shows WETH9 is predeployed, verify on-chain:

```bash
# Check WETH9 at canonical address
cast code 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 --rpc-url https://rpc-http-pub.d-bis.org

# Check bridge at bridge address
cast code 0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6 --rpc-url https://rpc-http-pub.d-bis.org
```

### 3. Update Verification Scripts

Update the verification scripts to:
- Check WETH9 at canonical address `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`
- Check bridge at bridge address `0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6`
- Clearly distinguish between WETH contracts and bridge contracts

### 4. Update Documentation

Update documentation to clarify:
- WETH contracts are predeployed at canonical addresses
- Bridge contracts are deployed separately
- The address-mapping.json was incorrect

---

## Conclusion

### Summary

1. ✅ **genesis.json is CORRECT**: WETH9 and WETH10 are predeployed at canonical addresses with bytecode
2. ✅ **.env configuration is CORRECT**: WETH addresses match canonical, bridge addresses are separate
3. ⚠️ **address-mapping.json is INCORRECT**: Maps WETH9 to bridge address instead of canonical address

### Action Items

1. **Immediate**: Verify WETH9 exists on-chain at canonical address
2. **Fix**: Update `address-mapping.json` to correct the mapping
3. **Update**: Fix verification scripts to use correct addresses
4. **Document**: Update documentation to reflect correct understanding

### For thirdweb Bridge Verification

**Use WETH9 at canonical address**: `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`

The previous verification scripts incorrectly checked the bridge address instead of the WETH address. The WETH contract should exist at the canonical address according to genesis.json.

---

**Last Updated**: 2025-01-27  
**Status**: ✅ Review Complete - Address Confusion Resolved
