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: remove minimum rent exempt check for SPL token withdrawals #3374

Merged
merged 6 commits into from
Jan 20, 2025

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Jan 17, 2025

Description

The minimum rent exempt 1_000_000 lamports was intended to avoid SOL token withdraw failure on gateway program when a Solana receiver account doesn't have enough lamports.

This rent exempt restriction should not be applied on SPL token because withdrawing SPL token already needs a non trivial amount of SOL for potential ATA creation so we can skip the minimal withdraw amount checking. Its already anti spam.

Changes:

  1. Skip rent exempt check in method validateZRC20Withdrawal for non-Gas token.
  2. Reduce default SPL withdraw amount 1_000_000 -> 100_000 in SPL withdraw E2E test.

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

  • Fixes

    • Removed minimum rent exempt check for SPL token withdrawals
    • Updated validation logic for ZRC20 withdrawal events to support different coin types
  • Testing

    • Enhanced test coverage for withdrawal events across different coin types
    • Updated test cases for BTC and SOL withdrawals
  • Improvements

    • Added coin type parameter to withdrawal validation methods
    • Refined validation process for cross-chain transactions

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

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

This pull request introduces modifications to the SPL token withdrawal validation process across multiple files. The changes primarily focus on enhancing the validation logic for cross-chain transactions by incorporating a new coin type parameter. The modifications affect the withdrawal validation mechanism, specifically removing the minimum rent exempt check for SPL token withdrawals and updating the validation methods to support more granular coin-type specific checks.

Changes

File Change Summary
changelog.md Added "Fixes" section under "unreleased", removing minimum rent exempt check for SPL token withdrawals
e2e/e2etests/e2etests.go Modified default SPL token withdrawal amount from 1,000,000 to 100,000
x/crosschain/keeper/cctx_orchestrator_validate_outbound.go Added CoinType parameter to processFailedOutboundOnExternalChain method
x/crosschain/keeper/evm_hooks.go Updated ValidateZRC20WithdrawEvent and validateZRC20Withdrawal methods to include coin type validation
x/crosschain/keeper/evm_hooks_test.go Added new test cases for SOL withdrawal events and updated existing tests with coin type validation
x/crosschain/keeper/v2_zevm_inbound.go Modified ProcessZEVMInboundV2 method to pass coin type to validation function

Sequence Diagram

sequenceDiagram
    participant Validator
    participant WithdrawalMethod
    participant CoinTypeChecker

    Validator->>WithdrawalMethod: Initiate Withdrawal
    WithdrawalMethod->>CoinTypeChecker: Validate Coin Type
    CoinTypeChecker-->>WithdrawalMethod: Validation Result
    WithdrawalMethod-->>Validator: Withdrawal Status
Loading

Possibly related PRs

Suggested Labels

breaking:cli, no-changelog

Suggested Reviewers

  • fbac
  • skosito
  • kingpinXD
  • lumtis
  • 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@ws4charlie ws4charlie added chain:solana SOLANA_TESTS Run make start-solana-test zetacore Issues related to ZetaCore bug Something isn't working labels Jan 17, 2025
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 63.22%. Comparing base (4bdfc0b) to head (a409a1a).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
x/crosschain/keeper/v2_zevm_inbound.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3374   +/-   ##
========================================
  Coverage    63.22%   63.22%           
========================================
  Files          436      436           
  Lines        30636    30639    +3     
========================================
+ Hits         19369    19372    +3     
  Misses       10432    10432           
  Partials       835      835           
Files with missing lines Coverage Δ
...hain/keeper/cctx_orchestrator_validate_outbound.go 70.95% <100.00%> (+0.12%) ⬆️
x/crosschain/keeper/evm_hooks.go 83.07% <100.00%> (+0.13%) ⬆️
x/crosschain/keeper/v2_zevm_inbound.go 3.88% <0.00%> (ø)

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.

Can we change the withdraw SLP test to use a lower value by default (so the if would be triggered for the check)

@ws4charlie
Copy link
Contributor Author

ws4charlie commented Jan 17, 2025

Can we change the withdraw SLP test to use a lower value by default (so the if would be triggered for the check)

Yeah. I'm modifying that and running the E2E test in local. It's now reduced in 594449e

@ws4charlie ws4charlie requested a review from lumtis January 17, 2025 18:08
@ws4charlie ws4charlie marked this pull request as ready for review January 17, 2025 18:08
@ws4charlie ws4charlie requested a review from a team as a code owner January 17, 2025 18:08
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: 0

🧹 Nitpick comments (1)
x/crosschain/keeper/evm_hooks_test.go (1)

175-187: Test case needs additional edge cases for SOL withdrawals.

While the test covers the basic rent exempt case, consider adding tests for:

  1. Values slightly below and above the rent exempt amount
  2. Maximum value limits
  3. Zero value transfers
 t.Run("successfully validate a valid SOL withdrawal event", func(t *testing.T) {
     k, ctx, _, _ := keepertest.CrosschainKeeper(t)

     // Test cases
+    testCases := []struct {
+        name      string
+        value     *big.Int
+        coinType  coin.CoinType
+        expectErr bool
+    }{
+        {"exactly rent exempt", big.NewInt(constant.SolanaWalletRentExempt), coin.CoinType_Gas, false},
+        {"slightly below rent exempt", big.NewInt(constant.SolanaWalletRentExempt - 1), coin.CoinType_Gas, true},
+        {"slightly above rent exempt", big.NewInt(constant.SolanaWalletRentExempt + 1), coin.CoinType_Gas, false},
+        {"zero value", big.NewInt(0), coin.CoinType_Gas, true},
+        {"max uint64", new(big.Int).SetUint64(math.MaxUint64), coin.CoinType_Gas, false},
+    }
+
+    for _, tc := range testCases {
+        t.Run(tc.name, func(t *testing.T) {
+            chainID := chains.SolanaMainnet.ChainId
+            to := []byte(sample.SolanaAddress(t))
+            solWithdrawalEvent := sample.ZRC20Withdrawal(to, tc.value)
+
+            err := k.ValidateZRC20WithdrawEvent(ctx, solWithdrawalEvent, chainID, tc.coinType)
+            if tc.expectErr {
+                require.Error(t, err)
+            } else {
+                require.NoError(t, err)
+            }
+        })
+    }
 })
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bdfc0b and 7c59d66.

📒 Files selected for processing (6)
  • changelog.md (1 hunks)
  • e2e/e2etests/e2etests.go (1 hunks)
  • x/crosschain/keeper/cctx_orchestrator_validate_outbound.go (1 hunks)
  • x/crosschain/keeper/evm_hooks.go (3 hunks)
  • x/crosschain/keeper/evm_hooks_test.go (6 hunks)
  • x/crosschain/keeper/v2_zevm_inbound.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
x/crosschain/keeper/v2_zevm_inbound.go (1)

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

x/crosschain/keeper/evm_hooks.go (1)

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

x/crosschain/keeper/cctx_orchestrator_validate_outbound.go (1)

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

x/crosschain/keeper/evm_hooks_test.go (1)

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

e2e/e2etests/e2etests.go (1)

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

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: start-solana-test / e2e
  • GitHub Check: start-e2e-test / e2e
🔇 Additional comments (7)
x/crosschain/keeper/v2_zevm_inbound.go (1)

78-78: LGTM! Correctly passes coin type for withdrawal validation.

The change properly integrates the new coin type parameter into the withdrawal validation flow.

x/crosschain/keeper/evm_hooks.go (2)

308-315: LGTM! Function signature updated correctly.

The ValidateZRC20WithdrawEvent function properly integrates the new coinType parameter.


Line range hint 320-358: Verify the security implications of removing rent exempt check for non-gas tokens.

The validation logic now only enforces the rent exempt check for SOL gas token withdrawals. While this aligns with the PR objective, we should verify:

  1. That SPL token withdrawals inherently require sufficient SOL for ATA creation
  2. That removing this check doesn't introduce security vulnerabilities

Run this script to check for any existing security measures or validations for SPL token withdrawals:

✅ Verification successful

Removal of rent exempt check for SPL tokens is architecturally sound

The validation now correctly enforces rent exempt check only for SOL withdrawals, which is the proper architectural approach since:

  • SOL minimum is critical for wallet creation
  • ATA requirements for SPL tokens are enforced at the Solana runtime level
  • SPL token amounts don't affect rent calculations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for SPL token withdrawal validations and ATA creation requirements
rg -A 5 "Associated Token Account|ATA creation|rent exempt|minimum balance" 

Length of output: 3849

x/crosschain/keeper/cctx_orchestrator_validate_outbound.go (1)

201-201: LGTM! Consistent with the updated validation flow.

The change correctly integrates the coin type parameter from the inbound parameters.

x/crosschain/keeper/evm_hooks_test.go (1)

189-199: LGTM! SPL token withdrawal test case is comprehensive.

The test correctly verifies that small amounts can be withdrawn for SPL tokens, which is the key change in this PR.

e2e/e2etests/e2etests.go (1)

456-456: LGTM! Test amount adjustment aligns with PR objectives.

The reduction in default test amount from 1,000,000 to 100,000 SPL tokens appropriately tests the removal of minimum rent exempt requirement.

changelog.md (1)

11-14: LGTM! Clear and well-structured changelog entry.

The entry properly documents the fix under the correct section and includes the PR reference.

@ws4charlie ws4charlie requested a review from lumtis January 17, 2025 21:16
@lumtis lumtis added this pull request to the merge queue Jan 20, 2025
Merged via the queue into develop with commit 80f13ec Jan 20, 2025
40 checks passed
@lumtis lumtis deleted the fix-SPL-withdraw-skip-rent-exempt-check branch January 20, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chain:solana SOLANA_TESTS Run make start-solana-test zetacore Issues related to ZetaCore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants