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

feat: add Whitelist message ability to whitelist SPL tokens on Solana #2984

Merged
merged 26 commits into from
Nov 4, 2024

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Oct 9, 2024

Description

Related solana program PR: zeta-chain/protocol-contracts-solana#60

This also includes latest version of gateway, and minor fixes so existing functionality works with latest gateway.

There is some duplicate code between whitelist and withdraw, as we add more spl integration soon it will be more clear which parts can be abstracted away.

NOTE: I didnt rename erc20 to something more generic, like maybe asset? in MsgWhitelistERC20 and related code, if thats needed will do in next PR, to focus on reviewing other pieces here, as that renaming should be simple but will result in bunch of files changed.

Also, this is adding protocol-contracts-solana package with autogenerated IDL for discriminators for now. There are some todos to generate types as well there, but it is out of scope of this PR.

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

Release Notes for Version 21.0.0

  • New Features

    • Support for stateful precompiled contracts and a staking precompiled contract.
    • Introduced a common importable RPC package for zetacored.
    • Enhanced support for restricted addresses in Solana and event emission from staking precompile.
    • Added support for multiple Bitcoin chains and Bitcoin inscription on testnet.
    • New functionalities for authenticated calls for smart contracts and inbound sender context reversion.
    • Ability to lock/unlock ZRC20 tokens through a fungible keeper.
  • Bug Fixes

    • Resolved issues with operator voting on discarded keygen ballots and observer set management.
  • Tests

    • Added end-to-end tests for new functionalities, including Solana whitelist support.
  • Chores

    • Updated dependencies and improved overall code structure and error handling.

@skosito skosito added the SOLANA_TESTS Run make start-solana-test label Oct 9, 2024
@skosito skosito linked an issue Oct 9, 2024 that may be closed by this pull request
cmd/zetae2e/config/local.yml Outdated Show resolved Hide resolved
@skosito
Copy link
Contributor Author

skosito commented Oct 14, 2024

@lumtis @ws4charlie could you please do initial review for this draft? i left some questions and open points, thanks

Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant updates to the ZetaChain node in version 21.0.0, including new features such as stateful precompiled contracts, an RPC package for zetacored, and enhancements for Solana and Bitcoin support. The changes also expand testing capabilities, particularly for Solana's SPL token whitelisting. Refactoring efforts focus on improving code quality and test coverage. Additionally, various modules have been updated to enhance functionality and stability, alongside modifications to dependencies and JSON structures related to transaction processing.

Changes

File Path Change Summary
changelog.md Updated to reflect changes in version 21.0.0, including new features and enhancements for stateful precompiled contracts, Solana support, and Bitcoin chain integration.
cmd/zetae2e/local/local.go Added a new test case e2etests.TestSolanaWhitelistSPLName for testing the whitelist functionality of SPL tokens in Solana.
cmd/zetae2e/local/solana.go Modified solanaTestRoutine to include a new parameter for the Zeta transaction server, enhancing Solana runner configuration.
e2e/e2etests/e2etests.go Introduced a new constant TestSolanaWhitelistSPLName for the SPL token whitelisting test and created a corresponding end-to-end test instance.
e2e/e2etests/test_solana_whitelist_spl.go Added an end-to-end test for Solana whitelist functionality, covering deployment and verification of SPL tokens.
e2e/runner/setup_solana.go Updated CreateSignedTransaction to include an additional parameter for private keys and modified account handling in transaction instructions.
e2e/runner/solana.go Enhanced CreateSignedTransaction to support multiple private keys and added a new method for deploying SPL tokens.
go.mod Added new dependencies and updated existing ones, including a new module for Solana protocol contracts.
pkg/contracts/solana/gateway.go Replaced hardcoded byte arrays with calls to GetDiscriminator for various gateway instructions and added a new function for the whitelist instruction.
pkg/contracts/solana/gateway.json Enhanced the structure of instructions and accounts, added new instructions related to whitelisting, and modified existing instruction arguments.
pkg/contracts/solana/gateway_message.go Introduced a new message structure MsgWhitelist for handling whitelist instructions in Solana.
pkg/contracts/solana/gateway_message_test.go Updated expected hash values in tests to reflect changes in the MsgWithdraw structure.
pkg/contracts/solana/instruction.go Added a new structure for handling whitelist instructions and associated parsing logic.
x/crosschain/keeper/msg_server_whitelist_erc20.go Modified WhitelistERC20 method to streamline logic and enhance error handling for ERC20 address validation.
x/crosschain/types/message_whitelist_erc20.go Updated validation logic for MsgWhitelistERC20 to check for empty asset addresses.
x/crosschain/types/message_whitelist_erc20_test.go Renamed and modified test cases for clarity in validating MsgWhitelistERC20.
zetaclient/chains/solana/observer/outbound.go Enhanced ParseGatewayInstruction to handle new coin types for whitelisting instructions.
zetaclient/chains/solana/signer/signer.go Updated TryProcessOutbound method to handle multiple coin types, improving transaction processing logic.
zetaclient/chains/solana/signer/whitelist.go Introduced functionality for signing and processing whitelist messages, including methods for constructing and serializing whitelist transactions.
zetaclient/testdata/solana/chain_901_inbound_tx_result_MS3MPLN7hkbyCZFwKqXcg8fmEvQMD74fN6Ps2LSWXJoRxPW5ehaxBorK9q1JFVbqnAvu9jXm6ertj7kT7HpYw1j.json Updated account keys and log messages in the transaction JSON structure to reflect new identifiers.
zetaclient/testutils/constant.go Updated GatewayAddresses constant map to reflect changes in development key pairs for Solana.

Possibly related PRs

  • chore: fix changelog for v21 #3052: This PR directly relates to the main PR as it also updates the changelog for version 21.0.0, including similar features and enhancements such as support for stateful precompiled contracts and restricted addresses in Solana.

Suggested labels

no-changelog

Suggested reviewers

  • lumtis
  • ws4charlie
  • swift1337
  • kingpinXD
  • fbac
  • brewmaster012
  • gartnera

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

github-actions bot commented Oct 29, 2024

!!!WARNING!!!
nosec detected in the following files: zetaclient/chains/solana/signer/whitelist.go, pkg/contracts/solana/gateway_message_test.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@skosito skosito requested a review from ws4charlie October 31, 2024 16:47
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

Not needed for this release but we should probably rename all erc20 occurence to asset

MsgWhitelistAsset

changelog.md Outdated Show resolved Hide resolved
e2e/e2etests/e2etests.go Outdated Show resolved Hide resolved
pkg/contracts/solana/gateway_message_test.go Show resolved Hide resolved
x/crosschain/keeper/msg_server_whitelist_erc20.go Outdated Show resolved Hide resolved
zetaclient/chains/solana/signer/signer.go Show resolved Hide resolved
@skosito skosito changed the title feat: whitelist spl feat: add Whitelist message ability to whitelist SPL tokens on Solana Nov 4, 2024
@skosito skosito added the ADMIN_TESTS Run make start-admin-tests label Nov 4, 2024
@skosito skosito requested a review from lumtis November 4, 2024 01:35
@skosito
Copy link
Contributor Author

skosito commented Nov 4, 2024

Not needed for this release but we should probably rename all erc20 occurence to asset

MsgWhitelistAsset

opened issue for renaming with TODO in code in proto file: #3083

pkg/chains/chain.go Outdated Show resolved Hide resolved
pkg/contracts/solana/gateway.go Outdated Show resolved Hide resolved
pkg/contracts/solana/gateway_message.go Show resolved Hide resolved
zetaclient/chains/solana/observer/outbound.go Show resolved Hide resolved
pkg/contracts/solana/gateway_message.go Show resolved Hide resolved
pkg/contracts/solana/instruction.go Show resolved Hide resolved
zetaclient/chains/solana/signer/signer.go Show resolved Hide resolved
zetaclient/chains/solana/signer/whitelist.go Outdated Show resolved Hide resolved
zetaclient/chains/solana/signer/signer.go Outdated Show resolved Hide resolved
@skosito skosito requested a review from swift1337 November 4, 2024 15:28
pkg/contracts/solana/gateway.go Show resolved Hide resolved
pkg/contracts/solana/gateway_message.go Show resolved Hide resolved
zetaclient/chains/solana/signer/signer.go Show resolved Hide resolved
zetaclient/chains/solana/signer/signer.go Show resolved Hide resolved
@skosito skosito enabled auto-merge November 4, 2024 15:44
@skosito skosito added this pull request to the merge queue Nov 4, 2024
Merged via the queue into develop with commit b317941 Nov 4, 2024
38 of 39 checks passed
@skosito skosito deleted the whitelist-spl branch November 4, 2024 16:08
Comment on lines 70 to 73
foreignCoins := k.fungibleKeeper.GetAllForeignCoins(ctx)
for _, fCoin := range foreignCoins {
assetAddr := ethcommon.HexToAddress(fCoin.Asset)
if assetAddr == erc20Addr && fCoin.ForeignChainId == msg.ChainId {
if fCoin.Asset == msg.Erc20Address && fCoin.ForeignChainId == msg.ChainId {
return nil, errorsmod.Wrapf(

Choose a reason for hiding this comment

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

You could use k.fungibleKeeper.GetForeignCoinFromAsset() instead to re-use existing logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADMIN_TESTS Run make start-admin-tests breaking:cli breaking:proto nosec SOLANA_TESTS Run make start-solana-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow MsgWhitelistERC20 to be used for Solana SPL tokens
5 participants