gate-evm-tools 1.0.26 → 1.0.27
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 +14 -0
- package/bin/workflow.cjs +19 -0
- package/dist/core/BytecodeChecker.d.ts.map +1 -1
- package/dist/core/BytecodeChecker.js +16 -1
- package/dist/core/BytecodeChecker.js.map +1 -1
- package/dist/core/legacyProxyArtifact.d.ts +6 -0
- package/dist/core/legacyProxyArtifact.d.ts.map +1 -0
- package/dist/core/legacyProxyArtifact.js +36 -0
- package/dist/core/legacyProxyArtifact.js.map +1 -0
- package/dist-runtime/config/hardhatAdapters.d.ts +5 -0
- package/dist-runtime/config/hardhatAdapters.js +53 -0
- package/dist-runtime/config/hardhatAdapters.js.map +1 -0
- package/dist-runtime/config/networks.d.ts +8 -0
- package/dist-runtime/config/networks.js +269 -0
- package/dist-runtime/config/networks.js.map +1 -0
- package/dist-runtime/config/openzeppelin.d.ts +28 -0
- package/dist-runtime/config/openzeppelin.js +144 -0
- package/dist-runtime/config/openzeppelin.js.map +1 -0
- package/dist-runtime/config/rpc.d.ts +7 -0
- package/dist-runtime/config/rpc.js +19 -0
- package/dist-runtime/config/rpc.js.map +1 -0
- package/dist-runtime/config/zksyncSolcPath.d.ts +1 -0
- package/dist-runtime/config/zksyncSolcPath.js +61 -0
- package/dist-runtime/config/zksyncSolcPath.js.map +1 -0
- package/dist-runtime/migrate.d.ts +13 -0
- package/dist-runtime/migrate.js +208 -0
- package/dist-runtime/migrate.js.map +1 -0
- package/dist-runtime/package.json +1 -0
- package/dist-runtime/projectHardhat.d.ts +4 -0
- package/dist-runtime/projectHardhat.js +16 -0
- package/dist-runtime/projectHardhat.js.map +1 -0
- package/dist-runtime/runtime-identity.json +4 -0
- package/dist-runtime/template-migration.json +293 -0
- package/dist-runtime/workflow/checkCode.d.ts +1 -0
- package/dist-runtime/workflow/checkCode.js +16 -0
- package/dist-runtime/workflow/checkCode.js.map +1 -0
- package/dist-runtime/workflow/checkCodeFinalize.d.ts +1 -0
- package/dist-runtime/workflow/checkCodeFinalize.js +11 -0
- package/dist-runtime/workflow/checkCodeFinalize.js.map +1 -0
- package/dist-runtime/workflow/checkCodePlan.d.ts +1 -0
- package/dist-runtime/workflow/checkCodePlan.js +11 -0
- package/dist-runtime/workflow/checkCodePlan.js.map +1 -0
- package/dist-runtime/workflow/cli.d.ts +1 -0
- package/dist-runtime/workflow/cli.js +302 -0
- package/dist-runtime/workflow/cli.js.map +1 -0
- package/dist-runtime/workflow/commitContractInfo.d.ts +1 -0
- package/dist-runtime/workflow/commitContractInfo.js +64 -0
- package/dist-runtime/workflow/commitContractInfo.js.map +1 -0
- package/dist-runtime/workflow/create2Hashes.d.ts +1 -0
- package/dist-runtime/workflow/create2Hashes.js +76 -0
- package/dist-runtime/workflow/create2Hashes.js.map +1 -0
- package/dist-runtime/workflow/forkSourceProxy.d.ts +1 -0
- package/dist-runtime/workflow/forkSourceProxy.js +151 -0
- package/dist-runtime/workflow/forkSourceProxy.js.map +1 -0
- package/dist-runtime/workflow/importState.d.ts +1 -0
- package/dist-runtime/workflow/importState.js +193 -0
- package/dist-runtime/workflow/importState.js.map +1 -0
- package/dist-runtime/workflow/lib/authority.d.ts +28 -0
- package/dist-runtime/workflow/lib/authority.js +122 -0
- package/dist-runtime/workflow/lib/authority.js.map +1 -0
- package/dist-runtime/workflow/lib/calldata.d.ts +2 -0
- package/dist-runtime/workflow/lib/calldata.js +8 -0
- package/dist-runtime/workflow/lib/calldata.js.map +1 -0
- package/dist-runtime/workflow/lib/calls.d.ts +23 -0
- package/dist-runtime/workflow/lib/calls.js +316 -0
- package/dist-runtime/workflow/lib/calls.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/args.d.ts +2 -0
- package/dist-runtime/workflow/lib/checkCode/args.js +68 -0
- package/dist-runtime/workflow/lib/checkCode/args.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/command.d.ts +5 -0
- package/dist-runtime/workflow/lib/checkCode/command.js +35 -0
- package/dist-runtime/workflow/lib/checkCode/command.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/dependencies.d.ts +6 -0
- package/dist-runtime/workflow/lib/checkCode/dependencies.js +125 -0
- package/dist-runtime/workflow/lib/checkCode/dependencies.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/finalize.d.ts +17 -0
- package/dist-runtime/workflow/lib/checkCode/finalize.js +174 -0
- package/dist-runtime/workflow/lib/checkCode/finalize.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/index.d.ts +3 -0
- package/dist-runtime/workflow/lib/checkCode/index.js +20 -0
- package/dist-runtime/workflow/lib/checkCode/index.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCode/plan.d.ts +22 -0
- package/dist-runtime/workflow/lib/checkCode/plan.js +145 -0
- package/dist-runtime/workflow/lib/checkCode/plan.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCodeReport.d.ts +25 -0
- package/dist-runtime/workflow/lib/checkCodeReport.js +102 -0
- package/dist-runtime/workflow/lib/checkCodeReport.js.map +1 -0
- package/dist-runtime/workflow/lib/checkCodeRunner.d.ts +87 -0
- package/dist-runtime/workflow/lib/checkCodeRunner.js +964 -0
- package/dist-runtime/workflow/lib/checkCodeRunner.js.map +1 -0
- package/dist-runtime/workflow/lib/cliTool.d.ts +10 -0
- package/dist-runtime/workflow/lib/cliTool.js +25 -0
- package/dist-runtime/workflow/lib/cliTool.js.map +1 -0
- package/dist-runtime/workflow/lib/config.d.ts +33 -0
- package/dist-runtime/workflow/lib/config.js +100 -0
- package/dist-runtime/workflow/lib/config.js.map +1 -0
- package/dist-runtime/workflow/lib/contractInfoCandidates.d.ts +82 -0
- package/dist-runtime/workflow/lib/contractInfoCandidates.js +441 -0
- package/dist-runtime/workflow/lib/contractInfoCandidates.js.map +1 -0
- package/dist-runtime/workflow/lib/create2.d.ts +49 -0
- package/dist-runtime/workflow/lib/create2.js +194 -0
- package/dist-runtime/workflow/lib/create2.js.map +1 -0
- package/dist-runtime/workflow/lib/create2Hashes.d.ts +22 -0
- package/dist-runtime/workflow/lib/create2Hashes.js +57 -0
- package/dist-runtime/workflow/lib/create2Hashes.js.map +1 -0
- package/dist-runtime/workflow/lib/deploymentInfo.d.ts +40 -0
- package/dist-runtime/workflow/lib/deploymentInfo.js +240 -0
- package/dist-runtime/workflow/lib/deploymentInfo.js.map +1 -0
- package/dist-runtime/workflow/lib/deploymentRecords.d.ts +137 -0
- package/dist-runtime/workflow/lib/deploymentRecords.js +374 -0
- package/dist-runtime/workflow/lib/deploymentRecords.js.map +1 -0
- package/dist-runtime/workflow/lib/deployments.d.ts +21 -0
- package/dist-runtime/workflow/lib/deployments.js +240 -0
- package/dist-runtime/workflow/lib/deployments.js.map +1 -0
- package/dist-runtime/workflow/lib/erc1967.d.ts +5 -0
- package/dist-runtime/workflow/lib/erc1967.js +29 -0
- package/dist-runtime/workflow/lib/erc1967.js.map +1 -0
- package/dist-runtime/workflow/lib/errors.d.ts +6 -0
- package/dist-runtime/workflow/lib/errors.js +77 -0
- package/dist-runtime/workflow/lib/errors.js.map +1 -0
- package/dist-runtime/workflow/lib/executionId.d.ts +7 -0
- package/dist-runtime/workflow/lib/executionId.js +26 -0
- package/dist-runtime/workflow/lib/executionId.js.map +1 -0
- package/dist-runtime/workflow/lib/executionPlan.d.ts +85 -0
- package/dist-runtime/workflow/lib/executionPlan.js +450 -0
- package/dist-runtime/workflow/lib/executionPlan.js.map +1 -0
- package/dist-runtime/workflow/lib/executionProgress.d.ts +5 -0
- package/dist-runtime/workflow/lib/executionProgress.js +100 -0
- package/dist-runtime/workflow/lib/executionProgress.js.map +1 -0
- package/dist-runtime/workflow/lib/external.d.ts +62 -0
- package/dist-runtime/workflow/lib/external.js +282 -0
- package/dist-runtime/workflow/lib/external.js.map +1 -0
- package/dist-runtime/workflow/lib/externalExecutionScanner.d.ts +64 -0
- package/dist-runtime/workflow/lib/externalExecutionScanner.js +638 -0
- package/dist-runtime/workflow/lib/externalExecutionScanner.js.map +1 -0
- package/dist-runtime/workflow/lib/forkSnapshot.d.ts +34 -0
- package/dist-runtime/workflow/lib/forkSnapshot.js +167 -0
- package/dist-runtime/workflow/lib/forkSnapshot.js.map +1 -0
- package/dist-runtime/workflow/lib/gateTool.d.ts +16 -0
- package/dist-runtime/workflow/lib/gateTool.js +177 -0
- package/dist-runtime/workflow/lib/gateTool.js.map +1 -0
- package/dist-runtime/workflow/lib/gateToolSync.d.ts +22 -0
- package/dist-runtime/workflow/lib/gateToolSync.js +253 -0
- package/dist-runtime/workflow/lib/gateToolSync.js.map +1 -0
- package/dist-runtime/workflow/lib/lock.d.ts +52 -0
- package/dist-runtime/workflow/lib/lock.js +269 -0
- package/dist-runtime/workflow/lib/lock.js.map +1 -0
- package/dist-runtime/workflow/lib/migrationState.d.ts +103 -0
- package/dist-runtime/workflow/lib/migrationState.js +920 -0
- package/dist-runtime/workflow/lib/migrationState.js.map +1 -0
- package/dist-runtime/workflow/lib/operatorExecution.d.ts +28 -0
- package/dist-runtime/workflow/lib/operatorExecution.js +134 -0
- package/dist-runtime/workflow/lib/operatorExecution.js.map +1 -0
- package/dist-runtime/workflow/lib/parameters.d.ts +58 -0
- package/dist-runtime/workflow/lib/parameters.js +322 -0
- package/dist-runtime/workflow/lib/parameters.js.map +1 -0
- package/dist-runtime/workflow/lib/pendingDeploymentReuse.d.ts +29 -0
- package/dist-runtime/workflow/lib/pendingDeploymentReuse.js +277 -0
- package/dist-runtime/workflow/lib/pendingDeploymentReuse.js.map +1 -0
- package/dist-runtime/workflow/lib/proxy.d.ts +18 -0
- package/dist-runtime/workflow/lib/proxy.js +19 -0
- package/dist-runtime/workflow/lib/proxy.js.map +1 -0
- package/dist-runtime/workflow/lib/registryCommit.d.ts +33 -0
- package/dist-runtime/workflow/lib/registryCommit.js +319 -0
- package/dist-runtime/workflow/lib/registryCommit.js.map +1 -0
- package/dist-runtime/workflow/lib/release.d.ts +57 -0
- package/dist-runtime/workflow/lib/release.js +256 -0
- package/dist-runtime/workflow/lib/release.js.map +1 -0
- package/dist-runtime/workflow/lib/releaseFinalize.d.ts +14 -0
- package/dist-runtime/workflow/lib/releaseFinalize.js +571 -0
- package/dist-runtime/workflow/lib/releaseFinalize.js.map +1 -0
- package/dist-runtime/workflow/lib/releaseParameters.d.ts +43 -0
- package/dist-runtime/workflow/lib/releaseParameters.js +184 -0
- package/dist-runtime/workflow/lib/releaseParameters.js.map +1 -0
- package/dist-runtime/workflow/lib/reporter.d.ts +39 -0
- package/dist-runtime/workflow/lib/reporter.js +452 -0
- package/dist-runtime/workflow/lib/reporter.js.map +1 -0
- package/dist-runtime/workflow/lib/resultPaths.d.ts +17 -0
- package/dist-runtime/workflow/lib/resultPaths.js +29 -0
- package/dist-runtime/workflow/lib/resultPaths.js.map +1 -0
- package/dist-runtime/workflow/lib/runtimeVersion.d.ts +10 -0
- package/dist-runtime/workflow/lib/runtimeVersion.js +46 -0
- package/dist-runtime/workflow/lib/runtimeVersion.js.map +1 -0
- package/dist-runtime/workflow/lib/signer.d.ts +10 -0
- package/dist-runtime/workflow/lib/signer.js +105 -0
- package/dist-runtime/workflow/lib/signer.js.map +1 -0
- package/dist-runtime/workflow/lib/signerIdentity.d.ts +1 -0
- package/dist-runtime/workflow/lib/signerIdentity.js +23 -0
- package/dist-runtime/workflow/lib/signerIdentity.js.map +1 -0
- package/dist-runtime/workflow/lib/simulation.d.ts +35 -0
- package/dist-runtime/workflow/lib/simulation.js +282 -0
- package/dist-runtime/workflow/lib/simulation.js.map +1 -0
- package/dist-runtime/workflow/lib/simulationCallers.d.ts +44 -0
- package/dist-runtime/workflow/lib/simulationCallers.js +260 -0
- package/dist-runtime/workflow/lib/simulationCallers.js.map +1 -0
- package/dist-runtime/workflow/lib/sourceRpcPolicy.d.ts +1 -0
- package/dist-runtime/workflow/lib/sourceRpcPolicy.js +43 -0
- package/dist-runtime/workflow/lib/sourceRpcPolicy.js.map +1 -0
- package/dist-runtime/workflow/lib/state.d.ts +6 -0
- package/dist-runtime/workflow/lib/state.js +25 -0
- package/dist-runtime/workflow/lib/state.js.map +1 -0
- package/dist-runtime/workflow/lib/staticValidation.d.ts +22 -0
- package/dist-runtime/workflow/lib/staticValidation.js +124 -0
- package/dist-runtime/workflow/lib/staticValidation.js.map +1 -0
- package/dist-runtime/workflow/lib/zksyncForkCapability.d.ts +27 -0
- package/dist-runtime/workflow/lib/zksyncForkCapability.js +52 -0
- package/dist-runtime/workflow/lib/zksyncForkCapability.js.map +1 -0
- package/dist-runtime/workflow/lib/zksyncForkRunner.d.ts +57 -0
- package/dist-runtime/workflow/lib/zksyncForkRunner.js +344 -0
- package/dist-runtime/workflow/lib/zksyncForkRunner.js.map +1 -0
- package/dist-runtime/workflow/reconcileExternal.d.ts +1 -0
- package/dist-runtime/workflow/reconcileExternal.js +87 -0
- package/dist-runtime/workflow/reconcileExternal.js.map +1 -0
- package/dist-runtime/workflow/reconcileExternalRun.d.ts +1 -0
- package/dist-runtime/workflow/reconcileExternalRun.js +77 -0
- package/dist-runtime/workflow/reconcileExternalRun.js.map +1 -0
- package/dist-runtime/workflow/releaseFinalize.d.ts +1 -0
- package/dist-runtime/workflow/releaseFinalize.js +11 -0
- package/dist-runtime/workflow/releaseFinalize.js.map +1 -0
- package/dist-runtime/workflow/run.d.ts +40 -0
- package/dist-runtime/workflow/run.js +858 -0
- package/dist-runtime/workflow/run.js.map +1 -0
- package/dist-runtime/workflow/staticValidate.d.ts +1 -0
- package/dist-runtime/workflow/staticValidate.js +26 -0
- package/dist-runtime/workflow/staticValidate.js.map +1 -0
- package/dist-runtime/workflow/steps/call.d.ts +3 -0
- package/dist-runtime/workflow/steps/call.js +9 -0
- package/dist-runtime/workflow/steps/call.js.map +1 -0
- package/dist-runtime/workflow/steps/check.d.ts +3 -0
- package/dist-runtime/workflow/steps/check.js +9 -0
- package/dist-runtime/workflow/steps/check.js.map +1 -0
- package/dist-runtime/workflow/steps/custom.d.ts +3 -0
- package/dist-runtime/workflow/steps/custom.js +33 -0
- package/dist-runtime/workflow/steps/custom.js.map +1 -0
- package/dist-runtime/workflow/steps/deploy.d.ts +3 -0
- package/dist-runtime/workflow/steps/deploy.js +595 -0
- package/dist-runtime/workflow/steps/deploy.js.map +1 -0
- package/dist-runtime/workflow/steps/upgrade.d.ts +3 -0
- package/dist-runtime/workflow/steps/upgrade.js +465 -0
- package/dist-runtime/workflow/steps/upgrade.js.map +1 -0
- package/dist-runtime/workflow/steps/view.d.ts +3 -0
- package/dist-runtime/workflow/steps/view.js +9 -0
- package/dist-runtime/workflow/steps/view.js.map +1 -0
- package/package.json +25 -5
- package/runtime/config/hardhatAdapters.ts +50 -0
- package/runtime/config/networks.ts +296 -0
- package/runtime/config/openzeppelin.ts +173 -0
- package/runtime/config/rpc.ts +27 -0
- package/runtime/config/zksyncSolcPath.ts +59 -0
- package/runtime/hardhat-types.d.ts +2 -0
- package/runtime/migrate.ts +154 -0
- package/runtime/projectHardhat.ts +10 -0
- package/runtime/template-migration.json +293 -0
- package/runtime/workflow/checkCode.ts +13 -0
- package/runtime/workflow/checkCodeFinalize.ts +8 -0
- package/runtime/workflow/checkCodePlan.ts +8 -0
- package/runtime/workflow/cli.ts +356 -0
- package/runtime/workflow/commitContractInfo.ts +63 -0
- package/runtime/workflow/create2Hashes.ts +79 -0
- package/runtime/workflow/forkSourceProxy.ts +193 -0
- package/runtime/workflow/importState.ts +190 -0
- package/runtime/workflow/lib/authority.ts +170 -0
- package/runtime/workflow/lib/calldata.ts +9 -0
- package/runtime/workflow/lib/calls.ts +407 -0
- package/runtime/workflow/lib/checkCode/args.ts +76 -0
- package/runtime/workflow/lib/checkCode/command.ts +36 -0
- package/runtime/workflow/lib/checkCode/dependencies.ts +112 -0
- package/runtime/workflow/lib/checkCode/finalize.ts +198 -0
- package/runtime/workflow/lib/checkCode/index.ts +18 -0
- package/runtime/workflow/lib/checkCode/plan.ts +163 -0
- package/runtime/workflow/lib/checkCodeReport.ts +133 -0
- package/runtime/workflow/lib/checkCodeRunner.ts +1225 -0
- package/runtime/workflow/lib/cliTool.ts +31 -0
- package/runtime/workflow/lib/config.ts +130 -0
- package/runtime/workflow/lib/contractInfoCandidates.ts +690 -0
- package/runtime/workflow/lib/create2.ts +278 -0
- package/runtime/workflow/lib/create2Hashes.ts +83 -0
- package/runtime/workflow/lib/deploymentInfo.ts +286 -0
- package/runtime/workflow/lib/deploymentRecords.ts +576 -0
- package/runtime/workflow/lib/deployments.ts +276 -0
- package/runtime/workflow/lib/erc1967.ts +57 -0
- package/runtime/workflow/lib/errors.ts +95 -0
- package/runtime/workflow/lib/executionId.ts +35 -0
- package/runtime/workflow/lib/executionPlan.ts +550 -0
- package/runtime/workflow/lib/executionProgress.ts +127 -0
- package/runtime/workflow/lib/external.ts +372 -0
- package/runtime/workflow/lib/externalExecutionScanner.ts +892 -0
- package/runtime/workflow/lib/forkSnapshot.ts +231 -0
- package/runtime/workflow/lib/gateTool.ts +261 -0
- package/runtime/workflow/lib/gateToolSync.ts +398 -0
- package/runtime/workflow/lib/lock.ts +388 -0
- package/runtime/workflow/lib/migrationState.ts +1246 -0
- package/runtime/workflow/lib/operatorExecution.ts +174 -0
- package/runtime/workflow/lib/parameters.ts +437 -0
- package/runtime/workflow/lib/pendingDeploymentReuse.ts +428 -0
- package/runtime/workflow/lib/proxy.ts +45 -0
- package/runtime/workflow/lib/registryCommit.ts +455 -0
- package/runtime/workflow/lib/release.ts +329 -0
- package/runtime/workflow/lib/releaseFinalize.ts +711 -0
- package/runtime/workflow/lib/releaseParameters.ts +248 -0
- package/runtime/workflow/lib/reporter.ts +502 -0
- package/runtime/workflow/lib/resultPaths.ts +49 -0
- package/runtime/workflow/lib/runtimeVersion.ts +28 -0
- package/runtime/workflow/lib/signer.ts +124 -0
- package/runtime/workflow/lib/signerIdentity.ts +22 -0
- package/runtime/workflow/lib/simulation.ts +415 -0
- package/runtime/workflow/lib/simulationCallers.ts +335 -0
- package/runtime/workflow/lib/sourceRpcPolicy.ts +41 -0
- package/runtime/workflow/lib/state.ts +25 -0
- package/runtime/workflow/lib/staticValidation.ts +142 -0
- package/runtime/workflow/lib/zksyncForkCapability.ts +80 -0
- package/runtime/workflow/lib/zksyncForkRunner.ts +505 -0
- package/runtime/workflow/reconcileExternal.ts +86 -0
- package/runtime/workflow/reconcileExternalRun.ts +88 -0
- package/runtime/workflow/releaseFinalize.ts +8 -0
- package/runtime/workflow/run.ts +1072 -0
- package/runtime/workflow/staticValidate.ts +23 -0
- package/runtime/workflow/steps/call.ts +10 -0
- package/runtime/workflow/steps/check.ts +10 -0
- package/runtime/workflow/steps/custom.ts +43 -0
- package/runtime/workflow/steps/deploy.ts +771 -0
- package/runtime/workflow/steps/upgrade.ts +598 -0
- package/runtime/workflow/steps/view.ts +10 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import hardhat from "../../projectHardhat";
|
|
5
|
+
import { syncWithHre } from "gate-evm-tools/sync";
|
|
6
|
+
import { writeJsonFile } from "./config";
|
|
7
|
+
|
|
8
|
+
export interface GateToolSyncEvidence {
|
|
9
|
+
outputPath: string;
|
|
10
|
+
data: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type GateToolSyncHre = Parameters<typeof syncWithHre>[1];
|
|
14
|
+
|
|
15
|
+
export interface SyncGateToolUupsOptions {
|
|
16
|
+
root: string;
|
|
17
|
+
evidenceDir: string;
|
|
18
|
+
evidenceName: string;
|
|
19
|
+
scheme: "evm" | "zksync-eravm";
|
|
20
|
+
network: string;
|
|
21
|
+
target: string;
|
|
22
|
+
manifestDir: string;
|
|
23
|
+
proxy: string;
|
|
24
|
+
implementation: string;
|
|
25
|
+
contract: string;
|
|
26
|
+
constructorArgs: unknown[];
|
|
27
|
+
transactionHash: string;
|
|
28
|
+
hre?: GateToolSyncHre;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SAFE_FILE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,199}$/;
|
|
32
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
33
|
+
const TRANSACTION_HASH = /^0x[a-fA-F0-9]{64}$/;
|
|
34
|
+
|
|
35
|
+
const confinedPath = (root: string, requested: string, label: string): string => {
|
|
36
|
+
const resolvedRoot = path.resolve(root);
|
|
37
|
+
const resolved = path.resolve(requested);
|
|
38
|
+
const relative = path.relative(resolvedRoot, resolved);
|
|
39
|
+
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
40
|
+
throw new Error(`${label} must be inside the project root`);
|
|
41
|
+
}
|
|
42
|
+
let current = resolvedRoot;
|
|
43
|
+
for (const segment of relative.split(path.sep).filter(Boolean)) {
|
|
44
|
+
current = path.join(current, segment);
|
|
45
|
+
if (fs.existsSync(current) && fs.lstatSync(current).isSymbolicLink()) {
|
|
46
|
+
throw new Error(`${label} path cannot contain a symlink`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return resolved;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const record = (value: unknown, label: string): Record<string, unknown> => {
|
|
53
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
54
|
+
throw new Error(`${label} must be an object`);
|
|
55
|
+
}
|
|
56
|
+
return value as Record<string, unknown>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const stringField = (value: Record<string, unknown>, key: string): string => {
|
|
60
|
+
const field = value[key];
|
|
61
|
+
if (typeof field !== "string" || !field) {
|
|
62
|
+
throw new Error(`GateTool sync result is missing ${key}`);
|
|
63
|
+
}
|
|
64
|
+
return field;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const sameAddress = (left: string, right: string): boolean => (
|
|
68
|
+
left.toLowerCase() === right.toLowerCase()
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const readRegularBytes = (filePath: string, label: string): Buffer => {
|
|
72
|
+
const stat = fs.lstatSync(filePath);
|
|
73
|
+
if (!stat.isFile()) throw new Error(`${label} must be a regular file`);
|
|
74
|
+
return fs.readFileSync(filePath);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const jsonFromBytes = (contents: Buffer, label: string): Record<string, unknown> => {
|
|
78
|
+
return record(JSON.parse(contents.toString("utf8")) as unknown, label);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const canonicalJsonBytes = (value: unknown): Buffer => (
|
|
82
|
+
Buffer.from(`${JSON.stringify(value, null, 2)}\n`)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const writeImmutableFile = (
|
|
86
|
+
filePath: string,
|
|
87
|
+
contents: Buffer,
|
|
88
|
+
root: string,
|
|
89
|
+
label: string,
|
|
90
|
+
): Buffer => {
|
|
91
|
+
const confined = confinedPath(root, filePath, label);
|
|
92
|
+
fs.mkdirSync(path.dirname(confined), { recursive: true });
|
|
93
|
+
confinedPath(root, path.dirname(confined), `${label} directory`);
|
|
94
|
+
if (fs.existsSync(confined)) {
|
|
95
|
+
const existing = readRegularBytes(confined, label);
|
|
96
|
+
if (!existing.equals(contents)) {
|
|
97
|
+
throw new Error(`${label} already exists with different bytes`);
|
|
98
|
+
}
|
|
99
|
+
return existing;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const temporary = confinedPath(
|
|
103
|
+
root,
|
|
104
|
+
`${confined}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`,
|
|
105
|
+
`${label} temporary file`,
|
|
106
|
+
);
|
|
107
|
+
let descriptor: number | undefined;
|
|
108
|
+
try {
|
|
109
|
+
descriptor = fs.openSync(temporary, "wx", 0o600);
|
|
110
|
+
fs.writeFileSync(descriptor, contents);
|
|
111
|
+
fs.fsyncSync(descriptor);
|
|
112
|
+
fs.closeSync(descriptor);
|
|
113
|
+
descriptor = undefined;
|
|
114
|
+
try {
|
|
115
|
+
fs.linkSync(temporary, confined);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
118
|
+
const existing = readRegularBytes(confined, label);
|
|
119
|
+
if (!existing.equals(contents)) {
|
|
120
|
+
throw new Error(`${label} already exists with different bytes`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const stored = readRegularBytes(confined, label);
|
|
124
|
+
if (!stored.equals(contents)) {
|
|
125
|
+
throw new Error(`${label} does not match the committed source report`);
|
|
126
|
+
}
|
|
127
|
+
return stored;
|
|
128
|
+
} finally {
|
|
129
|
+
if (descriptor !== undefined) fs.closeSync(descriptor);
|
|
130
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const validateManifestTransaction = (
|
|
135
|
+
syncReport: Record<string, unknown>,
|
|
136
|
+
options: SyncGateToolUupsOptions,
|
|
137
|
+
): void => {
|
|
138
|
+
if (
|
|
139
|
+
syncReport.version !== 1
|
|
140
|
+
|| syncReport.status !== "committed"
|
|
141
|
+
|| typeof syncReport.beforeHash !== "string"
|
|
142
|
+
|| typeof syncReport.afterHash !== "string"
|
|
143
|
+
|| !HASH.test(syncReport.beforeHash)
|
|
144
|
+
|| !HASH.test(syncReport.afterHash)
|
|
145
|
+
) {
|
|
146
|
+
throw new Error("GateTool manifest transaction report is not committed evidence");
|
|
147
|
+
}
|
|
148
|
+
const manifestFile = stringField(syncReport, "manifestFile");
|
|
149
|
+
const expectedManifestRoot = path.resolve(options.root, options.manifestDir);
|
|
150
|
+
const resolvedManifest = path.resolve(options.root, manifestFile);
|
|
151
|
+
if (!resolvedManifest.startsWith(`${expectedManifestRoot}${path.sep}`)) {
|
|
152
|
+
throw new Error("GateTool sync wrote outside the target manifest directory");
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const validateEvidenceIdentity = (
|
|
157
|
+
raw: Record<string, unknown>,
|
|
158
|
+
options: SyncGateToolUupsOptions,
|
|
159
|
+
): void => {
|
|
160
|
+
if (
|
|
161
|
+
raw.version !== 1
|
|
162
|
+
|| raw.status !== "succeeded"
|
|
163
|
+
|| raw.evidenceName !== options.evidenceName
|
|
164
|
+
|| raw.scheme !== options.scheme
|
|
165
|
+
|| raw.network !== options.network
|
|
166
|
+
|| raw.target !== options.target
|
|
167
|
+
|| raw.manifestDir !== options.manifestDir
|
|
168
|
+
|| raw.contract !== options.contract
|
|
169
|
+
|| JSON.stringify(raw.constructorArgs) !== JSON.stringify(options.constructorArgs)
|
|
170
|
+
|| raw.transactionHash !== options.transactionHash.toLowerCase()
|
|
171
|
+
|| typeof raw.proxy !== "string"
|
|
172
|
+
|| typeof raw.implementation !== "string"
|
|
173
|
+
|| !sameAddress(raw.proxy, options.proxy)
|
|
174
|
+
|| !sameAddress(raw.implementation, options.implementation)
|
|
175
|
+
) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
"GateTool sync metadata identity does not match the immutable UUPS receipt",
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const validateEvidenceBinding = (
|
|
183
|
+
raw: Record<string, unknown>,
|
|
184
|
+
options: SyncGateToolUupsOptions,
|
|
185
|
+
expectedSyncReportPath: string,
|
|
186
|
+
): { syncReport: Record<string, unknown>; syncReportBytes: Buffer } => {
|
|
187
|
+
validateEvidenceIdentity(raw, options);
|
|
188
|
+
const syncReportPath = confinedPath(
|
|
189
|
+
options.root,
|
|
190
|
+
path.resolve(options.root, stringField(raw, "syncReportPath")),
|
|
191
|
+
"GateTool manifest transaction report",
|
|
192
|
+
);
|
|
193
|
+
if (syncReportPath !== expectedSyncReportPath) {
|
|
194
|
+
throw new Error("GateTool sync evidence does not reference its immutable report snapshot");
|
|
195
|
+
}
|
|
196
|
+
const syncReport = record(
|
|
197
|
+
raw.manifestTransaction,
|
|
198
|
+
"GateTool sync manifest transaction",
|
|
199
|
+
);
|
|
200
|
+
validateManifestTransaction(syncReport, options);
|
|
201
|
+
const syncReportBytes = canonicalJsonBytes(syncReport);
|
|
202
|
+
const syncReportHash = crypto
|
|
203
|
+
.createHash("sha256")
|
|
204
|
+
.update(syncReportBytes)
|
|
205
|
+
.digest("hex");
|
|
206
|
+
if (
|
|
207
|
+
raw.syncReportHash !== syncReportHash
|
|
208
|
+
|| raw.completedAt !== syncReport.completedAt
|
|
209
|
+
) {
|
|
210
|
+
throw new Error("GateTool sync evidence does not match its committed manifest transaction");
|
|
211
|
+
}
|
|
212
|
+
return { syncReport, syncReportBytes };
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const validateExistingEvidence = (
|
|
216
|
+
raw: Record<string, unknown>,
|
|
217
|
+
options: SyncGateToolUupsOptions,
|
|
218
|
+
expectedSyncReportPath: string,
|
|
219
|
+
): void => {
|
|
220
|
+
const binding = validateEvidenceBinding(raw, options, expectedSyncReportPath);
|
|
221
|
+
const storedBytes = readRegularBytes(
|
|
222
|
+
expectedSyncReportPath,
|
|
223
|
+
"GateTool manifest transaction snapshot",
|
|
224
|
+
);
|
|
225
|
+
if (!storedBytes.equals(binding.syncReportBytes)) {
|
|
226
|
+
throw new Error("GateTool sync evidence does not match its immutable report snapshot");
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const buildSyncEvidence = (
|
|
231
|
+
options: SyncGateToolUupsOptions,
|
|
232
|
+
syncReportPath: string,
|
|
233
|
+
syncReportBytes: Buffer,
|
|
234
|
+
syncReport: Record<string, unknown>,
|
|
235
|
+
): Record<string, unknown> => ({
|
|
236
|
+
version: 1,
|
|
237
|
+
status: "succeeded",
|
|
238
|
+
evidenceName: options.evidenceName,
|
|
239
|
+
scheme: options.scheme,
|
|
240
|
+
network: options.network,
|
|
241
|
+
target: options.target,
|
|
242
|
+
manifestDir: options.manifestDir,
|
|
243
|
+
proxy: options.proxy.toLowerCase(),
|
|
244
|
+
implementation: options.implementation.toLowerCase(),
|
|
245
|
+
contract: options.contract,
|
|
246
|
+
constructorArgs: options.constructorArgs,
|
|
247
|
+
transactionHash: options.transactionHash.toLowerCase(),
|
|
248
|
+
syncReportPath: path.relative(options.root, syncReportPath).split(path.sep).join("/"),
|
|
249
|
+
syncReportHash: crypto.createHash("sha256").update(syncReportBytes).digest("hex"),
|
|
250
|
+
manifestTransaction: syncReport,
|
|
251
|
+
completedAt: syncReport.completedAt,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
export const syncGateToolUups = async (
|
|
255
|
+
options: SyncGateToolUupsOptions,
|
|
256
|
+
): Promise<GateToolSyncEvidence> => {
|
|
257
|
+
if (!SAFE_FILE_ID.test(options.evidenceName)) {
|
|
258
|
+
throw new Error(`GateTool sync evidenceName must match ${SAFE_FILE_ID}`);
|
|
259
|
+
}
|
|
260
|
+
if (!TRANSACTION_HASH.test(options.transactionHash)) {
|
|
261
|
+
throw new Error("GateTool sync requires a confirmed transaction hash");
|
|
262
|
+
}
|
|
263
|
+
const evidenceDir = confinedPath(
|
|
264
|
+
options.root,
|
|
265
|
+
options.evidenceDir,
|
|
266
|
+
"GateTool sync evidence directory",
|
|
267
|
+
);
|
|
268
|
+
const outputPath = confinedPath(
|
|
269
|
+
options.root,
|
|
270
|
+
path.join(evidenceDir, `${options.evidenceName}-sync.json`),
|
|
271
|
+
"GateTool sync evidence",
|
|
272
|
+
);
|
|
273
|
+
const syncReportSnapshotPath = confinedPath(
|
|
274
|
+
options.root,
|
|
275
|
+
path.join(evidenceDir, `${options.evidenceName}-manifest-transaction.json`),
|
|
276
|
+
"GateTool manifest transaction snapshot",
|
|
277
|
+
);
|
|
278
|
+
const syncMetadataPath = confinedPath(
|
|
279
|
+
options.root,
|
|
280
|
+
path.join(evidenceDir, `${options.evidenceName}-manifest-transaction-metadata.json`),
|
|
281
|
+
"GateTool manifest transaction metadata",
|
|
282
|
+
);
|
|
283
|
+
const relativeOutputPath = path.relative(options.root, outputPath).split(path.sep).join("/");
|
|
284
|
+
if (fs.existsSync(outputPath)) {
|
|
285
|
+
const outputBytes = readRegularBytes(outputPath, "GateTool sync evidence");
|
|
286
|
+
const data = jsonFromBytes(outputBytes, "GateTool sync evidence");
|
|
287
|
+
if (!fs.existsSync(syncMetadataPath)) {
|
|
288
|
+
throw new Error("GateTool sync evidence is missing its immutable identity metadata");
|
|
289
|
+
}
|
|
290
|
+
const metadataBytes = readRegularBytes(
|
|
291
|
+
syncMetadataPath,
|
|
292
|
+
"GateTool manifest transaction metadata",
|
|
293
|
+
);
|
|
294
|
+
if (!outputBytes.equals(metadataBytes)) {
|
|
295
|
+
throw new Error("GateTool sync evidence does not match its immutable identity metadata");
|
|
296
|
+
}
|
|
297
|
+
validateExistingEvidence(data, options, syncReportSnapshotPath);
|
|
298
|
+
return { outputPath: relativeOutputPath, data };
|
|
299
|
+
}
|
|
300
|
+
if (fs.existsSync(syncMetadataPath)) {
|
|
301
|
+
const metadataBytes = readRegularBytes(
|
|
302
|
+
syncMetadataPath,
|
|
303
|
+
"GateTool manifest transaction metadata",
|
|
304
|
+
);
|
|
305
|
+
const data = jsonFromBytes(
|
|
306
|
+
metadataBytes,
|
|
307
|
+
"GateTool manifest transaction metadata",
|
|
308
|
+
);
|
|
309
|
+
if (!metadataBytes.equals(canonicalJsonBytes(data))) {
|
|
310
|
+
throw new Error("GateTool manifest transaction metadata must be canonical JSON");
|
|
311
|
+
}
|
|
312
|
+
const binding = validateEvidenceBinding(
|
|
313
|
+
data,
|
|
314
|
+
options,
|
|
315
|
+
syncReportSnapshotPath,
|
|
316
|
+
);
|
|
317
|
+
writeImmutableFile(
|
|
318
|
+
syncReportSnapshotPath,
|
|
319
|
+
binding.syncReportBytes,
|
|
320
|
+
options.root,
|
|
321
|
+
"GateTool manifest transaction snapshot",
|
|
322
|
+
);
|
|
323
|
+
validateExistingEvidence(data, options, syncReportSnapshotPath);
|
|
324
|
+
writeJsonFile(outputPath, data);
|
|
325
|
+
return { outputPath: relativeOutputPath, data };
|
|
326
|
+
}
|
|
327
|
+
if (fs.existsSync(syncReportSnapshotPath)) {
|
|
328
|
+
throw new Error(
|
|
329
|
+
"GateTool manifest transaction snapshot is missing immutable identity metadata",
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const rawResult = record(await syncWithHre({
|
|
334
|
+
scheme: options.scheme,
|
|
335
|
+
network: options.network,
|
|
336
|
+
target: options.target,
|
|
337
|
+
proxy: options.proxy,
|
|
338
|
+
contract: options.contract,
|
|
339
|
+
constructorArgs: options.constructorArgs,
|
|
340
|
+
...(options.scheme === "evm"
|
|
341
|
+
? { skipTxHash: true }
|
|
342
|
+
: { transactionHash: options.transactionHash }),
|
|
343
|
+
}, options.hre ?? hardhat, options.root), "GateTool sync result");
|
|
344
|
+
const returnedProxy = typeof rawResult.proxyAddress === "string"
|
|
345
|
+
? rawResult.proxyAddress
|
|
346
|
+
: stringField(rawResult, "proxy");
|
|
347
|
+
const returnedImplementation = typeof rawResult.implementationAddress === "string"
|
|
348
|
+
? rawResult.implementationAddress
|
|
349
|
+
: stringField(rawResult, "implementation");
|
|
350
|
+
if (
|
|
351
|
+
!sameAddress(returnedProxy, options.proxy)
|
|
352
|
+
|| !sameAddress(returnedImplementation, options.implementation)
|
|
353
|
+
) {
|
|
354
|
+
throw new Error("GateTool sync result does not match the confirmed UUPS chain state");
|
|
355
|
+
}
|
|
356
|
+
const returnedSyncReport = record(
|
|
357
|
+
rawResult.manifestTransaction,
|
|
358
|
+
"GateTool returned manifest transaction",
|
|
359
|
+
);
|
|
360
|
+
validateManifestTransaction(returnedSyncReport, options);
|
|
361
|
+
const returnedSyncReportBytes = canonicalJsonBytes(returnedSyncReport);
|
|
362
|
+
|
|
363
|
+
const syncReportPath = confinedPath(
|
|
364
|
+
options.root,
|
|
365
|
+
stringField(rawResult, "syncReport"),
|
|
366
|
+
"GateTool manifest transaction report",
|
|
367
|
+
);
|
|
368
|
+
const sourceSyncReportBytes = readRegularBytes(
|
|
369
|
+
syncReportPath,
|
|
370
|
+
"GateTool manifest transaction report",
|
|
371
|
+
);
|
|
372
|
+
if (!sourceSyncReportBytes.equals(returnedSyncReportBytes)) {
|
|
373
|
+
throw new Error(
|
|
374
|
+
"GateTool source report does not match its returned manifest transaction",
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const data = buildSyncEvidence(
|
|
379
|
+
options,
|
|
380
|
+
syncReportSnapshotPath,
|
|
381
|
+
returnedSyncReportBytes,
|
|
382
|
+
returnedSyncReport,
|
|
383
|
+
);
|
|
384
|
+
writeImmutableFile(
|
|
385
|
+
syncMetadataPath,
|
|
386
|
+
canonicalJsonBytes(data),
|
|
387
|
+
options.root,
|
|
388
|
+
"GateTool manifest transaction metadata",
|
|
389
|
+
);
|
|
390
|
+
writeImmutableFile(
|
|
391
|
+
syncReportSnapshotPath,
|
|
392
|
+
returnedSyncReportBytes,
|
|
393
|
+
options.root,
|
|
394
|
+
"GateTool manifest transaction snapshot",
|
|
395
|
+
);
|
|
396
|
+
writeJsonFile(outputPath, data);
|
|
397
|
+
return { outputPath: relativeOutputPath, data };
|
|
398
|
+
};
|