Skip to content

fix: solana call required accounts number condition#3895

Merged
skosito merged 4 commits intodevelopfrom
fix-solana-call-accounts-number
May 27, 2025
Merged

fix: solana call required accounts number condition#3895
skosito merged 4 commits intodevelopfrom
fix-solana-call-accounts-number

Conversation

@skosito
Copy link
Member

@skosito skosito commented May 21, 2025

Description

https://github.com/zeta-chain/protocol-private/issues/263

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

  • Bug Fixes

    • Improved validation for Solana gateway calls to require at least one signer account, enhancing compatibility with various transaction scenarios.
  • Documentation

    • Updated the changelog to reflect the fix related to Solana account requirements.
  • Tests

    • Adjusted test cases to align with the new account validation logic for Solana instructions.

@skosito skosito added the SOLANA_TESTS Run make start-solana-test label May 21, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 21, 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 change updates the Solana gateway logic and tests to refine the handling and validation of account counts for call instructions. It introduces a new constant for required accounts, adjusts the validation logic to require at least one signer account, and updates related tests and documentation for clarity and consistency.

Changes

File(s) Change Summary
changelog.md Added a new fix entry for PR #3895, describing the update to the required number of accounts for Solana calls.
pkg/contracts/solana/gateway.go Renamed internal constants for account counts, improved comments, and introduced accountsNumberCall for call instruction.
pkg/contracts/solana/inbound.go Updated validation logic in ParseInboundAsCall to require at least one signer account, using the new constant.
pkg/contracts/solana/inbound_test.go Adjusted test cases to simulate wrong account counts by truncating the instruction's accounts, and removed unused imports.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Gateway
    participant Validator

    Client->>Gateway: Submit Solana call instruction
    Gateway->>Gateway: Validate signer accounts (require at least 1)
    alt If valid
        Gateway->>Validator: Process instruction
        Validator-->>Gateway: Return result
        Gateway-->>Client: Return success
    else If invalid
        Gateway-->>Client: Return error (wrong signer accounts count)
    end
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@skosito skosito marked this pull request as ready for review May 23, 2025 13:04
@skosito skosito requested a review from a team as a code owner May 23, 2025 13:04
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

🧹 Nitpick comments (1)
pkg/contracts/solana/gateway.go (1)

14-25: Improve naming consistency across constants.

The constants use inconsistent naming patterns. Consider standardizing to either all exported or all unexported with a consistent naming scheme.

Apply consistent naming pattern:

-// accountsNumDeposit is the number of accounts required for Solana gateway deposit instruction
-// [signer, pda, system_program]
-accountsNumDeposit = 3
-
-// accountsNumberDepositSPL is the number of accounts required for Solana gateway deposit spl instruction
-// [signer, pda, whitelist_entry, mint_account, token_program, from, to, system_program]
-accountsNumberDepositSPL = 8
-
-// accountsNumberCall is the number of accounts required for Solana gateway call instruction
-// [signer]
-accountsNumberCall = 1
+// accountsNumDeposit is the number of accounts required for Solana gateway deposit instruction
+// [signer, pda, system_program]
+accountsNumDeposit = 3
+
+// accountsNumDepositSPL is the number of accounts required for Solana gateway deposit spl instruction
+// [signer, pda, whitelist_entry, mint_account, token_program, from, to, system_program]
+accountsNumDepositSPL = 8
+
+// accountsNumCall is the number of accounts required for Solana gateway call instruction
+// [signer]
+accountsNumCall = 1
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b06813 and 1d51e54.

📒 Files selected for processing (4)
  • changelog.md (1 hunks)
  • pkg/contracts/solana/gateway.go (1 hunks)
  • pkg/contracts/solana/inbound.go (1 hunks)
  • pkg/contracts/solana/inbound_test.go (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

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

  • pkg/contracts/solana/gateway.go
  • pkg/contracts/solana/inbound.go
  • pkg/contracts/solana/inbound_test.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: start-solana-test / e2e
  • GitHub Check: start-e2e-test / e2e
🔇 Additional comments (4)
pkg/contracts/solana/gateway.go (1)

22-25: Well-documented constant addition.

The new accountsNumberCall constant is properly documented and aligns with the PR objective of standardizing account validation for call instructions.

changelog.md (1)

52-52: Clear and concise changelog entry.

The changelog entry accurately documents the fix and follows the established format with proper PR reference.

pkg/contracts/solana/inbound.go (1)

248-250:

Details

✅ Verification successful

Validation logic updated appropriately.

The change from exact count validation to minimum count validation aligns with the PR objective. The updated error message clearly indicates the requirement for at least one signer account, which is appropriate for call instructions.

Verify that relaxing the validation from exact count to minimum count doesn't introduce security vulnerabilities:


🏁 Script executed:

#!/bin/bash
# Search for other usages of ParseInboundAsCall to ensure this change is safe
rg -A 10 -B 5 "ParseInboundAsCall"

Length of output: 6489


✅ Validation logic update approved—ensure no unintended relaxation

The change from an exact-to-a-minimum account count (if len(instructionAccounts) < accountsNumberCall) correctly enforces “at least one signer” and preserves existing tests (which still error when there are zero signers). I reviewed all call‐parsing sites—only the Solana observer invokes ParseInboundAsCall—and there are no other call‐count invariants in the codebase.

No further fixes required, but please confirm in your integration tests that no instruction ever provides extra signer accounts that could subvert downstream logic.

pkg/contracts/solana/inbound_test.go (1)

113-114: Test simplification improves clarity.

The consistent pattern of simplifying test setup across all "wrong accounts count" test cases improves readability and maintainability. Removing the complexity of adding extra account keys while maintaining error condition validation is a good refactoring approach.

Also applies to: 200-201, 285-286, 373-374, 458-459

@swift1337 swift1337 self-requested a review May 27, 2025 11:35
@skosito skosito enabled auto-merge May 27, 2025 20:05
@skosito skosito added this pull request to the merge queue May 27, 2025
Merged via the queue into develop with commit a2ffdb6 May 27, 2025
47 checks passed
@skosito skosito deleted the fix-solana-call-accounts-number branch May 27, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SOLANA_TESTS Run make start-solana-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants