Skip to content

Conversation

@z3roai
Copy link
Contributor

@z3roai z3roai commented Jul 21, 2025

This PR adds a .cursorrules config for Rust-based Solana smart contract development using the Anchor framework.

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive "Rust + Solana (Anchor) Best Practices" guide covering program structure, Anchor usage, manual Solana SDK patterns, serialization, testing, security, performance, developer workflow, documentation standards, wallet/network handling, and CI/CD/deployment recommendations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

A new documentation file, rules-new/rust.mdc, was added containing a comprehensive best-practices guide for developing Solana programs in Rust, covering Anchor and raw Solana SDK patterns across structure, serialization, testing, security, performance, workflow, documentation, wallet/network handling, and CI/CD.

Changes

Cohort / File(s) Change Summary
New documentation
rules-new/rust.mdc
Added a governance-style best-practices document for Rust Solana development (Anchor and solana_program), detailing program structure, Anchor usage, serialization, testing, SDK guidelines, security patterns, performance, dev workflow, docs, wallet/network handling, and CI/CD recommendations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • PatrickJS

Poem

In the warren of code a new guide is found,
Rust rules for Solana, safe and sound.
Anchor the handlers, keep tests in sight,
Docs and CI to guide the flight.
This rabbit hops off—your code looks bright! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dfd43b7 and 7028157.

📒 Files selected for processing (1)
  • rules-new/rust.mdc (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • rules-new/rust.mdc
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 0

🧹 Nitpick comments (5)
rules-new/rust.mdc (5)

17-19: Fix typo in constraint-macro example

bump] is missing its opening bracket and is not wrapped inside the #[account(...)] attribute, which may confuse readers unfamiliar with Anchor syntax.

- - Validate accounts strictly using constraint macros (e.g., `#[account(mut)]`, `seeds`, `bump]`)
+ - Validate accounts strictly using constraint macros, e.g.  
+   ```rust
+   #[account(
+       mut,
+       seeds = [b"seed", authority.key().as_ref()],
+       bump
+   )]
+   ```

24-28: Clarify packed-layout advice

You recommend both #[repr(C)] here and #[repr(packed)] later (line 57). These have different guarantees; mixing them may mislead newcomers.

Consider collapsing into a single bullet such as:

- Always include `#[account(zero_copy)]` or `#[repr(C)]` for packed structures
+ For zero-copy accounts, combine  
+ `#[account(zero_copy)]` with `#[repr(packed)]` (or `#[repr(C)]` when explicit padding is acceptable) to guarantee a deterministic on-chain layout.

30-36: Update log-message access path

Anchor’s confirmed transaction object exposes logs under tx.meta.logMessages, not tx.confirmation.logMessages.

- Validate program logs using `tx.confirmation.logMessages`
+ Validate program logs using `tx.meta.logMessages`

45-47: Remove Ethereum terminology

msg.sender is an Ethereum concept and may confuse Solana readers.

- Always validate `msg.sender`/signer with `account_info.is_signer`
+ Always validate the signer with `account_info.is_signer`

74-77: Align provider variable name with Anchor examples

Most Anchor TS examples use provider.wallet.publicKey; anchorProvider isn’t standard and could cause friction when readers copy/paste.

- Use `anchorProvider.wallet.publicKey` for signer verification in tests
+ Use `provider.wallet.publicKey` for signer verification in tests
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42ac7cf and dfd43b7.

📒 Files selected for processing (1)
  • rules-new/rust.mdc (1 hunks)

@z3roai
Copy link
Contributor Author

z3roai commented Aug 12, 2025

I pushed a fix in commit 8cabeb1, please review it.

@z3roai z3roai closed this Aug 12, 2025
@z3roai z3roai reopened this Aug 12, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll examine the file you've added to provide a proper review of your Rust Solana development guidelines.


🏁 Script executed:

#!/bin/bash
# Read the content of the new rust.mdc file to review it
cat rules-new/rust.mdc

Length of output: 4267


@z3roai Thank you for adding this comprehensive Rust + Solana development guidelines document! I've reviewed the rules-new/rust.mdc file and it's an excellent addition to the repository.

✅ Strengths

Comprehensive Coverage: The document covers all essential aspects of Solana development from program structure to CI/CD, making it a valuable resource for developers.

Technical Accuracy: The recommendations align with current best practices:

  • Proper Anchor framework usage with #[derive(Accounts)] and constraint macros
  • Correct serialization guidance (Borsh over Serde)
  • Security-focused patterns including signer validation and replay attack prevention
  • Performance optimization with zero-copy deserialization

Well-Organized Structure: The use of emoji icons and clear sections makes the guidelines easily scannable and developer-friendly.

Practical Examples: Each section provides actionable advice rather than abstract concepts, which is perfect for cursor rules.

📝 Minor Suggestions

The content is solid overall. Just a couple of small observations:

  1. Line consistency: Most sections use consistent formatting, but the constraint macro example could be more uniform: #[account(mut)], seeds, bump#[account(mut, seeds = [...], bump)]

  2. Typo in performance section: "Profile compute units with solana logs and anchor run" - should be anchor test for the typical workflow.

The document successfully fills a gap in the repository by providing specialized guidance for the growing Solana ecosystem. The technical depth and practical focus make it a valuable resource for developers working with Rust and Anchor.

Recommendation: ✅ Approve - This is a high-quality addition that enhances the repository's coverage of blockchain development environments.

@z3roai
Copy link
Contributor Author

z3roai commented Aug 12, 2025

I pushed a fix in commit 7028157, please review it.

@PatrickJS PatrickJS merged commit c4663a5 into PatrickJS:main Aug 12, 2025
1 check passed
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.

2 participants