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

Potential issue with contracts/scripts/verify-deployed-contract.ts #473

Open
tudorpintea999 opened this issue Nov 2, 2023 · 0 comments
Open

Comments

@tudorpintea999
Copy link

The script provided is a Node.js program that uses the ethers library to deploy contracts and verify their bytecode against a deployed version on Ethereum. Here are a few observations and potential issues:

  1. Environment Variable Assumption:
    The line const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, ... assumes that the environment variable ZKSYNC_HOME is set. If it's not set, this could cause the script to fail. It's a good practice to check if the environment variable exists and provide a clear error message if not.

  2. Error Handling for JSON Parsing:
    The script reads and parses a JSON file without a try-catch block, which could throw an unhandled exception if the file is not found or the JSON is malformed:

    const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

    It would be safer to wrap this in a try-catch block to handle potential errors gracefully.

  3. Commander Usage:
    The Command object from the commander package is used to define command-line options. However, the .description() method is chained after .option() calls, which might not set the description as intended for the command. The .description() method should be chained directly to the program object.

  4. Potential Issue with Asynchronous Execution:
    The action callback within the program definition is an asynchronous function. It's important to ensure that commander supports asynchronous actions, otherwise, the script may not work as expected or may exit before the asynchronous operations complete.

  5. Redundant Code:
    The if statements checking for the contract type and deploying them could be refactored to reduce redundancy. A switch statement or a mapping object could be used to map contract names to deploy functions, which would make the code cleaner and more maintainable.

  6. Bytecode Comparison:
    The script compares the bytecode of the local and remote contracts with localBytecode === remoteBytecode. This is a strict comparison and assumes that the bytecodes must match exactly. Any slight difference, including metadata or constructor parameters, will cause this comparison to fail. It's important to ensure that such differences are accounted for or documented.

  7. Error Handling in Main Function:
    The main function catches errors and logs them, which is good practice. However, it might be beneficial to log the full error stack for debugging purposes, not just the message.

  8. Use of process.exit:
    Using process.exit() can be considered bad practice because it forces the process to terminate immediately, possibly interrupting asynchronous operations that are still pending. It's better to let the process exit naturally after the event loop is empty unless there's a specific reason to terminate immediately.

  9. No await on fs.readFileSync:
    The fs.readFileSync function is used, which is synchronous and can block the event loop. If the file is large or the file system is slow, this could cause performance issues. Consider using the asynchronous version fs.promises.readFile with await for better performance in an I/O-heavy application.

  10. Potential Unhandled Promises:
    The script uses await within the action callback without a surrounding try-catch block. If any of the promises reject, it could lead to an unhandled promise rejection.

  11. Missing await in Action Callback:
    The action callback is an async function, but the call to verify does not use await. This could lead to issues where the process.exit(0) is called before the verify function completes its execution.

  12. Commander Action Parameters:
    The action callback is using (cmd: Command) as a parameter, but typically the parameters passed to the action callback are the options defined in the command. This might not cause a functional issue, but it could be misleading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@tudorpintea999 and others