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

fix: resolve bug in code #157

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand Down
12 changes: 11 additions & 1 deletion scripts/setup-tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ 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}
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) {
Expand All @@ -26,6 +29,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}"}`;

Expand All @@ -42,6 +47,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...");
Expand All @@ -67,6 +74,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) {
Expand All @@ -75,6 +83,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<Wallet> {
let wallet: Wallet;

Expand All @@ -96,6 +105,7 @@ async function getOrCreateWallet(filePath: string): Promise<Wallet> {
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)}`);
Expand Down
26 changes: 20 additions & 6 deletions scripts/slither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ 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;

Expand All @@ -21,7 +28,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?",
Expand All @@ -30,25 +37,27 @@ 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",
},
]);

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...");

Expand All @@ -63,19 +72,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) => {
Expand Down