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!: tolerate v2 contracts in tss migration tests #3002

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Oct 11, 2024

Description

#2932 broke the tss migration tests because the V2 ERC20 custody contract did not have UpdateTSSAddress on the current protocol-contracts version (related to zeta-chain/protocol-contracts#363).

Use the latest version of protocol-contracts. This includes a consensus breaking change from zeta-chain/protocol-contracts#377.

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Enhanced transaction error messaging for better clarity on transaction outcomes.
    • Updated handling of amounts in transaction contexts to improve accuracy.
  • Bug Fixes

    • Improved method calls to ensure compatibility with the latest ERC20 custody standards.
  • Chores

    • Updated Go module version and dependencies for improved performance and feature support.

@gartnera gartnera added no-changelog Skip changelog CI check TSS_MIGRATION_TESTS Run TSS migration tests labels Oct 11, 2024
@lumtis lumtis marked this pull request as ready for review October 14, 2024 12:33
@lumtis lumtis added this pull request to the merge queue Oct 14, 2024
Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several updates across multiple files, primarily focusing on enhancing transaction handling and error reporting. Key changes include modifications to the E2ERunner struct to utilize ERC20CustodyV2, updates to error message formatting in transaction functions, and adjustments to the handling of the Amount field in the RevertContext struct. Additionally, the go.mod file has been updated to a newer Go version and includes updates to several dependencies.

Changes

File Path Change Summary
e2e/runner/admin_evm.go Updated UpdateTssAddressForErc20custody to reference r.ERC20CustodyV2 and modified TSS address retrieval.
e2e/utils/require.go Enhanced RequireTxSuccessful and RequiredTxFailed to include transaction hash in error messages.
x/fungible/keeper/v2_evm.go Modified CallExecuteRevert and CallDepositAndRevert to handle Amount as *big.Int directly.
zetaclient/chains/evm/signer/v2_sign.go Updated signGatewayExecuteRevert and signERC20CustodyWithdrawRevert to assign txData.amount directly to RevertContext.
go.mod Updated Go version from go1.22.2 to go1.22.5, modified several dependency versions, and added new dependencies.

Possibly related PRs

Suggested labels

breaking:cli, UPGRADE_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • skosito
  • ws4charlie
  • brewmaster012
  • swift1337

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.

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: 1

🧹 Outside diff range and nitpick comments (5)
e2e/runner/admin_evm.go (1)

29-38: Approve changes with minor suggestion for consistency

The modifications to use ERC20CustodyV2 are appropriate and align with the PR objectives. The added comment provides valuable clarity regarding the naming convention differences between v1 and v2.

To maintain consistency with the UpdateTssAddressForConnector method, consider updating the log message to include "V2" for clarity:

-r.Logger.Info(fmt.Sprintf("TSS ERC20 Address Update Tx: %s", tx.Hash().String()))
+r.Logger.Info(fmt.Sprintf("TSS ERC20V2 Address Update Tx: %s", tx.Hash().String()))

This minor change would make it explicit that the V2 contract is being updated, enhancing code readability and maintaining consistency with the changes made.

e2e/utils/require.go (2)

28-35: Approve changes with a minor suggestion for improvement.

The inclusion of the transaction hash in the error message is a valuable addition, providing more context for debugging failed tests. However, there's a minor inconsistency in the error message format.

Consider updating the error message format for clarity:

-	msg := "receipt status is not successful: %s"
+	msg := "receipt status is not successful (tx hash: %s)"

This change makes it explicit that the additional information is the transaction hash, improving readability of the error message.


Line range hint 1-48: Summary: Improved error reporting with minor suggestions for consistency.

The changes to RequireTxSuccessful and RequireTxFailed (formerly RequiredTxFailed) functions enhance error reporting by including transaction hashes. This addition provides valuable context for debugging failed tests.

To further improve these utility functions:

  1. Implement the suggested changes for consistent and clear error messaging.
  2. Consider reviewing other similar utility functions in this file or package to ensure they follow the same pattern of including relevant identifiers (like transaction hashes) in error messages.

Maintaining consistency in error reporting across test utilities is crucial for efficient debugging and test maintenance.

zetaclient/chains/evm/signer/v2_sign.go (1)

204-204: Approval: Consistent improvement in Amount field handling

The modification in the signERC20CustodyWithdrawRevert function mirrors the improvement made in signGatewayExecuteRevert. This change maintains consistency across the codebase and offers the same benefits of preserving precision for large numerical values.

Given the similarity of these changes, consider refactoring the RevertContext creation into a separate function to reduce code duplication and enhance maintainability. For example:

func createRevertContext(sender string, asset common.Address, amount *big.Int, revertMessage string) revert.RevertContext {
    return revert.RevertContext{
        Sender:        common.HexToAddress(sender),
        Asset:         asset,
        Amount:        amount,
        RevertMessage: revertMessage,
    }
}

This function could then be used in both signGatewayExecuteRevert and signERC20CustodyWithdrawRevert, promoting code reuse and consistency.

go.mod (1)

Inaccessible Replace Directives Identified

The replace directives in your go.mod file reference repositories that are currently inaccessible:

  • github.com/zeta-chain/tss-lib
  • github.com/zeta-chain/go-ethereum
  • github.com/zeta-chain/go-libp2p
  • github.com/zeta-chain/go-tss

This may lead to build issues or prevent dependency updates. Please verify that these replace directives are necessary and update their repository URLs accordingly.

🔗 Analysis chain

Line range hint 3-5: Approve Go version update and verify development environment.

The update to Go 1.22.5 is commendable, as it likely includes important security patches and bug fixes. However, it is crucial to ensure that all development environments and CI/CD pipelines are aligned with this version to maintain consistency across the project.

To verify the Go version across the project, please run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Go version in CI/CD configuration files
echo "Checking CI/CD configurations for Go version:"
grep -r "go-version" .github/workflows/*.yml .gitlab-ci.yml 2>/dev/null || echo "No CI/CD configs found with go-version specified."

# Check Go version in Dockerfiles
echo -e "\nChecking Dockerfiles for Go version:"
grep -r "FROM golang:" Dockerfile* 2>/dev/null || echo "No Dockerfiles found with golang base image."

# Reminder for local development environments
echo -e "\nReminder: Ensure all developers update their local Go version to 1.22.5"

Length of output: 1970

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 404bd96 and 85f55b7.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • e2e/runner/admin_evm.go (1 hunks)
  • e2e/utils/require.go (1 hunks)
  • go.mod (1 hunks)
  • x/fungible/keeper/v2_evm.go (2 hunks)
  • zetaclient/chains/evm/signer/v2_sign.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
e2e/runner/admin_evm.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/utils/require.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/keeper/v2_evm.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/signer/v2_sign.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (6)
x/fungible/keeper/v2_evm.go (3)

190-190: Improved precision in Amount handling

The modification to directly assign the *big.Int value to the Amount field in the RevertContext struct is a commendable improvement. This change eliminates the potential loss of precision that could occur when converting from *big.Int to uint64, ensuring accurate representation of large numbers which is crucial in blockchain contexts.


244-244: Consistent improvement in Amount handling

The modification in CallDepositAndRevert mirrors the change made in CallExecuteRevert, demonstrating a consistent approach to handling the Amount field. This change maintains precision by directly using the *big.Int type and ensures uniformity across the codebase, which is crucial for maintainability and reducing potential errors.


190-190: Summary of improvements

The modifications to CallExecuteRevert and CallDepositAndRevert functions represent a significant enhancement in handling large numbers within the EVM context. By directly using *big.Int for the Amount field in RevertContext, these changes:

  1. Eliminate potential precision loss.
  2. Ensure consistency across the codebase.
  3. Align with best practices for blockchain development.

These improvements contribute to the overall robustness of the system and support the PR's objective of addressing issues in tss migration tests.

Also applies to: 244-244

zetaclient/chains/evm/signer/v2_sign.go (1)

84-84: Approval: Enhanced precision in Amount field assignment

The modification to directly assign txData.amount to the Amount field in RevertContext is a commendable improvement. This change preserves the original type of amount, likely a *big.Int, thus maintaining full precision for large numerical values. This adjustment mitigates potential issues related to integer overflow that could have occurred with the previous uint64 conversion, especially when dealing with substantial amounts in blockchain transactions.

go.mod (2)

62-62: Verify impact of dependency updates and additions.

The update of github.com/zeta-chain/protocol-contracts and the addition of new dependencies (github.com/bnb-chain/tss-lib, github.com/showa-93/go-mask, github.com/tonkeeper/tongo) may introduce new features or security improvements. However, it is essential to assess their impact on the project.

Please run the following script to analyze the usage of these dependencies:

#!/bin/bash
echo "Analyzing usage of updated and new dependencies:"

# Check usage of updated zeta-chain/protocol-contracts
echo "Usage of updated zeta-chain/protocol-contracts:"
grep -R "github.com/zeta-chain/protocol-contracts" . --include="*.go" || echo "No direct usage found."

# Check usage of new dependencies
for dep in "github.com/bnb-chain/tss-lib" "github.com/showa-93/go-mask" "github.com/tonkeeper/tongo"; do
    echo -e "\nUsage of $dep:"
    grep -R "$dep" . --include="*.go" || echo "No usage found."
done

echo -e "\nPlease review the output and ensure these dependencies are necessary and used appropriately."

Also applies to: 283-287


Line range hint 290-306: Review and validate replace directives.

The use of replace directives, particularly for ZetaChain maintained forks, is noted. While these can be beneficial for applying custom patches or using specific versions, it's crucial to regularly review their necessity and ensure they're up-to-date.

Please run the following script to analyze the replace directives:

#!/bin/bash
echo "Analyzing replace directives:"

# Check if the replaced repositories exist and are accessible
for repo in "github.com/zeta-chain/tss-lib" "github.com/zeta-chain/go-ethereum" "github.com/zeta-chain/go-libp2p" "github.com/zeta-chain/go-tss"; do
    echo -e "\nChecking $repo:"
    git ls-remote $repo > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        echo "Repository is accessible."
        echo "Latest commit:"
        git ls-remote $repo HEAD | cut -f1
    else
        echo "Repository is not accessible or doesn't exist."
    fi
done

echo -e "\nPlease review the output and ensure all replace directives are necessary and point to the correct versions."

e2e/utils/require.go Show resolved Hide resolved
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 14, 2024
@skosito skosito added the UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light label Oct 14, 2024
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 66.02%. Comparing base (404bd96) to head (6e1d089).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
x/fungible/keeper/v2_evm.go 0.00% 2 Missing ⚠️
zetaclient/chains/evm/signer/v2_sign.go 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3002      +/-   ##
===========================================
- Coverage    66.05%   66.02%   -0.04%     
===========================================
  Files          397      397              
  Lines        22313    22337      +24     
===========================================
+ Hits         14739    14747       +8     
- Misses        6806     6816      +10     
- Partials       768      774       +6     
Files with missing lines Coverage Δ
pkg/contracts/testdappv2/TestDAppV2.go 0.00% <ø> (ø)
x/fungible/keeper/v2_evm.go 26.98% <0.00%> (ø)
zetaclient/chains/evm/signer/v2_sign.go 0.00% <0.00%> (ø)

... and 4 files with indirect coverage changes

@skosito skosito added this pull request to the merge queue Oct 14, 2024
Merged via the queue into develop with commit 09e8c3a Oct 14, 2024
32 of 33 checks passed
@skosito skosito deleted the fix-tss-migration-tests branch October 14, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check TSS_MIGRATION_TESTS Run TSS migration tests UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants