From 8f155fc708d7ac01440062f1567936d7531a0cf2 Mon Sep 17 00:00:00 2001 From: Maksym Pyvovarov <119981087+maxpv026@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:28:45 +0200 Subject: [PATCH 1/6] Update setup-tutorial.ts provided comments for each function describing their purpose and made some minor improvements for clarity. Additionally, I've used typescript syntax for better readability. --- scripts/setup-tutorial.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/setup-tutorial.ts b/scripts/setup-tutorial.ts index 5e56cdde..5902c874 100644 --- a/scripts/setup-tutorial.ts +++ b/scripts/setup-tutorial.ts @@ -2,13 +2,16 @@ import { Wallet } from "ethers"; import * as fs from "fs"; import * as https from "https"; +// Path to the JSON file storing wallet information const jsonPath = "scripts/.wallet.json"; +// Interface defining the structure of the wallet configuration interface WalletConfig { address: string; privateKey: string; } +// Function to save environment files with wallet information function saveEnvFiles(address: string, privateKey: string): void { const value: string = ` PRIVATE_KEY=${privateKey} @@ -16,6 +19,7 @@ ZETA_NETWORK=athens EXECUTE_PROGRAMMATICALLY=true`; const filePaths: string[] = ["packages/example-contracts/.env", "packages/zevm-example-contracts/.env"]; + // Write wallet information to each environment file filePaths.forEach((filePath: string) => { fs.writeFile(filePath, value, (err: NodeJS.ErrnoException | null) => { if (err) { @@ -26,6 +30,8 @@ EXECUTE_PROGRAMMATICALLY=true`; }); }); } + +// Function to save wallet information to a JSON file function saveWalletFile(address: string, privateKey: string, jsonPath: string): void { const data = `{"address": "${address}", "privateKey": "${privateKey}"}`; @@ -42,6 +48,8 @@ function saveWalletFile(address: string, privateKey: string, jsonPath: string): } }); } + +// Function to call the faucet and request testnet assets function callFaucet(address: string): void { // Hit Faucet to get some testnet Zeta console.log("Requesting testnet assets from the faucet..."); @@ -67,6 +75,7 @@ function callFaucet(address: string): void { req.end(); } +// Function to check if the wallet file exists, and execute a callback if it does function createWallet(filePath: string, callback: () => void): void { fs.access(filePath, (err) => { if (!err) { @@ -75,6 +84,7 @@ function createWallet(filePath: string, callback: () => void): void { }); } +// Function to get or create a wallet based on the wallet file async function getOrCreateWallet(filePath: string): Promise { let wallet: Wallet; @@ -96,6 +106,7 @@ async function getOrCreateWallet(filePath: string): Promise { return wallet; } +// Main function to get or create a wallet, and perform necessary actions const wallet = getOrCreateWallet(jsonPath).then(async (wallet) => { console.log(`Your Wallet Address: ${wallet.address}`); console.log(`Your Private Key: ${wallet.privateKey.substring(2)}`); From ef78335dd31a686852e2fcd2ce06088741ce3ded Mon Sep 17 00:00:00 2001 From: Maksym Pyvovarov <119981087+maxpv026@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:29:57 +0200 Subject: [PATCH 2/6] Update slither.ts Provided comments for each function describing their purpose in English and made some minor improvements for clarity. Additionally, I've used javascript syntax for better readability. --- scripts/slither.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/scripts/slither.ts b/scripts/slither.ts index 92c0c7a2..1344095f 100644 --- a/scripts/slither.ts +++ b/scripts/slither.ts @@ -2,11 +2,19 @@ import inquirer from "inquirer"; import { execSync } from "node:child_process"; import path from "node:path"; +// Root directory of the project const projectRoot = path.join(__dirname, "../"); + +// Solidity compiler version const solcVersion = "0.8.7"; + +// Timestamp for unique file naming const timestamp = Date.now(); + +// List of package names to choose from const packageNames = ["protocol-contracts", "example-contracts"]; +// Function to get the package name based on user input async function getPackageName() { let packageName; @@ -21,7 +29,7 @@ async function getPackageName() { return packageName; } else { - packageName = await inquirer.prompt([ + const { contracts } = await inquirer.prompt([ { choices: packageNames, message: "Which set of contracts would you like to test?", @@ -30,17 +38,18 @@ async function getPackageName() { }, ]); - return packageName.contracts; + return contracts; } } +// Function to get the filter paths based on user input async function getFilterPaths() { if (process.env.CI) return ""; - const { confirm: includeLibraries } = await inquirer.prompt([ + const { includeLibraries } = await inquirer.prompt([ { message: "Do you want to include OpenZeppelin & Uniswap libraries in this scan?", - name: "confirm", + name: "includeLibraries", type: "confirm", }, ]); @@ -48,7 +57,8 @@ async function getFilterPaths() { return includeLibraries ? "" : `--filter-paths "node_modules/@openzeppelin/","node_modules/@uniswap/"`; } -const run = async (command: string) => { +// Function to execute a shell command +const run = async (command) => { try { console.log("Starting -- This may take a few minutes..."); @@ -63,19 +73,24 @@ const run = async (command: string) => { console.error(`${error}`); } }; -function runSlither(packageName: string, filterPaths: string) { + +// Function to run Slither analysis +function runSlither(packageName, filterPaths) { const dockerCommand = `cd /home/trufflecon/packages/${packageName} && \ solc-select use ${solcVersion} && \ slither --json ../../scripts/slither-results/${packageName}-${timestamp}.json \ --sarif ../../scripts/slither-results/${packageName}-${timestamp}.sarif \ --checklist ./ ${filterPaths} | tee ../../scripts/slither-results/${packageName}-${timestamp}.md`; + run(`docker run -v "${projectRoot}":/home/trufflecon trailofbits/eth-security-toolbox -c "${dockerCommand}"`); } +// Main function to orchestrate Slither analysis async function main() { runSlither(await getPackageName(), await getFilterPaths()); } +// Execute the main function and handle errors main() .then(() => process.exit(0)) .catch((error) => { From 67a80ae5260bfeadc12dcd03e457ad7493044b26 Mon Sep 17 00:00:00 2001 From: Maksym Pyvovarov <119981087+maxpv026@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:32:34 +0200 Subject: [PATCH 3/6] Update .eslintrc.js added comments explaining the purpose of each section and made minor adjustments for clarity and readability. --- .eslintrc.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.eslintrc.js b/.eslintrc.js index a13a8dc2..7e2d9751 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,36 +6,53 @@ const OFF = 0; * @type {import("eslint").Linter.Config} */ module.exports = { + // Define the environment env: { browser: false, es2021: true, mocha: true, node: true, }, + // Use recommended Prettier configuration extends: ["plugin:prettier/recommended"], + // Use TypeScript parser parser: "@typescript-eslint/parser", parserOptions: { ecmaVersion: 12, }, + // Define ESLint plugins plugins: ["@typescript-eslint", "prettier", "simple-import-sort", "sort-keys-fix", "typescript-sort-keys"], + // Define ESLint rules rules: { + // Enable sorting of type union/intersection members "@typescript-eslint/sort-type-union-intersection-members": "error", + // Disable camelcase rule camelcase: "off", + // Disable no-console rule "no-console": OFF, + // Enable sorting of exports "simple-import-sort/exports": "error", + // Enable sorting of imports "simple-import-sort/imports": "error", + // Enable sorting of object keys "sort-keys-fix/sort-keys-fix": "error", + // Enable sorting of interface keys "typescript-sort-keys/interface": "error", + // Enable sorting of string enum keys "typescript-sort-keys/string-enum": "error", }, + // Define ESLint settings settings: { + // Configure import parser for TypeScript "import/parsers": { "@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx", ".d.ts"], }, + // Configure import resolver for TypeScript "import/resolver": { node: { extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"], }, + // Specify the TypeScript project path typescript: { project: path.join(__dirname, "tsconfig.json"), }, From 404d21af252852a659b64d9fe4e93cfabab5a826 Mon Sep 17 00:00:00 2001 From: Maksym Pyvovarov <119981087+maxpv026@users.noreply.github.com> Date: Wed, 28 Feb 2024 20:21:38 +0200 Subject: [PATCH 4/6] fix: .eslintrc.js --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7e2d9751..afac71f6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,7 +20,7 @@ module.exports = { parserOptions: { ecmaVersion: 12, }, - // Define ESLint plugins + // Define ESLint plugins. plugins: ["@typescript-eslint", "prettier", "simple-import-sort", "sort-keys-fix", "typescript-sort-keys"], // Define ESLint rules rules: { From e985d8734c859b7811e3849ac9ac260a959d0978 Mon Sep 17 00:00:00 2001 From: Maksym Pyvovarov <119981087+maxpv026@users.noreply.github.com> Date: Wed, 28 Feb 2024 20:21:59 +0200 Subject: [PATCH 5/6] fix: setup-tutorial.ts --- scripts/setup-tutorial.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/setup-tutorial.ts b/scripts/setup-tutorial.ts index 5902c874..0118d634 100644 --- a/scripts/setup-tutorial.ts +++ b/scripts/setup-tutorial.ts @@ -10,7 +10,6 @@ interface WalletConfig { address: string; privateKey: string; } - // Function to save environment files with wallet information function saveEnvFiles(address: string, privateKey: string): void { const value: string = ` From deee81db0228628494df5e635b7da0cb910a5e5e Mon Sep 17 00:00:00 2001 From: Maksym Pyvovarov <119981087+maxpv026@users.noreply.github.com> Date: Wed, 28 Feb 2024 20:22:15 +0200 Subject: [PATCH 6/6] fix: slither.ts --- scripts/slither.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/slither.ts b/scripts/slither.ts index 1344095f..9ac3e0f6 100644 --- a/scripts/slither.ts +++ b/scripts/slither.ts @@ -7,7 +7,6 @@ const projectRoot = path.join(__dirname, "../"); // Solidity compiler version const solcVersion = "0.8.7"; - // Timestamp for unique file naming const timestamp = Date.now();