Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/remove reports from webapp #179

Merged
merged 21 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ COPY ./pnpm-workspace.yaml /app/pnpm-workspace.yaml
COPY ./packages/common/package.json /app/packages/common/package.json
COPY ./packages/contracts/package.json /app/packages/contracts/package.json
COPY ./packages/e2e/package.json /app/packages/e2e/package.json
COPY ./packages/ethereum-reports/package.json /app/packages/ethereum-reports/package.json
COPY ./packages/typescript-config/package.json /app/packages/typescript-config/package.json
COPY ./apps/web/package.json /app/apps/web/package.json
COPY ./apps/cli/package.json /app/apps/cli/package.json
Expand Down
1 change: 0 additions & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
},
"dependencies": {
"@repo/common": "workspace:*",
"@repo/ethereum-reports": "workspace:*",
"chalk": "^5.3.0",
"cli-table3": "^0.6.4",
"dotenv": "^16.4.5",
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/commands/check-command.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { EnvBuilder } from "../lib/env-builder.js";
import { hexToBytes } from "viem";
import { withSpinner } from "../lib/with-spinner.js";
import { ZksyncEraState } from "@repo/ethereum-reports/zksync-era-state";
import { ZkSyncEraDiff } from "@repo/ethereum-reports/zk-sync-era-diff";
import { ZksyncEraState } from "../reports/zksync-era-state";
import { ZkSyncEraDiff } from "../reports/zk-sync-era-diff";
import { DIAMOND_ADDRS } from "@repo/common/ethereum";
import { StringCheckReport } from "@repo/ethereum-reports/reports/string-check-report";
import { UpgradeFile } from "../lib/upgrade-file";
import { StringCheckReport } from "../reports/reports/string-check-report";

export async function checkCommand(env: EnvBuilder, upgradeFilePath: string) {
const dataHex = UpgradeFile.fromFile(upgradeFilePath)
Expand Down
9 changes: 5 additions & 4 deletions apps/cli/src/commands/download-code-command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ContractData, ADDRESS_ZERO, OPEN_ZEP_PROXY_IMPL_SLOT } from "@repo/common/ethereum";
import type { GitContractsRepo } from "@repo/ethereum-reports/git-contracts-repo";
import { ZkSyncEraDiff, hexAreEq } from "@repo/ethereum-reports/zk-sync-era-diff";
import { type HexEraPropName, ZksyncEraState } from "@repo/ethereum-reports/zksync-era-state";
import { ADDRESS_ZERO, OPEN_ZEP_PROXY_IMPL_SLOT } from "@repo/common/ethereum";
import type { GitContractsRepo } from "../reports/git-contracts-repo";
import { ZkSyncEraDiff, hexAreEq } from "../reports/zk-sync-era-diff";
import { type HexEraPropName, ZksyncEraState } from "../reports/zksync-era-state";
import type { EnvBuilder } from "../lib/env-builder.js";
import { withSpinner } from "../lib/with-spinner.js";
import path from "node:path";
import { hexToBigInt, hexToBytes } from "viem";
import { UpgradeFile } from "../lib/upgrade-file";
import { ContractData } from "../ethereum/contract-data";

async function downloadAllCode(
diff: ZkSyncEraDiff,
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/fail-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Argv } from "yargs";
import type { EnvBuilder } from "../lib/env-builder.js";
import { printError } from "@repo/common/ethereum";
import { printError } from "../lib/errors";

export async function failHandler(
env: EnvBuilder,
Expand Down
16 changes: 6 additions & 10 deletions apps/cli/src/commands/storage-change-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import type { Hex } from "viem";
import { Option } from "nochoices";
import { withSpinner } from "../lib/with-spinner.js";
import { DIAMOND_ADDRS } from "@repo/common/ethereum";
import { type MemoryDiffRaw, memoryDiffParser } from "@repo/common/schemas";
import {
ListOfAddressesExtractor,
FacetsToSelectorsVisitor,
} from "@repo/ethereum-reports/reports/extractors";
import { StringStorageChangeReport } from "@repo/ethereum-reports/reports/string-storage-change-report";
import { RecordStorageSnapshot } from "@repo/ethereum-reports/storage/snapshot/record-storage-snapshot";
import { RpcStorageSnapshot } from "@repo/ethereum-reports/storage/snapshot/rpc-storage-snapshot";
import { StorageChanges } from "@repo/ethereum-reports/storage/storage-changes";
import { MAIN_CONTRACT_FIELDS } from "@repo/ethereum-reports/storage/storage-props";
import { UpgradeFile } from "../lib/upgrade-file";
import { RecordStorageSnapshot, RpcStorageSnapshot } from "../reports/storage/snapshot";
import { MAIN_CONTRACT_FIELDS } from "../reports/storage/storage-props";
import { FacetsToSelectorsVisitor, ListOfAddressesExtractor } from "../reports/reports/extractors";
import { StorageChanges } from "../reports/storage/storage-changes";
import { StringStorageChangeReport } from "../reports/reports/string-storage-change-report";
import { type MemoryDiffRaw, memoryDiffParser } from "../ethereum/rpc-client";

async function getMemoryPath(
preCalculatedPath: Option<string>,
Expand Down
8 changes: 4 additions & 4 deletions apps/cli/src/commands/storage-snapshot-command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DIAMOND_ADDRS } from "@repo/common/ethereum";
import { SnapshotReport } from "@repo/ethereum-reports/reports/storage-snapshot-report";
import { RpcStorageSnapshot } from "@repo/ethereum-reports/storage/snapshot/rpc-storage-snapshot";
import { mainDiamondFields } from "@repo/ethereum-reports/storage/storage-props";
import { ZksyncEraState } from "@repo/ethereum-reports/zksync-era-state";
import { ZksyncEraState } from "../reports/zksync-era-state";
import type { EnvBuilder } from "../lib/env-builder.js";
import { RpcStorageSnapshot } from "../reports/storage/snapshot";
import { SnapshotReport } from "../reports/reports/storage-snapshot-report";
import { mainDiamondFields } from "../reports/storage/storage-props";

export async function storageSnapshotCommand(env: EnvBuilder): Promise<void> {
const rpc = env.rpcL1();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import { z, type ZodType } from "zod";
import type { Hex } from "viem";
import { addressSchema, contractEventSchema, type ContractEvent } from "@repo/common/schemas";
import { addressSchema, hexSchema } from "@repo/common/schemas";
import { ContractAbi } from "./contract-abi";
import { ContractData } from "./contract-data";
import { ContractNotVerified, ExternalApiError } from "./errors";
import { getAbiSchema, sourceCodeResponseSchema, sourceCodeSchema } from "../schemas/etherscan";
import { ERA_BLOCK_EXPLORER_ENDPOINTS, ETHERSCAN_ENDPOINTS, type Network } from "./constants";
import { ContractNotVerified, ExternalApiError } from "../lib/errors";
import {
ERA_BLOCK_EXPLORER_ENDPOINTS,
ETHERSCAN_ENDPOINTS,
type Network,
} from "@repo/common/ethereum";

export const contractEventSchema = z.object({
address: hexSchema,
topics: z.array(hexSchema),
data: hexSchema,
transactionHash: hexSchema,
blockNumber: hexSchema,
});

export type ContractEvent = z.infer<typeof contractEventSchema>;

const sourcesParser = z.record(z.string(), z.object({ content: z.string() }));
export const sourceCodeSchema = z.object({
language: z.string(),
sources: sourcesParser,
});

export const numericString = z.string().regex(/^[0-9]*$/, "Invalid number");

export const getAbiSchema = z.object({
status: numericString,
message: z.enum(["OK", "NOTOK"]),
result: z.string(),
});

export const etherscanSourceCodeSchema = z.object({
SourceCode: z.string(),
ABI: z.string(),
ContractName: z.string(),
CompilerVersion: z.string(),
OptimizationUsed: z.string(),
Runs: z.string(),
ConstructorArguments: z.string(),
EVMVersion: z.string(),
Library: z.string(),
LicenseType: z.string(),
Proxy: z.string(),
Implementation: z.string(),
SwarmSource: z.string(),
});

export const sourceCodeResponseSchema = z.object({
status: numericString,
message: z.enum(["OK", "NOTOK"]),
result: z.array(etherscanSourceCodeSchema),
});

export interface BlockExplorer {
getAbi(rawAddress: string): Promise<ContractAbi>;
Expand Down Expand Up @@ -35,7 +84,7 @@ export class BlockExplorerClient implements BlockExplorer {
parser: T
): Promise<z.infer<typeof parser>> {
// TODO: Make an option to avoid this
// This is to trottle the amount of request made to etherscan, because free plans
// This is to trottle the amount of request made to ethereum, because free plans
// rate limits the calls to 5 per second.
if (this.callCount % 5 === 4) {
await new Promise((resolve) => setTimeout(resolve, 1000));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import path from "node:path";
import fs from "node:fs/promises";
import type { Sources } from "../schemas/etherscan";
import { z } from "zod";

const sourcesSchema = z.record(z.string(), z.object({ content: z.string() }));
export type Sources = z.infer<typeof sourcesSchema>;

export class ContractData {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,46 @@ import {
import { type TypeOf, z, type ZodType } from "zod";
import type { PublicClient, HttpTransport } from "viem";
import { getStorageAt } from "viem/actions";
import {
callTracerSchema,
contractEventSchema,
memoryDiffParser,
type CallTrace,
type MemoryDiffRaw,
} from "../schemas/index";
import { L1_DEFAULT_URLS, L2_DEFAULT_URLS, type Network } from "./constants";
import { L1_DEFAULT_URLS, L2_DEFAULT_URLS, type Network } from "@repo/common/ethereum";
import { hexSchema, optionSchema } from "@repo/common/schemas";

const stateParser = z.record(
z.string(),
z.object({
nonce: optionSchema(z.number()),
storage: optionSchema(z.record(z.string(), hexSchema)),
})
);

export const memoryDiffParser = z.object({
result: z.object({
post: stateParser,
pre: stateParser,
}),
});

export const contractEventSchema = z.object({
address: hexSchema,
topics: z.array(hexSchema),
data: hexSchema,
transactionHash: hexSchema,
blockNumber: hexSchema,
});

const baseCallTracerSchema = z.object({
from: z.string(),
to: z.string(),
input: z.string(),
});
export type CallTrace = z.infer<typeof baseCallTracerSchema> & {
calls?: CallTrace[];
};

export const callTracerSchema: z.ZodType<CallTrace> = baseCallTracerSchema.extend({
calls: z.lazy(() => callTracerSchema.array().optional()),
});

export type MemoryDiffRaw = z.infer<typeof memoryDiffParser>;

export class RpcClient {
private viemClient: PublicClient<HttpTransport>;
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function buildCli(
}
}, true)
.option("ethscankey", {
describe: "Api key for etherscan",
describe: "Api key for ethereum",
type: "string",
demandOption:
"Please provide a valid Etherscan api key. You can set ETHERSCAN_API_KEY env var or use the option --ethscankey",
Expand Down
8 changes: 5 additions & 3 deletions apps/cli/src/lib/env-builder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { FileSystem } from "./file-system.js";
import { Terminal } from "./terminal.js";
import { GitContractsRepo } from "@repo/ethereum-reports/git-contracts-repo";
import { BlockExplorerClient, NET_VERSIONS, RpcClient, type Network } from "@repo/common/ethereum";
import { GitContractsRepo } from "../reports/git-contracts-repo";
import { NET_VERSIONS, type Network } from "@repo/common/ethereum";
import { BlockExplorerClient } from "../ethereum/block-explorer-client";
import { RpcClient } from "../ethereum/rpc-client";

export class EnvBuilder {
private _etherscanApiKey?: string;
Expand Down Expand Up @@ -49,7 +51,7 @@ export class EnvBuilder {

get etherscanApiKey(): string {
if (!this._etherscanApiKey) {
throw new Error("Missing etherscan key");
throw new Error("Missing ethereum key");
}
return this._etherscanApiKey;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/lib/file-system.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs/promises";
import type { Stats } from "node:fs";
import { NotADir } from "@repo/common/ethereum";
import { NotADir } from "./errors";

export class FileSystem {
async readFile(path: string): Promise<Buffer> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { type Abi, bytesToHex, type Hex, hexToBytes, toFunctionSelector } from "viem";
import type {
BlockExplorer,
BlockExplorerClient,
ContractAbi,
ContractData,
RpcClient,
} from "@repo/common/ethereum";
import type { ZodType } from "zod";
import { facetsResponseSchema } from "./schema/new-facets.js";
import type { FacetData } from "./upgrade-changes.js";
import type { BlockExplorer, BlockExplorerClient } from "../ethereum/block-explorer-client";
import type { ContractAbi } from "../ethereum/contract-abi";
import type { ContractData } from "../ethereum/contract-data";
import type { RpcClient } from "../ethereum/rpc-client";

const DIAMOND_FUNCTIONS = {
facets: "facets",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "node:fs/promises";
import type { Stats } from "node:fs";
import path from "node:path";
import os from "node:os";
import { NotADir } from "@repo/common/ethereum";
import { NotADir } from "../lib/errors";

export async function directoryExists(path: string): Promise<boolean> {
let targetDirStat: Stats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { compiledArtifactParser } from "./schema/compiled.js";
import { utils } from "zksync-ethers";
import { type SystemContractHashes, systemContractHashesParser } from "./schema/github-schemas.js";
import { Option } from "nochoices";
import type { Sources } from "@repo/common/schemas";
import type { Sources } from "../ethereum/contract-data";

const execPromise = promisify(exec);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "../zksync-era-state.js";
import type { Hex } from "viem";
import type { Option } from "nochoices";
import type { BlockExplorer } from "@repo/common/ethereum";
import type { BlockExplorer } from "../../ethereum/block-explorer-client";

export type SystemContractUpgrade = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StorageSnapshot } from "../storage/snapshot/index.js";
import type { StorageSnapshot } from "../storage/snapshot";
import type { ContractField } from "../storage/contractField.js";
import { StringStorageVisitor } from "./string-storage-visitor.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CliTable from "cli-table3";
import { HEX_ZKSYNC_FIELDS, NUMERIC_ZKSYNC_FIELDS } from "../zksync-era-state.js";
import type { Hex } from "viem";
import chalk from "chalk";
import type { BlockExplorer } from "@repo/common/ethereum";
import type { BlockExplorer } from "../../ethereum/block-explorer-client";

export interface CheckReportOptions {
shortOutput: boolean;
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MemoryDataType } from "./types/data-type.js";
import type { Option } from "nochoices";

import type { StorageSnapshot } from "./snapshot/index.js";
import type { StorageSnapshot } from "./snapshot";
import type { StorageValue } from "./values/storage-value.js";

export class ContractField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MemoryDataType } from "./types/data-type.js";
import { Option } from "nochoices";
import { bytesToHex, hexToBigInt, keccak256, numberToBytes } from "viem";

import type { StorageSnapshot } from "./snapshot/index.js";
import type { StorageSnapshot } from "./snapshot";
import type { StorageValue } from "./values/storage-value.js";
import { EmptyValue } from "./values/empty-value.js";
import { MappingValue } from "./values/mapping-value.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { StorageSnapshot } from "./storage-snapshot.js";
import { Option } from "nochoices";
import { type Hex, hexToBytes } from "viem";
import { CompoundStorageSnapshot } from "./compound-storage-snapshot.js";
import type { RpcClient } from "@repo/common/ethereum";
import type { RpcClient } from "../../../ethereum/rpc-client";

export class RpcStorageSnapshot implements StorageSnapshot {
private rpc: RpcClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Option } from "nochoices";
import type { Hex } from "viem";
import type { ContractField } from "./contractField.js";
import type { StorageSnapshot } from "./snapshot/index.js";
import type { StorageSnapshot } from "./snapshot";
import { PropertyChange } from "./property-change.js";
import { mainDiamondFields } from "./storage-props.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MemoryDataType } from "./data-type.js";
import type { Option } from "nochoices";
import { bytesToHex, type Hex } from "viem";

import type { StorageSnapshot } from "../snapshot/index.js";
import type { StorageSnapshot } from "../snapshot";
import { AddressValue } from "../values/address-value.js";
import type { StorageValue } from "../values/storage-value.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MemoryDataType } from "./data-type.js";
import type { StorageSnapshot } from "../snapshot/index.js";
import type { StorageSnapshot } from "../snapshot";
import { Option } from "nochoices";
import { bytesToBigint } from "viem/utils";
import { hexToBigInt, keccak256, numberToBytes } from "viem";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MemoryDataType } from "./data-type.js";
import type { Option } from "nochoices";
import { bytesToBigInt } from "viem";

import type { StorageSnapshot } from "../snapshot/index.js";
import type { StorageSnapshot } from "../snapshot";
import { BigNumberValue } from "../values/big-number-value.js";
import type { StorageValue } from "../values/storage-value.js";

Expand Down
Loading
Loading