gate-evm-tools 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -5
- package/bin/manifest-bootstrap.js +109 -3
- package/dist/commands/prepare.d.ts +8 -0
- package/dist/commands/prepare.d.ts.map +1 -0
- package/dist/commands/prepare.js +78 -0
- package/dist/commands/prepare.js.map +1 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +11 -28
- package/dist/commands/sync.js.map +1 -1
- package/dist/core/preparation/artifacts.d.ts +21 -0
- package/dist/core/preparation/artifacts.d.ts.map +1 -0
- package/dist/core/preparation/artifacts.js +80 -0
- package/dist/core/preparation/artifacts.js.map +1 -0
- package/dist/core/preparation/evm.d.ts +39 -0
- package/dist/core/preparation/evm.d.ts.map +1 -0
- package/dist/core/preparation/evm.js +290 -0
- package/dist/core/preparation/evm.js.map +1 -0
- package/dist/core/preparation/index.d.ts +9 -0
- package/dist/core/preparation/index.d.ts.map +1 -0
- package/dist/core/preparation/index.js +15 -0
- package/dist/core/preparation/index.js.map +1 -0
- package/dist/core/preparation/manifest.d.ts +43 -0
- package/dist/core/preparation/manifest.d.ts.map +1 -0
- package/dist/core/preparation/manifest.js +169 -0
- package/dist/core/preparation/manifest.js.map +1 -0
- package/dist/core/preparation/normalize.d.ts +7 -0
- package/dist/core/preparation/normalize.d.ts.map +1 -0
- package/dist/core/preparation/normalize.js +496 -0
- package/dist/core/preparation/normalize.js.map +1 -0
- package/dist/core/preparation/types.d.ts +111 -0
- package/dist/core/preparation/types.d.ts.map +1 -0
- package/dist/core/preparation/types.js +2 -0
- package/dist/core/preparation/types.js.map +1 -0
- package/dist/core/preparation/zkManifestSync.d.ts +49 -0
- package/dist/core/preparation/zkManifestSync.d.ts.map +1 -0
- package/dist/core/preparation/zkManifestSync.js +159 -0
- package/dist/core/preparation/zkManifestSync.js.map +1 -0
- package/dist/core/preparation/zkUpgradeValidation.d.ts +37 -0
- package/dist/core/preparation/zkUpgradeValidation.d.ts.map +1 -0
- package/dist/core/preparation/zkUpgradeValidation.js +91 -0
- package/dist/core/preparation/zkUpgradeValidation.js.map +1 -0
- package/dist/core/preparation/zksync.d.ts +28 -0
- package/dist/core/preparation/zksync.d.ts.map +1 -0
- package/dist/core/preparation/zksync.js +248 -0
- package/dist/core/preparation/zksync.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/sync/index.d.ts +31 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +57 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/workflow/index.d.ts +5 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +3 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist-cjs/core/preparation/artifacts.js +89 -0
- package/dist-cjs/core/preparation/artifacts.js.map +1 -0
- package/dist-cjs/core/preparation/evm.js +297 -0
- package/dist-cjs/core/preparation/evm.js.map +1 -0
- package/dist-cjs/core/preparation/index.js +19 -0
- package/dist-cjs/core/preparation/index.js.map +1 -0
- package/dist-cjs/core/preparation/manifest.js +180 -0
- package/dist-cjs/core/preparation/manifest.js.map +1 -0
- package/dist-cjs/core/preparation/normalize.js +507 -0
- package/dist-cjs/core/preparation/normalize.js.map +1 -0
- package/dist-cjs/core/preparation/types.js +3 -0
- package/dist-cjs/core/preparation/types.js.map +1 -0
- package/dist-cjs/core/preparation/zkManifestSync.js +166 -0
- package/dist-cjs/core/preparation/zkManifestSync.js.map +1 -0
- package/dist-cjs/core/preparation/zkUpgradeValidation.js +101 -0
- package/dist-cjs/core/preparation/zkUpgradeValidation.js.map +1 -0
- package/dist-cjs/core/preparation/zksync.js +252 -0
- package/dist-cjs/core/preparation/zksync.js.map +1 -0
- package/dist-cjs/core/syncUpgradeJson.js +315 -0
- package/dist-cjs/core/syncUpgradeJson.js.map +1 -0
- package/dist-cjs/sync/index.js +60 -0
- package/dist-cjs/sync/index.js.map +1 -0
- package/dist-cjs/types.js +3 -0
- package/dist-cjs/types.js.map +1 -0
- package/dist-cjs/utils/manifestTransaction.js +302 -0
- package/dist-cjs/utils/manifestTransaction.js.map +1 -0
- package/dist-cjs/utils/openzeppelin.js +57 -0
- package/dist-cjs/utils/openzeppelin.js.map +1 -0
- package/dist-cjs/workflow/index.js +12 -0
- package/dist-cjs/workflow/index.js.map +1 -0
- package/package.json +42 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type GateToolArtifact } from './artifacts.js';
|
|
2
|
+
import { loadZkValidationCandidate, type ZkValidationCandidate, type ZkValidationHre } from './zkUpgradeValidation.js';
|
|
3
|
+
interface ZkManifestSyncHre extends ZkValidationHre {
|
|
4
|
+
run(task: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
5
|
+
artifacts: {
|
|
6
|
+
readArtifact(name: string): Promise<GateToolArtifact>;
|
|
7
|
+
};
|
|
8
|
+
ethers: {
|
|
9
|
+
provider: {
|
|
10
|
+
getNetwork(): Promise<{
|
|
11
|
+
chainId: bigint | number | string;
|
|
12
|
+
}>;
|
|
13
|
+
getCode(address: string): Promise<string>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface ZkManifestSyncOptions {
|
|
18
|
+
root?: string;
|
|
19
|
+
scheme: 'zksync-eravm';
|
|
20
|
+
network: string;
|
|
21
|
+
target: string;
|
|
22
|
+
proxy: string;
|
|
23
|
+
contract: string;
|
|
24
|
+
constructorArgs?: unknown[];
|
|
25
|
+
unsafeAllow?: string[];
|
|
26
|
+
transactionHash?: string;
|
|
27
|
+
hre: ZkManifestSyncHre;
|
|
28
|
+
}
|
|
29
|
+
export interface ZkManifestSyncDependencies {
|
|
30
|
+
loadCandidate?: (hre: ZkValidationHre, request: Parameters<typeof loadZkValidationCandidate>[1], artifact: GateToolArtifact) => Promise<ZkValidationCandidate>;
|
|
31
|
+
assertImplementationSafe?: (candidate: ZkValidationCandidate) => void;
|
|
32
|
+
getCurrentImplementation?: (hre: ZkValidationHre, proxy: string) => Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
export declare const syncZkManifest: (options: ZkManifestSyncOptions, dependencies?: ZkManifestSyncDependencies) => Promise<{
|
|
35
|
+
manifestTransaction: import("../../utils/manifestTransaction.js").ManifestTransactionReport;
|
|
36
|
+
syncReport: string;
|
|
37
|
+
scheme: "zksync-eravm";
|
|
38
|
+
network: string;
|
|
39
|
+
target: string;
|
|
40
|
+
chainId: string;
|
|
41
|
+
proxy: string;
|
|
42
|
+
implementation: string;
|
|
43
|
+
artifact: import("./types.js").GateToolArtifactIdentity;
|
|
44
|
+
layoutHash: string;
|
|
45
|
+
manifestDigest: string;
|
|
46
|
+
manifestFile: string;
|
|
47
|
+
}>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=zkManifestSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zkManifestSync.d.ts","sourceRoot":"","sources":["../../../src/core/preparation/zkManifestSync.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAGL,yBAAyB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,0BAA0B,CAAC;AAGlC,UAAU,iBAAkB,SAAQ,eAAe;IACjD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvE,SAAS,EAAE;QAAE,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;KAAE,CAAC;IACrE,MAAM,EAAE;QACN,QAAQ,EAAE;YACR,UAAU,IAAI,OAAO,CAAC;gBAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;aAAE,CAAC,CAAC;YAC7D,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC3C,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,iBAAiB,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,CACd,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,EACxD,QAAQ,EAAE,gBAAgB,KACvB,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACpC,wBAAwB,CAAC,EAAE,CAAC,SAAS,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACtE,wBAAwB,CAAC,EAAE,CACzB,GAAG,EAAE,eAAe,EACpB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAmDD,eAAO,MAAM,cAAc,GACzB,SAAS,qBAAqB,EAC9B,eAAc,0BAA+B;;;;;;;;;;;;;EA0H9C,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { getAddress, hexlify } from 'ethers';
|
|
5
|
+
import { utils } from 'zksync-ethers';
|
|
6
|
+
import { artifactIdentity, assertArtifactScheme, } from './artifacts.js';
|
|
7
|
+
import { hashStorageLayout, parseTargetManifest, resolveTargetManifestPaths, } from './manifest.js';
|
|
8
|
+
import { assertZkImplementationSafe, getZkCurrentImplementation, loadZkValidationCandidate, } from './zkUpgradeValidation.js';
|
|
9
|
+
import { withManifestTransaction } from '../../utils/manifestTransaction.js';
|
|
10
|
+
const bytecodeHash = (bytecode, label) => {
|
|
11
|
+
try {
|
|
12
|
+
return hexlify(utils.hashBytecode(bytecode)).toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16
|
+
throw new Error(`${label} is not valid EraVM bytecode: ${message}`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const readManifestForSync = (manifestFile, fallbackFile) => {
|
|
20
|
+
const canonicalExists = fs.existsSync(manifestFile);
|
|
21
|
+
const fallbackExists = fallbackFile !== manifestFile && fs.existsSync(fallbackFile);
|
|
22
|
+
if (!canonicalExists && !fallbackExists) {
|
|
23
|
+
return { manifestVersion: '3.2', impls: {}, proxies: [] };
|
|
24
|
+
}
|
|
25
|
+
const selected = canonicalExists ? manifestFile : fallbackFile;
|
|
26
|
+
const stat = fs.lstatSync(selected);
|
|
27
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
28
|
+
throw new Error('OpenZeppelin manifest must be a regular file');
|
|
29
|
+
}
|
|
30
|
+
return parseTargetManifest(fs.readFileSync(selected));
|
|
31
|
+
};
|
|
32
|
+
const normalizeTransactionHash = (raw) => {
|
|
33
|
+
if (raw === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(raw)) {
|
|
36
|
+
throw new Error('sync transactionHash must be 32-byte hex');
|
|
37
|
+
}
|
|
38
|
+
return raw.toLowerCase();
|
|
39
|
+
};
|
|
40
|
+
const candidateRequest = (options) => ({
|
|
41
|
+
version: 1,
|
|
42
|
+
kind: 'uups-upgrade',
|
|
43
|
+
scheme: 'zksync-eravm',
|
|
44
|
+
network: options.network,
|
|
45
|
+
target: options.target,
|
|
46
|
+
contract: options.contract,
|
|
47
|
+
constructorArgs: options.constructorArgs ?? [],
|
|
48
|
+
factory: '0x0000000000000000000000000000000000000001',
|
|
49
|
+
proxyKind: 'uups',
|
|
50
|
+
proxy: options.proxy,
|
|
51
|
+
implementationSalt: `0x${'00'.repeat(31)}01`,
|
|
52
|
+
...(options.unsafeAllow ? { unsafeAllow: options.unsafeAllow } : {}),
|
|
53
|
+
});
|
|
54
|
+
export const syncZkManifest = async (options, dependencies = {}) => {
|
|
55
|
+
if (options.scheme !== 'zksync-eravm')
|
|
56
|
+
throw new Error('zkSync sync requires zksync-eravm');
|
|
57
|
+
if (options.hre.network.config?.zksync !== true) {
|
|
58
|
+
throw new Error(`Hardhat network ${options.hre.network.name} is not configured for zkSync`);
|
|
59
|
+
}
|
|
60
|
+
if (options.network !== options.hre.network.name) {
|
|
61
|
+
throw new Error(`sync network ${options.network} does not match Hardhat network ${options.hre.network.name}`);
|
|
62
|
+
}
|
|
63
|
+
if (options.target !== options.network) {
|
|
64
|
+
throw new Error('zkSync sync requires target to equal the active network');
|
|
65
|
+
}
|
|
66
|
+
const root = path.resolve(options.root ?? options.hre.config.paths.root);
|
|
67
|
+
if (root !== path.resolve(options.hre.config.paths.root)) {
|
|
68
|
+
throw new Error('sync root does not match the Hardhat project root');
|
|
69
|
+
}
|
|
70
|
+
const proxy = getAddress(options.proxy).toLowerCase();
|
|
71
|
+
const txHash = normalizeTransactionHash(options.transactionHash);
|
|
72
|
+
await options.hre.run('compile', { quiet: true });
|
|
73
|
+
const artifact = await options.hre.artifacts.readArtifact(options.contract);
|
|
74
|
+
assertArtifactScheme(artifact, 'zksync-eravm');
|
|
75
|
+
const network = await options.hre.ethers.provider.getNetwork();
|
|
76
|
+
const chainId = Number(network.chainId);
|
|
77
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0)
|
|
78
|
+
throw new Error('provider chainId is invalid');
|
|
79
|
+
const configuredChainId = options.hre.network.config?.chainId;
|
|
80
|
+
if (configuredChainId !== undefined && configuredChainId !== chainId) {
|
|
81
|
+
throw new Error(`provider chainId ${chainId} does not match configured chainId ${configuredChainId}`);
|
|
82
|
+
}
|
|
83
|
+
const request = candidateRequest(options);
|
|
84
|
+
const candidate = await (dependencies.loadCandidate ?? loadZkValidationCandidate)(options.hre, request, artifact);
|
|
85
|
+
(dependencies.assertImplementationSafe ?? assertZkImplementationSafe)(candidate);
|
|
86
|
+
if (!/^[0-9a-f]{64}$/.test(candidate.version.linkedWithoutMetadata)) {
|
|
87
|
+
throw new Error('zkSync implementation version key is invalid');
|
|
88
|
+
}
|
|
89
|
+
const implementation = getAddress(await (dependencies.getCurrentImplementation ?? getZkCurrentImplementation)(options.hre, proxy)).toLowerCase();
|
|
90
|
+
const [proxyCode, implementationCode] = await Promise.all([
|
|
91
|
+
options.hre.ethers.provider.getCode(proxy),
|
|
92
|
+
options.hre.ethers.provider.getCode(implementation),
|
|
93
|
+
]);
|
|
94
|
+
if (!proxyCode || proxyCode === '0x')
|
|
95
|
+
throw new Error(`proxy has no code at ${proxy}`);
|
|
96
|
+
if (!implementationCode || implementationCode === '0x') {
|
|
97
|
+
throw new Error(`implementation has no code at ${implementation}`);
|
|
98
|
+
}
|
|
99
|
+
const expectedHash = bytecodeHash(artifact.bytecode, 'artifact bytecode');
|
|
100
|
+
const actualHash = bytecodeHash(implementationCode, 'deployed implementation bytecode');
|
|
101
|
+
if (actualHash !== expectedHash) {
|
|
102
|
+
throw new Error(`implementation bytecode mismatch: actual=${actualHash} expected=${expectedHash}`);
|
|
103
|
+
}
|
|
104
|
+
const paths = resolveTargetManifestPaths(root, options.target, chainId);
|
|
105
|
+
const transaction = await withManifestTransaction({
|
|
106
|
+
root,
|
|
107
|
+
manifestFile: paths.file,
|
|
108
|
+
fallbackFile: paths.fallbackFile,
|
|
109
|
+
operation: async ({ manifestFile, fallbackFile, writeManifestAtomic }) => {
|
|
110
|
+
const manifest = readManifestForSync(manifestFile, fallbackFile);
|
|
111
|
+
const versionKey = candidate.version.linkedWithoutMetadata;
|
|
112
|
+
const existing = manifest.impls[versionKey];
|
|
113
|
+
if (existing && hashStorageLayout(existing.layout) !== hashStorageLayout(candidate.layout)) {
|
|
114
|
+
throw new Error('registered implementation layout conflicts with compiled artifact');
|
|
115
|
+
}
|
|
116
|
+
const priorAddresses = existing
|
|
117
|
+
? [existing.address, ...(existing.allAddresses ?? [])]
|
|
118
|
+
: [];
|
|
119
|
+
const allAddresses = [...new Set([...priorAddresses, implementation].map((address) => getAddress(address).toLowerCase()))];
|
|
120
|
+
manifest.impls[versionKey] = {
|
|
121
|
+
address: implementation,
|
|
122
|
+
...(txHash ? { txHash } : {}),
|
|
123
|
+
layout: candidate.layout,
|
|
124
|
+
...(allAddresses.length > 1 ? { allAddresses } : {}),
|
|
125
|
+
};
|
|
126
|
+
manifest.proxies = manifest.proxies.filter((entry) => entry.address.toLowerCase() !== proxy);
|
|
127
|
+
manifest.proxies.push({ address: proxy, kind: 'uups' });
|
|
128
|
+
if (fallbackFile !== manifestFile && fs.existsSync(fallbackFile))
|
|
129
|
+
fs.unlinkSync(fallbackFile);
|
|
130
|
+
writeManifestAtomic(Buffer.from(`${JSON.stringify(manifest, null, 2)}\n`));
|
|
131
|
+
const verified = parseTargetManifest(fs.readFileSync(manifestFile));
|
|
132
|
+
if (verified.impls[versionKey]?.address.toLowerCase() !== implementation) {
|
|
133
|
+
throw new Error('implementation registration post-condition failed');
|
|
134
|
+
}
|
|
135
|
+
const registeredProxy = verified.proxies.find((entry) => entry.address.toLowerCase() === proxy);
|
|
136
|
+
if (registeredProxy?.kind !== 'uups') {
|
|
137
|
+
throw new Error('proxy registration post-condition failed');
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
scheme: 'zksync-eravm',
|
|
141
|
+
network: options.network,
|
|
142
|
+
target: options.target,
|
|
143
|
+
chainId: chainId.toString(10),
|
|
144
|
+
proxy,
|
|
145
|
+
implementation,
|
|
146
|
+
artifact: artifactIdentity(artifact, 'zksync-eravm'),
|
|
147
|
+
layoutHash: hashStorageLayout(candidate.layout),
|
|
148
|
+
manifestDigest: crypto.createHash('sha256').update(fs.readFileSync(manifestFile)).digest('hex'),
|
|
149
|
+
manifestFile,
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
...transaction.value,
|
|
155
|
+
manifestTransaction: transaction.report,
|
|
156
|
+
syncReport: transaction.reportFile,
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=zkManifestSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zkManifestSync.js","sourceRoot":"","sources":["../../../src/core/preparation/zkManifestSync.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,0BAA0B,GAE3B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,GAG1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAuC7E,MAAM,YAAY,GAAG,CAAC,QAAgB,EAAE,KAAa,EAAU,EAAE;IAC/D,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC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AAC,WAAW,EAAE,KAAK,cAAc,EAAE,CAAC;gBACzE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACvE,CAAC;YACD,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAC3C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK,CACjD,CAAC;YACF,IAAI,eAAe,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;gBACrC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAC9D,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,cAAuB;gBAC/B,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7B,KAAK;gBACL,cAAc;gBACd,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EAAE,cAAc,CAAC;gBACpD,UAAU,EAAE,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC;gBAC/C,cAAc,EAAE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC/F,YAAY;aACb,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW,CAAC,KAAK;QACpB,mBAAmB,EAAE,WAAW,CAAC,MAAM;QACvC,UAAU,EAAE,WAAW,CAAC,UAAU;KACnC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getChainId, type StorageLayout, type ValidationDataCurrent, type ValidationOptions, type Version } from '@openzeppelin/upgrades-core';
|
|
2
|
+
import { type GateToolArtifact } from './artifacts.js';
|
|
3
|
+
import type { GateToolUupsInitialValidation, GateToolUupsPlaceholderDeployRequestV1, GateToolUupsUpgradeRequestV1, GateToolUupsUpgradeValidation } from './types.js';
|
|
4
|
+
export interface ZkValidationHre {
|
|
5
|
+
config: {
|
|
6
|
+
paths: {
|
|
7
|
+
root: string;
|
|
8
|
+
cache: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
network: {
|
|
12
|
+
name: string;
|
|
13
|
+
config?: {
|
|
14
|
+
zksync?: boolean;
|
|
15
|
+
chainId?: number;
|
|
16
|
+
};
|
|
17
|
+
provider: Parameters<typeof getChainId>[0];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ZkValidationCandidate {
|
|
21
|
+
validations: ValidationDataCurrent;
|
|
22
|
+
version: Version;
|
|
23
|
+
layout: StorageLayout;
|
|
24
|
+
validationOptions: Required<ValidationOptions>;
|
|
25
|
+
}
|
|
26
|
+
type ZkUupsRequest = GateToolUupsPlaceholderDeployRequestV1 | GateToolUupsUpgradeRequestV1;
|
|
27
|
+
export interface ZkValidationDependencies {
|
|
28
|
+
loadCandidate?: (hre: ZkValidationHre, request: ZkUupsRequest, artifact: GateToolArtifact) => Promise<ZkValidationCandidate>;
|
|
29
|
+
assertImplementationSafe?: (candidate: ZkValidationCandidate) => void;
|
|
30
|
+
getCurrentImplementation?: (hre: ZkValidationHre, proxy: string) => Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
export declare const loadZkValidationCandidate: (hre: ZkValidationHre, request: ZkUupsRequest, artifact: GateToolArtifact) => Promise<ZkValidationCandidate>;
|
|
33
|
+
export declare const assertZkImplementationSafe: (candidate: ZkValidationCandidate) => void;
|
|
34
|
+
export declare const getZkCurrentImplementation: (hre: ZkValidationHre, proxy: string) => Promise<string>;
|
|
35
|
+
export declare const validateZkImplementation: (hre: ZkValidationHre, request: ZkUupsRequest, artifact: GateToolArtifact, dependencies?: ZkValidationDependencies) => Promise<GateToolUupsInitialValidation | GateToolUupsUpgradeValidation>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=zkUpgradeValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zkUpgradeValidation.d.ts","sourceRoot":"","sources":["../../../src/core/preparation/zkUpgradeValidation.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,UAAU,EAMV,KAAK,aAAa,EAElB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACb,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAK7E,OAAO,KAAK,EACV,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,6BAA6B,EAC9B,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACnD,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,OAAO,CAAC;YAAC,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAChD,QAAQ,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;KAC5C,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,qBAAqB,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;IACtB,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;CAChD;AAED,KAAK,aAAa,GACd,sCAAsC,GACtC,4BAA4B,CAAC;AAEjC,MAAM,WAAW,wBAAwB;IACvC,aAAa,CAAC,EAAE,CACd,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,gBAAgB,KACvB,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACpC,wBAAwB,CAAC,EAAE,CACzB,SAAS,EAAE,qBAAqB,KAC7B,IAAI,CAAC;IACV,wBAAwB,CAAC,EAAE,CACzB,GAAG,EAAE,eAAe,EACpB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAoBD,eAAO,MAAM,yBAAyB,GACpC,KAAK,eAAe,EACpB,SAAS,aAAa,EACtB,UAAU,gBAAgB,KACzB,OAAO,CAAC,qBAAqB,CAoB/B,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,WAAW,qBAAqB,KAAG,IAE7E,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,KAAK,eAAe,EACpB,OAAO,MAAM,KACZ,OAAO,CAAC,MAAM,CAA0D,CAAC;AAQ5E,eAAO,MAAM,wBAAwB,GACnC,KAAK,eAAe,EACpB,SAAS,aAAa,EACtB,UAAU,gBAAgB,EAC1B,eAAc,wBAA6B,KAC1C,OAAO,CAAC,6BAA6B,GAAG,6BAA6B,CA6CvE,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ContractFactory, getAddress } from 'ethers';
|
|
4
|
+
import { assertStorageUpgradeSafe, assertUpgradeSafe, getChainId, getImplementationAddress, getStorageLayout, getVersion, isCurrentValidationData, withValidationDefaults, } from '@openzeppelin/upgrades-core';
|
|
5
|
+
import { assertArtifactScheme } from './artifacts.js';
|
|
6
|
+
import { hashStorageLayout, readRegisteredZkUpgradeState, } from './manifest.js';
|
|
7
|
+
const confinedValidationFile = (hre) => {
|
|
8
|
+
const root = path.resolve(hre.config.paths.root);
|
|
9
|
+
const cache = path.resolve(hre.config.paths.cache);
|
|
10
|
+
const relative = path.relative(root, cache);
|
|
11
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
12
|
+
throw new Error('Hardhat validation cache must stay inside the project root');
|
|
13
|
+
}
|
|
14
|
+
const file = path.join(cache, 'validations.json');
|
|
15
|
+
if (!fs.existsSync(file)) {
|
|
16
|
+
throw new Error('zkSync validations cache is missing; compile with the pinned Matter Labs plugin');
|
|
17
|
+
}
|
|
18
|
+
const stat = fs.lstatSync(file);
|
|
19
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
20
|
+
throw new Error('zkSync validations cache must be a regular file');
|
|
21
|
+
}
|
|
22
|
+
return file;
|
|
23
|
+
};
|
|
24
|
+
export const loadZkValidationCandidate = async (hre, request, artifact) => {
|
|
25
|
+
const file = confinedValidationFile(hre);
|
|
26
|
+
const rawValidations = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
27
|
+
if (!isCurrentValidationData(rawValidations)) {
|
|
28
|
+
throw new Error('zkSync validations cache is missing or outdated');
|
|
29
|
+
}
|
|
30
|
+
const validations = rawValidations;
|
|
31
|
+
const factory = new ContractFactory(artifact.abi, artifact.bytecode);
|
|
32
|
+
const constructorInput = factory.interface.encodeDeploy(request.constructorArgs);
|
|
33
|
+
const version = getVersion(artifact.bytecode, artifact.bytecode, constructorInput);
|
|
34
|
+
const validationOptions = withValidationDefaults({
|
|
35
|
+
kind: 'uups',
|
|
36
|
+
...(request.unsafeAllow ? { unsafeAllow: request.unsafeAllow } : {}),
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
validations,
|
|
40
|
+
version,
|
|
41
|
+
layout: getStorageLayout(validations, version),
|
|
42
|
+
validationOptions,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export const assertZkImplementationSafe = (candidate) => {
|
|
46
|
+
assertUpgradeSafe(candidate.validations, candidate.version, candidate.validationOptions);
|
|
47
|
+
};
|
|
48
|
+
export const getZkCurrentImplementation = async (hre, proxy) => getImplementationAddress(hre.network.provider, proxy);
|
|
49
|
+
const selectedChainId = async (hre) => {
|
|
50
|
+
const configured = hre.network.config?.chainId;
|
|
51
|
+
if (configured !== undefined)
|
|
52
|
+
return configured;
|
|
53
|
+
return getChainId(hre.network.provider);
|
|
54
|
+
};
|
|
55
|
+
export const validateZkImplementation = async (hre, request, artifact, dependencies = {}) => {
|
|
56
|
+
assertArtifactScheme(artifact, 'zksync-eravm');
|
|
57
|
+
if (hre.network.config?.zksync !== true) {
|
|
58
|
+
throw new Error(`Hardhat network ${hre.network.name} is not configured for zkSync`);
|
|
59
|
+
}
|
|
60
|
+
const candidate = await (dependencies.loadCandidate ?? loadZkValidationCandidate)(hre, request, artifact);
|
|
61
|
+
(dependencies.assertImplementationSafe ?? assertZkImplementationSafe)(candidate);
|
|
62
|
+
if (request.kind === 'uups-placeholder-deploy') {
|
|
63
|
+
return {
|
|
64
|
+
kind: 'uups-initial',
|
|
65
|
+
engine: 'matterlabs-openzeppelin',
|
|
66
|
+
artifactFormat: 'hh-zksolc-artifact-1',
|
|
67
|
+
implementationSafe: true,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const implementation = getAddress(await (dependencies.getCurrentImplementation ?? getZkCurrentImplementation)(hre, request.proxy)).toLowerCase();
|
|
71
|
+
const state = readRegisteredZkUpgradeState({
|
|
72
|
+
root: hre.config.paths.root,
|
|
73
|
+
target: request.target,
|
|
74
|
+
chainId: await selectedChainId(hre),
|
|
75
|
+
proxy: request.proxy,
|
|
76
|
+
currentImplementation: implementation,
|
|
77
|
+
});
|
|
78
|
+
assertStorageUpgradeSafe(state.oldLayout, candidate.layout, candidate.validationOptions);
|
|
79
|
+
return {
|
|
80
|
+
kind: 'uups-upgrade',
|
|
81
|
+
engine: 'matterlabs-openzeppelin',
|
|
82
|
+
artifactFormat: 'hh-zksolc-artifact-1',
|
|
83
|
+
implementationSafe: true,
|
|
84
|
+
storageLayoutCompatible: true,
|
|
85
|
+
currentImplementation: implementation,
|
|
86
|
+
oldLayoutHash: hashStorageLayout(state.oldLayout),
|
|
87
|
+
newLayoutHash: hashStorageLayout(candidate.layout),
|
|
88
|
+
manifestDigest: state.digest,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=zkUpgradeValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zkUpgradeValidation.js","sourceRoot":"","sources":["../../../src/core/preparation/zkUpgradeValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,UAAU,EACV,wBAAwB,EACxB,gBAAgB,EAChB,UAAU,EACV,uBAAuB,EACvB,sBAAsB,GAMvB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,oBAAoB,EAAyB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AA2CvB,MAAM,sBAAsB,GAAG,CAAC,GAAoB,EAAU,EAAE;IAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5C,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3F,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAChF,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;IAClD,IAAI,CAAC,EAAE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|
1
|
+
import { type GateToolArtifact } from './artifacts.js';
|
|
2
|
+
import type { GateToolPreparationPlanV1, GateToolPreparationRequestV1 } from './types.js';
|
|
3
|
+
import { type ZkValidationDependencies, type ZkValidationHre } from './zkUpgradeValidation.js';
|
|
4
|
+
interface ZkPreparationHre extends ZkValidationHre {
|
|
5
|
+
network: ZkValidationHre['network'] & {
|
|
6
|
+
config?: {
|
|
7
|
+
zksync?: boolean;
|
|
8
|
+
chainId?: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
artifacts: {
|
|
12
|
+
readArtifact(name: string): Promise<GateToolArtifact>;
|
|
13
|
+
};
|
|
14
|
+
ethers: {
|
|
15
|
+
provider: {
|
|
16
|
+
getNetwork(): Promise<{
|
|
17
|
+
chainId: bigint | number | string;
|
|
18
|
+
}>;
|
|
19
|
+
getCode(address: string): Promise<string>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface ZkPreparationDependencies {
|
|
24
|
+
validation?: ZkValidationDependencies;
|
|
25
|
+
}
|
|
26
|
+
export declare const prepareZkSync: (hre: ZkPreparationHre, request: GateToolPreparationRequestV1, dependencies?: ZkPreparationDependencies) => Promise<GateToolPreparationPlanV1>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=zksync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zksync.d.ts","sourceRoot":"","sources":["../../../src/core/preparation/zksync.ts"],"names":[],"mappings":"AASA,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,KAAK,EAIV,yBAAyB,EACzB,4BAA4B,EAI7B,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,eAAe,EACrB,MAAM,0BAA0B,CAAC;AAiBlC,UAAU,gBAAiB,SAAQ,eAAe;IAChD,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG;QACpC,MAAM,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,OAAO,CAAC;YAAC,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KACjD,CAAC;IACF,SAAS,EAAE;QAAE,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;KAAE,CAAC;IACrE,MAAM,EAAE;QACN,QAAQ,EAAE;YACR,UAAU,IAAI,OAAO,CAAC;gBAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;aAAE,CAAC,CAAC;YAC7D,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC3C,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,yBAAyB;IACxC,UAAU,CAAC,EAAE,wBAAwB,CAAC;CACvC;AAwRD,eAAO,MAAM,aAAa,GACxB,KAAK,gBAAgB,EACrB,SAAS,4BAA4B,EACrC,eAAc,yBAA8B,KAC3C,OAAO,CAAC,yBAAyB,CAcnC,CAAC"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { ContractFactory, getAddress, hexlify, Interface, keccak256, } from 'ethers';
|
|
2
|
+
import { utils } from 'zksync-ethers';
|
|
3
|
+
import { artifactIdentity, assertArtifactScheme, collectZkFactoryDeps, } from './artifacts.js';
|
|
4
|
+
import { hashPreparationRequest, normalizePreparationPlan, } from './normalize.js';
|
|
5
|
+
import { validateZkImplementation, } from './zkUpgradeValidation.js';
|
|
6
|
+
const ERC1967_PROXY_ARTIFACT = '@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy';
|
|
7
|
+
const CONTRACT_DEPLOYER_INTERFACE = new Interface([
|
|
8
|
+
'function create2(bytes32 salt, bytes32 bytecodeHash, bytes input) returns (address)',
|
|
9
|
+
]);
|
|
10
|
+
const FACTORY_INTERFACE = new Interface([
|
|
11
|
+
'function deploy(bytes32 salt, bytes initCode, bytes data, uint256 create2ForwardValue, uint256 callForwardValue) payable returns (address)',
|
|
12
|
+
]);
|
|
13
|
+
const UPGRADE_INTERFACE = new Interface([
|
|
14
|
+
'function upgradeToAndCall(address newImplementation, bytes data) payable',
|
|
15
|
+
]);
|
|
16
|
+
const assertAddressPolicy = (predictedAddress, policy, label) => {
|
|
17
|
+
if (!policy)
|
|
18
|
+
return;
|
|
19
|
+
const normalized = getAddress(predictedAddress);
|
|
20
|
+
if (policy.expectedAddress && normalized !== getAddress(policy.expectedAddress)) {
|
|
21
|
+
throw new Error(`${label} predicted ${normalized} but expected ${policy.expectedAddress}`);
|
|
22
|
+
}
|
|
23
|
+
if (policy.leadingZeroBytes !== undefined
|
|
24
|
+
&& !normalized.slice(2).toLowerCase().startsWith('00'.repeat(policy.leadingZeroBytes))) {
|
|
25
|
+
throw new Error(`${label} does not satisfy leadingZeroBytes=${policy.leadingZeroBytes}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const bytecodeHash = (bytecode, label) => {
|
|
29
|
+
try {
|
|
30
|
+
return hexlify(utils.hashBytecode(bytecode)).toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
34
|
+
throw new Error(`${label} is not valid EraVM bytecode: ${message}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const assertZeroForwarding = (request) => {
|
|
38
|
+
if (BigInt(request.create2ForwardValue ?? '0') !== 0n
|
|
39
|
+
|| BigInt(request.callForwardValue ?? '0') !== 0n) {
|
|
40
|
+
throw new Error('zkSync V1 requires zero factory and call forwarding values');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const buildDeployment = async (input) => {
|
|
44
|
+
assertArtifactScheme(input.artifact, 'zksync-eravm');
|
|
45
|
+
const contractFactory = new ContractFactory(input.artifact.abi, input.artifact.bytecode);
|
|
46
|
+
const constructorInput = contractFactory.interface.encodeDeploy(input.constructorArgs);
|
|
47
|
+
const selectedBytecodeHash = bytecodeHash(input.artifact.bytecode, `${input.role} bytecode`);
|
|
48
|
+
const predictedAddress = utils.create2Address(input.factory, selectedBytecodeHash, input.salt, constructorInput);
|
|
49
|
+
assertAddressPolicy(predictedAddress, input.policy, input.role);
|
|
50
|
+
const existingCode = await input.hre.ethers.provider.getCode(predictedAddress);
|
|
51
|
+
const status = existingCode && existingCode !== '0x' ? 'reused' : 'required';
|
|
52
|
+
if (status === 'reused') {
|
|
53
|
+
const existingHash = bytecodeHash(existingCode, `${input.role} deployed bytecode`);
|
|
54
|
+
if (existingHash !== selectedBytecodeHash) {
|
|
55
|
+
throw new Error(`${input.role} bytecode mismatch at ${predictedAddress}: `
|
|
56
|
+
+ `actual=${existingHash} expected=${selectedBytecodeHash}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const deployment = {
|
|
60
|
+
role: input.role,
|
|
61
|
+
address: predictedAddress,
|
|
62
|
+
salt: input.salt,
|
|
63
|
+
status,
|
|
64
|
+
constructorInput,
|
|
65
|
+
bytecodeHash: selectedBytecodeHash,
|
|
66
|
+
constructorInputHash: keccak256(constructorInput),
|
|
67
|
+
};
|
|
68
|
+
if (status === 'reused')
|
|
69
|
+
return { deployment, contractFactory };
|
|
70
|
+
const deployerInput = CONTRACT_DEPLOYER_INTERFACE.encodeFunctionData('create2', [
|
|
71
|
+
input.salt,
|
|
72
|
+
selectedBytecodeHash,
|
|
73
|
+
constructorInput,
|
|
74
|
+
]);
|
|
75
|
+
const purpose = input.role === 'contract'
|
|
76
|
+
? 'deploy-contract'
|
|
77
|
+
: input.role === 'implementation'
|
|
78
|
+
? 'deploy-implementation'
|
|
79
|
+
: 'deploy-proxy';
|
|
80
|
+
const factoryDeps = await collectZkFactoryDeps(input.hre.artifacts, input.artifact);
|
|
81
|
+
return {
|
|
82
|
+
deployment,
|
|
83
|
+
contractFactory,
|
|
84
|
+
transaction: {
|
|
85
|
+
id: purpose,
|
|
86
|
+
purpose,
|
|
87
|
+
to: input.factory,
|
|
88
|
+
value: '0',
|
|
89
|
+
data: FACTORY_INTERFACE.encodeFunctionData('deploy', [
|
|
90
|
+
input.salt,
|
|
91
|
+
deployerInput,
|
|
92
|
+
'0x',
|
|
93
|
+
0n,
|
|
94
|
+
0n,
|
|
95
|
+
]),
|
|
96
|
+
operation: 0,
|
|
97
|
+
factoryDeps,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const preparePlain = async (hre, request, artifact) => {
|
|
102
|
+
assertZeroForwarding(request);
|
|
103
|
+
const prepared = await buildDeployment({
|
|
104
|
+
hre,
|
|
105
|
+
role: 'contract',
|
|
106
|
+
artifact,
|
|
107
|
+
constructorArgs: request.constructorArgs,
|
|
108
|
+
factory: request.factory,
|
|
109
|
+
salt: request.salt,
|
|
110
|
+
policy: request.addressPolicy,
|
|
111
|
+
});
|
|
112
|
+
const network = await hre.ethers.provider.getNetwork();
|
|
113
|
+
return normalizePreparationPlan({
|
|
114
|
+
version: 1,
|
|
115
|
+
requestHash: hashPreparationRequest(request),
|
|
116
|
+
kind: request.kind,
|
|
117
|
+
scheme: request.scheme,
|
|
118
|
+
network: request.network,
|
|
119
|
+
target: request.target,
|
|
120
|
+
chainId: network.chainId.toString(),
|
|
121
|
+
contract: request.contract,
|
|
122
|
+
artifact: artifactIdentity(artifact, 'zksync-eravm'),
|
|
123
|
+
validation: {
|
|
124
|
+
kind: 'artifact',
|
|
125
|
+
engine: 'hardhat-artifact',
|
|
126
|
+
artifactFormat: 'hh-zksolc-artifact-1',
|
|
127
|
+
},
|
|
128
|
+
deployments: [prepared.deployment],
|
|
129
|
+
transactions: prepared.transaction ? [prepared.transaction] : [],
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const initializerData = (factory, call) => (call ? factory.interface.encodeFunctionData(call.method, call.args) : '0x');
|
|
133
|
+
const prepareUupsInitial = async (hre, request, artifact, dependencies) => {
|
|
134
|
+
const validation = await validateZkImplementation(hre, request, artifact, dependencies.validation);
|
|
135
|
+
if (validation.kind !== 'uups-initial') {
|
|
136
|
+
throw new Error('zkSync initial UUPS validation returned an invalid result');
|
|
137
|
+
}
|
|
138
|
+
const implementation = await buildDeployment({
|
|
139
|
+
hre,
|
|
140
|
+
role: 'implementation',
|
|
141
|
+
artifact,
|
|
142
|
+
constructorArgs: request.constructorArgs,
|
|
143
|
+
factory: request.factory,
|
|
144
|
+
salt: request.implementationSalt,
|
|
145
|
+
});
|
|
146
|
+
const proxyArtifact = await hre.artifacts.readArtifact(ERC1967_PROXY_ARTIFACT);
|
|
147
|
+
assertArtifactScheme(proxyArtifact, 'zksync-eravm');
|
|
148
|
+
const proxy = await buildDeployment({
|
|
149
|
+
hre,
|
|
150
|
+
role: 'proxy',
|
|
151
|
+
artifact: proxyArtifact,
|
|
152
|
+
constructorArgs: [request.placeholderImplementation, '0x'],
|
|
153
|
+
factory: request.factory,
|
|
154
|
+
salt: request.proxySalt,
|
|
155
|
+
policy: request.proxyAddressPolicy,
|
|
156
|
+
});
|
|
157
|
+
const transactions = [implementation.transaction, proxy.transaction]
|
|
158
|
+
.filter((transaction) => transaction !== undefined);
|
|
159
|
+
transactions.push({
|
|
160
|
+
id: 'upgrade-proxy',
|
|
161
|
+
purpose: 'upgrade-proxy',
|
|
162
|
+
to: proxy.deployment.address,
|
|
163
|
+
value: '0',
|
|
164
|
+
data: UPGRADE_INTERFACE.encodeFunctionData('upgradeToAndCall', [
|
|
165
|
+
implementation.deployment.address,
|
|
166
|
+
initializerData(implementation.contractFactory, request.call),
|
|
167
|
+
]),
|
|
168
|
+
operation: 0,
|
|
169
|
+
factoryDeps: [],
|
|
170
|
+
});
|
|
171
|
+
const network = await hre.ethers.provider.getNetwork();
|
|
172
|
+
return normalizePreparationPlan({
|
|
173
|
+
version: 1,
|
|
174
|
+
requestHash: hashPreparationRequest(request),
|
|
175
|
+
kind: request.kind,
|
|
176
|
+
scheme: request.scheme,
|
|
177
|
+
network: request.network,
|
|
178
|
+
target: request.target,
|
|
179
|
+
chainId: network.chainId.toString(),
|
|
180
|
+
contract: request.contract,
|
|
181
|
+
proxyKind: 'uups',
|
|
182
|
+
artifact: artifactIdentity(artifact, 'zksync-eravm'),
|
|
183
|
+
validation,
|
|
184
|
+
deployments: [implementation.deployment, proxy.deployment],
|
|
185
|
+
transactions,
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
const prepareUupsUpgrade = async (hre, request, artifact, dependencies) => {
|
|
189
|
+
const validation = await validateZkImplementation(hre, request, artifact, dependencies.validation);
|
|
190
|
+
if (validation.kind !== 'uups-upgrade') {
|
|
191
|
+
throw new Error('zkSync UUPS upgrade validation returned an invalid result');
|
|
192
|
+
}
|
|
193
|
+
const implementation = await buildDeployment({
|
|
194
|
+
hre,
|
|
195
|
+
role: 'implementation',
|
|
196
|
+
artifact,
|
|
197
|
+
constructorArgs: request.constructorArgs,
|
|
198
|
+
factory: request.factory,
|
|
199
|
+
salt: request.implementationSalt,
|
|
200
|
+
policy: request.implementationAddressPolicy,
|
|
201
|
+
});
|
|
202
|
+
const transactions = implementation.transaction ? [implementation.transaction] : [];
|
|
203
|
+
transactions.push({
|
|
204
|
+
id: 'upgrade-proxy',
|
|
205
|
+
purpose: 'upgrade-proxy',
|
|
206
|
+
to: request.proxy,
|
|
207
|
+
value: '0',
|
|
208
|
+
data: UPGRADE_INTERFACE.encodeFunctionData('upgradeToAndCall', [
|
|
209
|
+
implementation.deployment.address,
|
|
210
|
+
initializerData(implementation.contractFactory, request.call),
|
|
211
|
+
]),
|
|
212
|
+
operation: 0,
|
|
213
|
+
factoryDeps: [],
|
|
214
|
+
});
|
|
215
|
+
const network = await hre.ethers.provider.getNetwork();
|
|
216
|
+
return normalizePreparationPlan({
|
|
217
|
+
version: 1,
|
|
218
|
+
requestHash: hashPreparationRequest(request),
|
|
219
|
+
kind: request.kind,
|
|
220
|
+
scheme: request.scheme,
|
|
221
|
+
network: request.network,
|
|
222
|
+
target: request.target,
|
|
223
|
+
chainId: network.chainId.toString(),
|
|
224
|
+
contract: request.contract,
|
|
225
|
+
proxyKind: 'uups',
|
|
226
|
+
artifact: artifactIdentity(artifact, 'zksync-eravm'),
|
|
227
|
+
validation,
|
|
228
|
+
deployments: [implementation.deployment],
|
|
229
|
+
transactions,
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
export const prepareZkSync = async (hre, request, dependencies = {}) => {
|
|
233
|
+
if (request.scheme !== 'zksync-eravm') {
|
|
234
|
+
throw new Error('zkSync adapter received a non-zkSync request');
|
|
235
|
+
}
|
|
236
|
+
if (hre.network.config?.zksync !== true) {
|
|
237
|
+
throw new Error(`Hardhat network ${hre.network.name} is not configured for zkSync`);
|
|
238
|
+
}
|
|
239
|
+
const artifact = await hre.artifacts.readArtifact(request.contract);
|
|
240
|
+
assertArtifactScheme(artifact, 'zksync-eravm');
|
|
241
|
+
if (request.kind === 'create2-deploy')
|
|
242
|
+
return preparePlain(hre, request, artifact);
|
|
243
|
+
if (request.kind === 'uups-placeholder-deploy') {
|
|
244
|
+
return prepareUupsInitial(hre, request, artifact, dependencies);
|
|
245
|
+
}
|
|
246
|
+
return prepareUupsUpgrade(hre, request, artifact, dependencies);
|
|
247
|
+
};
|
|
248
|
+
//# sourceMappingURL=zksync.js.map
|