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

docs: add scripts and section to help with ZRC20 deployment for ZRC20 upgrade #418

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Oct 29, 2024

Add instruction for ZRC20 upgrade

Summary by CodeRabbit

  • New Features
    • Added a detailed deployment guide for ZRC20 reference contracts in the README.
    • Introduced two utility scripts:
      • get_zrc20_info.sh for retrieving ZRC20 contract attributes.
      • compare_zrc20_info.sh for comparing attributes between two ZRC20 contracts.
  • Documentation
    • Updated descriptions and instructions in the README for clarity on deployment processes and script usage.

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

📝 Walkthrough

Walkthrough

The changes introduce new utility scripts and a detailed deployment process for a ZRC20 reference contract in the readme.md file. The deployment instructions include using specific scripts to retrieve constructor arguments and verify contract attributes. The new Bash scripts, get_zrc20_info.sh and compare_zrc20_info.sh, facilitate the retrieval and comparison of ZRC20 contract attributes, respectively. Additionally, the description of an existing deployment script has been clarified.

Changes

File Path Change Summary
v2/scripts/deploy/readme.md New section on deploying a ZRC20 reference contract; mentions utility scripts for deployment.
v2/scripts/utils/get_zrc20_info.sh New script to retrieve attributes of a ZRC20 contract using provided address and RPC URL.
v2/scripts/utils/compare_zrc20_info.sh New script to compare attributes between two ZRC20 contracts on the blockchain.

Possibly related PRs

Suggested reviewers

  • fadeev
  • CharlieMc0
  • andresaiello
  • brewmaster012
  • fbac
  • skosito

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lumtis lumtis linked an issue Oct 29, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.27%. Comparing base (5774038) to head (a931f5a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #418   +/-   ##
=======================================
  Coverage   84.27%   84.27%           
=======================================
  Files           8        8           
  Lines         388      388           
  Branches      123      123           
=======================================
  Hits          327      327           
  Misses         61       61           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Outside diff range and nitpick comments (4)
v2/scripts/utils/get_zrc20_info.sh (1)

1-10: Enhance documentation with examples and error scenarios.

The documentation is clear but could be more helpful by including:

  • Example command with actual values
  • Sample output format
  • Common error scenarios and troubleshooting steps

Add these sections to the documentation:

 # Usage:
 #   ./get_zrc20_info.sh <contract_address> <rpc_url>
+#
+# Example:
+#   ./get_zrc20_info.sh 0x1234...5678 https://rpc.example.com
+#
+# Output Format:
+#   SYSTEM_CONTRACT=0x...
+#   ZRC20_NAME=Token Name
+#   ZRC20_SYMBOL=TKN
+#   ...
+#
+# Common Errors:
+#   - "Error: Contract not found": Verify contract address and RPC URL
+#   - "Method not found": Contract might not be a valid ZRC20
v2/scripts/utils/compare_zrc20_info.sh (1)

1-8: Consider enhancing the script documentation.

While the current documentation is clear, consider adding:

  • Example output to show the expected format
  • Description of exit codes
  • License header to match the project's open-source nature
v2/scripts/deploy/readme.md (2)

87-93: LGTM! Consider adding a note about proxy patterns.

The introduction clearly explains the upgrade process. To enhance clarity, consider adding a brief explanation of why this contract doesn't follow the ERC1967Proxy standard, as this might help developers better understand the architectural decision.


96-98: Add language specifiers to code blocks.

For better syntax highlighting and documentation consistency, add language specifiers to the code blocks:

-```
+```shell
./scripts/utils/get_zrc20_info.sh <zrc20_address> <rpc>

- +properties
SYSTEM_CONTRACT=0xEdf...795B
...




Also applies to: 104-112

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary>

96-96: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</details>

</details>

<details>
<summary>📜 Review details</summary>

**Configuration used: .coderabbit.yaml**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Files that changed from the base of the PR and between 577403818960651383532c665ac1dba92d41f397 and a931f5a83f572f6113678b5ab9c6781de3d734ca.

</details>

<details>
<summary>📒 Files selected for processing (3)</summary>

* v2/scripts/deploy/readme.md (2 hunks)
* v2/scripts/utils/compare_zrc20_info.sh (1 hunks)
* v2/scripts/utils/get_zrc20_info.sh (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>v2/scripts/deploy/readme.md</summary>

[grammar] ~126-~126: Did you mean “verifying”? Or maybe you should add a pronoun? In active voice, ‘allow’ + ‘to’ takes an object, usually a pronoun.
Context: ...nt, the following utility script allows to verify the ZRC20 has been deployed with the co...

(ALLOW_TO)

</details>

</details>
<details>
<summary>🪛 Markdownlint</summary>

<details>
<summary>v2/scripts/deploy/readme.md</summary>

96-96: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

104-104: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

115-115: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

127-127: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (5)</summary>

<details>
<summary>v2/scripts/utils/get_zrc20_info.sh (2)</summary>

`24-26`: **LGTM!**

Variable assignments are clear and well-named.

---

`28-35`: _:warning: Potential issue_

**Add error handling for RPC calls and improve robustness.**

The current implementation has several potential issues:
1. No error handling for failed RPC calls
2. No validation of contract responses
3. Sequential RPC calls might be slow

Implement error handling and response validation:

```diff
+# Function to make RPC calls with error handling
+make_rpc_call() {
+    local result
+    if ! result=$(cast call "$CONTRACT_ADDRESS" "$1" --rpc-url "$RPC_URL" 2>&1); then
+        echo "Error calling $1: $result" >&2
+        exit 1
+    fi
+    echo "$result"
+}
+
 # Run the cast commands and capture the outputs
-SYSTEM_CONTRACT=$(cast call "$CONTRACT_ADDRESS" "SYSTEM_CONTRACT_ADDRESS()(address)" --rpc-url "$RPC_URL" | tr -d '\n')
+SYSTEM_CONTRACT=$(make_rpc_call "SYSTEM_CONTRACT_ADDRESS()(address)" | tr -d '\n')
+
+# Validate system contract address format
+if ! [[ $SYSTEM_CONTRACT =~ ^0x[a-fA-F0-9]{40}$ ]]; then
+    echo "Error: Invalid system contract address returned: $SYSTEM_CONTRACT"
+    exit 1
+fi
+
 # Continue with other calls using make_rpc_call...

Let's verify the contract interface:

v2/scripts/utils/compare_zrc20_info.sh (1)

53-53: Verify completeness of ZRC20 attributes.

Please confirm that the ATTRIBUTES array includes all necessary fields for validating a ZRC20 upgrade. Consider checking the ZRC20 specification or existing contracts to ensure no critical attributes are missing.

✅ Verification successful

All necessary ZRC20 attributes are being verified

The ATTRIBUTES array in compare_zrc20_info.sh correctly includes all the essential attributes from the ZRC20 contract implementation:

  • SYSTEM_CONTRACT_ADDRESS - System contract reference
  • name, symbol, decimals - Standard token metadata
  • CHAIN_ID - Chain identifier
  • COIN_TYPE - Token type identifier
  • GAS_LIMIT - Gas limit for operations

The script's attribute list matches all the key immutable and configurable properties defined in the ZRC20 contract that need to be compared during upgrades.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ZRC20 interface definitions and implementations
rg -A 10 "contract.*ZRC20.*{" 

Length of output: 131


Script:

#!/bin/bash
# Search for ZRC20 interface or contract definitions
rg -l "ZRC20"

# Search for attribute definitions or constants in ZRC20-related files
rg -A 5 "(constant|attribute|field|property)" $(rg -l "ZRC20")

Length of output: 66664


Script:

#!/bin/bash
# Search for ZRC20 interface and implementation to find all attributes
rg -A 10 "interface.*ZRC20|contract.*ZRC20" v2/contracts/zevm/interfaces/IZRC20.sol v2/contracts/zevm/ZRC20.sol

# Search for attribute usage in get_zrc20_info.sh
cat v2/scripts/utils/get_zrc20_info.sh

Length of output: 7256

v2/scripts/deploy/readme.md (2)

156-156: LGTM! Clear description of dual purpose.

The updated description clearly communicates that the script serves both testing and upgrade processes.


102-112: Consider security implications of example values.

The example shows real contract addresses. Consider:

  1. Using placeholder addresses (e.g., 0x123...abc) in documentation
  2. Adding a warning about keeping contract addresses and configuration secure

Let's verify if these addresses are sensitive:

🧰 Tools
🪛 Markdownlint

104-104: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

Copy link
Contributor

@fbac fbac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I reviewed these scripts as part of the other PR and posted some thoughts.

@lumtis lumtis merged commit 18d5c12 into main Oct 29, 2024
11 checks passed
@lumtis lumtis deleted the docs/zrc20-deployments branch October 29, 2024 14:24
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

Successfully merging this pull request may close these issues.

Add documentation for ZRC20 deployment
4 participants