generated from PaulRBerg/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathverify-deployments.ts
More file actions
281 lines (243 loc) · 9.03 KB
/
verify-deployments.ts
File metadata and controls
281 lines (243 loc) · 9.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import fs from "fs";
import { createPublicClient, http, getAddress, isAddress } from "viem";
import { mainnet, optimism, base } from "viem/chains";
interface DeploymentEntry {
name: string;
address: string;
args?: any[];
proxy?: {
admin?: string;
implementation?: string;
owner?: string;
type?: "transparent" | "uups" | "custom";
};
}
interface DeploymentData {
[contractName: string]: DeploymentEntry;
}
interface ChainConfig {
id: number;
name: string;
client: any;
deploymentFile: string;
}
const CHAINS: ChainConfig[] = [
{
id: 1,
name: "Ethereum",
client: createPublicClient({ chain: mainnet, transport: http() }),
deploymentFile: "evm/deployments/1.json",
},
{
id: 10,
name: "OP Mainnet",
client: createPublicClient({ chain: optimism, transport: http() }),
deploymentFile: "evm/deployments/10.json",
},
{
id: 8453,
name: "Base",
client: createPublicClient({ chain: base, transport: http() }),
deploymentFile: "evm/deployments/8453.json",
},
];
// Contract display names (consistent with generate-deployment-docs.ts)
const CONTRACT_DISPLAY_NAMES: Record<string, string> = {
WCT: "WCT Token",
L2WCT: "L2WCT Token",
AdminTimelock: "Admin Timelock",
ManagerTimelock: "Manager Timelock",
NttManager: "NTT Manager",
NttTransceiver: "NTT Transceiver",
LockedTokenStakerBackers: "LockedTokenStaker Backers",
LockedTokenStakerReown: "LockedTokenStaker Reown",
LockedTokenStakerWalletConnect: "LockedTokenStaker WalletConnect",
MerkleVesterBackers: "MerkleVester Backers",
MerkleVesterReown: "MerkleVester Reown",
MerkleVesterWalletConnect: "MerkleVester WalletConnect",
StakingRewardsCalculator: "StakingRewardCalculator",
};
// EIP-1967 storage slots
const EIP1967_IMPLEMENTATION_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
const EIP1967_ADMIN_SLOT = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
async function loadDeploymentData(filePath: string): Promise<DeploymentData | null> {
try {
if (!fs.existsSync(filePath)) {
console.warn(`⚠️ Deployment file not found: ${filePath}`);
return null;
}
const data = fs.readFileSync(filePath, "utf8");
return JSON.parse(data);
} catch (error) {
console.error(`❌ Error reading ${filePath}:`, error);
return null;
}
}
function getContractDisplayName(contractName: string): string {
return CONTRACT_DISPLAY_NAMES[contractName] || contractName;
}
async function getStorageSlot(client: any, address: string, slot: string): Promise<string | null> {
try {
const result = await client.getStorageAt({
address: address as `0x${string}`,
slot: slot as `0x${string}`,
});
if (!result || result === "0x0000000000000000000000000000000000000000000000000000000000000000") {
return null;
}
// Extract address from storage slot (last 20 bytes)
const addressHex = result.slice(-40);
return getAddress(`0x${addressHex}`);
} catch (error) {
console.error(`Error reading storage slot for ${address}:`, error);
return null;
}
}
async function verifyContract(client: any, chainName: string, contractName: string, deployment: DeploymentEntry) {
const displayName = getContractDisplayName(contractName);
console.log(`\n🔍 Verifying ${displayName} on ${chainName}...`);
if (!isAddress(deployment.address)) {
console.error(`❌ Invalid address format: ${deployment.address}`);
return false;
}
// Check if contract exists
try {
const code = await client.getBytecode({ address: deployment.address });
if (!code || code === "0x") {
console.error(`❌ No contract code found at ${deployment.address}`);
return false;
}
console.log(`✅ Contract exists at ${deployment.address}`);
} catch (error) {
console.error(`❌ Error checking contract existence:`, error);
return false;
}
// Check proxy configuration if proxy metadata exists
if (deployment.proxy) {
console.log(`🔧 Checking proxy configuration...`);
// Get implementation address
const implementation = await getStorageSlot(client, deployment.address, EIP1967_IMPLEMENTATION_SLOT);
if (!implementation) {
console.error(`❌ No implementation found in EIP-1967 slot`);
return false;
}
console.log(`✅ Implementation: ${implementation}`);
// Verify implementation matches
if (
deployment.proxy.implementation &&
implementation.toLowerCase() !== deployment.proxy.implementation.toLowerCase()
) {
console.error(`❌ Implementation mismatch!`);
console.error(` Expected: ${deployment.proxy.implementation}`);
console.error(` Actual: ${implementation}`);
return false;
}
// Check admin for transparent proxies
if (deployment.proxy.admin) {
const admin = await getStorageSlot(client, deployment.address, EIP1967_ADMIN_SLOT);
if (!admin) {
console.error(`❌ No admin found in EIP-1967 slot`);
return false;
}
if (admin.toLowerCase() !== deployment.proxy.admin.toLowerCase()) {
console.error(`❌ ProxyAdmin mismatch!`);
console.error(` Expected: ${deployment.proxy.admin}`);
console.error(` Actual: ${admin}`);
return false;
}
console.log(`✅ ProxyAdmin verified: ${admin}`);
}
// Check owner for UUPS proxies
if (deployment.proxy.owner) {
try {
const result = await client.readContract({
address: deployment.address as `0x${string}`,
abi: [
{ inputs: [], name: "owner", outputs: [{ type: "address" }], stateMutability: "view", type: "function" },
],
functionName: "owner",
});
const owner = result as string;
if (owner.toLowerCase() !== deployment.proxy.owner.toLowerCase()) {
console.error(`❌ Owner mismatch!`);
console.error(` Expected: ${deployment.proxy.owner}`);
console.error(` Actual: ${owner}`);
return false;
}
console.log(`✅ Owner verified: ${owner}`);
} catch (error) {
console.error(`❌ Error reading owner():`, error);
return false;
}
}
} else {
// For non-proxy contracts, check that they don't have proxy storage
const implementation = await getStorageSlot(client, deployment.address, EIP1967_IMPLEMENTATION_SLOT);
if (implementation) {
console.warn(`⚠️ Contract appears to be a proxy but is marked as non-proxy`);
console.warn(` Implementation found: ${implementation}`);
} else {
console.log(`✅ Confirmed non-proxy contract`);
}
}
return true;
}
async function verifyChain(chainConfig: ChainConfig) {
console.log(`\n🌐 === Verifying ${chainConfig.name} (Chain ID: ${chainConfig.id}) ===`);
const deploymentData = await loadDeploymentData(chainConfig.deploymentFile);
if (!deploymentData) {
console.error(`❌ Could not load deployment data for ${chainConfig.name}`);
return false;
}
const results: { contractName: string; success: boolean }[] = [];
// Filter out chainId and verify contracts
const contracts = Object.entries(deploymentData).filter(([name]) => name !== "chainId");
for (const [contractName, deployment] of contracts) {
const success = await verifyContract(chainConfig.client, chainConfig.name, contractName, deployment);
results.push({ contractName, success });
}
const successCount = results.filter((r) => r.success).length;
const totalCount = results.length;
console.log(`\n📊 ${chainConfig.name} Results: ${successCount}/${totalCount} contracts verified successfully`);
if (successCount < totalCount) {
console.log(`❌ Failed contracts:`);
results
.filter((r) => !r.success)
.forEach((r) => {
console.log(` - ${getContractDisplayName(r.contractName)}`);
});
}
return successCount === totalCount;
}
async function main() {
console.log("🚀 Starting deployment verification...");
console.log("📋 This script will verify:");
console.log(" • Contract existence at documented addresses");
console.log(" • Proxy admin addresses for proxy contracts");
console.log(" • Implementation addresses for proxy contracts");
try {
const results: { chain: string; success: boolean }[] = [];
for (const chainConfig of CHAINS) {
const success = await verifyChain(chainConfig);
results.push({ chain: chainConfig.name, success });
}
// Final summary
console.log("\n🎯 === FINAL SUMMARY ===");
for (const result of results) {
console.log(`${result.chain}: ${result.success ? "✅ PASSED" : "❌ FAILED"}`);
}
const allPassed = results.every((r) => r.success);
if (allPassed) {
console.log("\n🎉 All deployments verified successfully!");
process.exit(0);
} else {
console.log("\n💥 Some verifications failed. Please check the logs above.");
process.exit(1);
}
} catch (error) {
console.error("💥 Fatal error during verification:", error);
process.exit(1);
}
}
// Run the verification
main().catch(console.error);