- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control. - Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities. - Created .gitmodules to include OpenZeppelin contracts as a submodule. - Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment. - Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks. - Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring. - Created scripts for resource import and usage validation across non-US regions. - Added tests for CCIP error handling and integration to ensure robust functionality. - Included various new files and directories for the orchestration portal and deployment scripts.
3.3 KiB
3.3 KiB
Smart CREATE2 Deployment Guide
Overview
Instead of brute-forcing salts, we use Foundry's impersonation features and direct salt calculation to deploy contracts to exact addresses from genesis.json.
Key Insights
- Foundry Impersonation: Use
vm.startBroadcast(address)to impersonate any address (even if we don't have the private key) - Salt Calculation: Since addresses are in genesis.json, we can calculate the salt for known deployers
- No Brute Force Needed: Try common salts first (0, 1, chain ID, contract name, etc.)
Why This Works Better
Old Approach (Brute Force)
- ❌ Tries thousands of salt values
- ❌ Slow and gas-intensive
- ❌ May never find the correct salt
New Approach (Smart Calculation)
- ✅ Tries common salts first (instant)
- ✅ Uses Foundry's impersonation (no private key needed)
- ✅ Leverages the fact that addresses are pre-allocated in genesis.json
Usage
Option 1: Use the Smart Script
# Deploy WETH9
forge script script/DeployWETH9Smart.s.sol:DeployWETH9Smart \
--rpc-url http://localhost:8545 \
--broadcast \
--sender <deployer-address> \
--legacy
Note: When using --sender, Foundry will impersonate that address using vm.startBroadcast(address).
Option 2: Calculate Parameters First
Run the calculation script to find the salt:
./scripts/deployment/calculate-create2-parameters.sh
This will output the deployer address and salt needed, which you can then use in your deployment script.
How It Works
Step 1: Identify Potential Deployers
Since the addresses are in genesis.json, likely deployers are:
- Standard CREATE2 deployer (
0x4e59b44847b379578588920cA78FbF26c0B4956C) - Genesis addresses (those with high balances in genesis.json)
- CREATE2Factory address (if one exists)
Step 2: Calculate Salt for Each Deployer
For each potential deployer, try common salts:
0(zero)1(one)138(chain ID)keccak256("WETH9")orkeccak256("WETH10")keccak256("Wrapped Ether")- Address-specific values
Step 3: Impersonate and Deploy
Once we find the correct deployer/salt combination:
- Use
vm.startBroadcast(deployerAddress)to impersonate - Deploy using CREATE2 with the calculated salt
- Verify the deployed address matches the target
Example
// Impersonate the CREATE2 deployer (no private key needed!)
vm.startBroadcast(CREATE2_DEPLOYER);
// Deploy with calculated salt
address deployed = deployCreate2(bytecode, calculatedSalt);
// Verify
require(deployed == TARGET_WETH9, "Address mismatch!");
Benefits
- Faster: Common salts are checked instantly
- No Private Keys Needed: Uses Foundry's impersonation
- More Reliable: Leverages genesis.json information
- Gas Efficient: Only deploys once, doesn't try thousands of salts
Limitations
- If the deployer is unknown or uses an unusual salt, we still need to search
- CREATE2 is a one-way function, so we can't directly reverse it
- Some salts may require sequential search (limited to first 1000)