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

chore(evm-solidity): Move unrelated docs, gen-embeds, and add Solidity docs #2168

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Jan 16, 2025

Purpose / Abstract

  • docs(evm-embeds): Move Nibiru repo hacking docs to separate file so they won't be published on npm for @nibiruchain/solidity
  • chore(evm-embeds): just gen-embeds + more docs

Summary by CodeRabbit

  • Documentation

    • Added a new HACKING.md guide for Solidity development best practices.
    • Updated README.md to reference the new hacking guide.
  • Code Improvements

    • Modified function state mutability in the IFunToken contract to view.
    • Updated documentation comments in Solidity contracts for clarity.
    • Regenerated contract bytecode artifacts.
  • Solidity Conventions

    • Standardized NatSpec documentation approach with clearer annotations.
    • Clarified function state mutability (view vs. nonpayable).

@Unique-Divine Unique-Divine requested a review from a team as a code owner January 16, 2025 20:34
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

Warning

Rate limit exceeded

@Unique-Divine has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 17 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 503ea58 and 2498e25.

📒 Files selected for processing (6)
  • CHANGELOG.md (2 hunks)
  • x/evm/embeds/artifacts/contracts/TestERC20TransferThenPrecompileSend.sol/TestERC20TransferThenPrecompileSend.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestFunTokenPrecompileLocalGas.sol/TestFunTokenPrecompileLocalGas.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestInfiniteRecursionERC20.sol/TestInfiniteRecursionERC20.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestNativeSendThenPrecompileSend.sol/TestNativeSendThenPrecompileSend.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestPrecompileSelfCallRevert.sol/TestPrecompileSelfCallRevert.json (1 hunks)

Walkthrough

This pull request introduces a new HACKING.md file in the x/evm/embeds directory, providing comprehensive guidance for Solidity development within the project. The changes focus on documenting best practices for building outputs, precompile Solidity documentation, and Solidity conventions. Additionally, the README.md file has been updated to reference the new hacking guide, and several contract artifacts and interfaces have been modified, primarily updating bytecode and function state mutability.

Changes

File Change Summary
x/evm/embeds/HACKING.md New file added with Solidity development guidelines
x/evm/embeds/README.md Updated to link to new hacking guide
x/evm/embeds/abi/IFunToken.json
x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json
State mutability changed for balance, bankBalance, and whoAmI functions from nonpayable to view
x/evm/embeds/contracts/IFunToken.sol Updated documentation comments and function signatures
Various contract artifacts Updated bytecode representations

Possibly related PRs

Poem

🐰 Solidity's dance, a rabbit's delight,
Docs now shine clear and oh-so-bright!
From view to pure, we code with grace,
NatSpec comments find their place
In Nibiru's EVM, wisdom takes flight! 🚀


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.

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

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.

@Unique-Divine Unique-Divine changed the title chore(evm-solidity) chore(evm-solidity): Move unrelated docs, gen-embeds, and add Solidity docs Jan 16, 2025
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 (3)
x/evm/embeds/HACKING.md (3)

9-20: Enhance build instructions with prerequisites and details.

Consider adding:

  1. Prerequisites for the just command installation
  2. Description of what gen-embeds does
  3. Clear order of operations (what to run first)
 ## Building Outputs 
 
-Workhorse command
+### Prerequisites
+
+1. Install `just` command runner:
+   ```bash
+   # macOS
+   brew install just
+   
+   # Linux
+   curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash
+   ```
+
+### Steps
+
+1. First, install dependencies and compile contracts:
+   ```bash
+   cd x/evm/embeds
+   npm install
+   npx hardhat compile
+   ```
+
+2. Generate embeds (updates Go files with compiled contract artifacts):
 ```bash
 just gen-embeds

-From inside the "Nibiru/x/evm/embeds" directory
-bash -npm install -npx hardhat compile -


---

`22-75`: **Consider adding guidelines for error documentation and validation tools.**

The documentation guidelines are comprehensive. Consider enhancing them with:
1. Guidelines for documenting error conditions using `@custom:error` or `@revert`
2. Mention of tools like `solhint` or `hardhat-docgen` for validating NatSpec comments


```diff
 ### NatSpec Fields
 
 - `@notice`: Used to explain to end users what the function does. Should be written in plain English and focus on the function's purpose.  
   Best practice: Include for all public and external functions.
 - `@param`: Describes a function parameter. Should explain what the parameter is used for.  
   Best practice: Include for all function parameters, especially in interfaces.
 - `@dev`: Provides additional details for developers. Used for implementation details, notes, or warnings for developers.  
   Best practice: Use when there's important information that doesn't fit in `@notice` but is crucial for developers.
 - `@return`: Describes what a function returns.  
   Best practice: Use for all functions that return values, explaining each return value.
+- `@custom:error`: Documents custom error conditions.
+  Best practice: Use for all custom errors to explain when they occur.
+- `@revert`: Documents conditions that cause the function to revert.
+  Best practice: Document all revert conditions for better error handling.
+
+### Validation Tools
+
+Use these tools to ensure documentation quality:
+- `solhint` with NatSpec validation rules
+- `hardhat-docgen` for generating documentation
+- VS Code Solidity extension for real-time validation
🧰 Tools
🪛 LanguageTool

[uncategorized] ~34-~34: Loose punctuation mark.
Context: ...mments. ### NatSpec Fields - @notice: Used to explain to end users what the f...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~34-~34: To form a complete sentence, be sure to include a subject.
Context: ...in to end users what the function does. Should be written in plain English and focus o...

(MISSING_IT_THERE)


[uncategorized] ~36-~36: Loose punctuation mark.
Context: ...ublic and external functions. - @param: Describes a function parameter. Should ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~38-~38: Loose punctuation mark.
Context: ...ters, especially in interfaces. - @dev: Provides additional details for develop...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~40-~40: Loose punctuation mark.
Context: ...t is crucial for developers. - @return: Describes what a function returns. ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~41-~41: Possible missing comma found.
Context: ... a function returns. Best practice: Use for all functions that return values, e...

(AI_HYDRA_LEO_MISSING_COMMA)


76-112: Add gas optimization context to state mutability guidelines.

The state mutability section is clear and well-exemplified. Consider adding:

  1. Gas optimization benefits of using view/pure functions
  2. Common pitfalls when choosing between different state mutability types
 ### State Mutability
 
 State mutability defines how a function interacts with the blockchain state. Always explicitly declare non-default state mutability keywords for clarity and correctness.
+
+#### Gas Optimization Considerations
+
+- `view` and `pure` functions are free when called externally (no gas cost)
+- Marking functions as `view` or `pure` when possible helps users save gas
+- Be cautious of state reads in loops even in `view` functions
 
 1. `view` : For stateful queries
    - Reads state, but cannot modify it.  
🧰 Tools
🪛 LanguageTool

[uncategorized] ~82-~82: Loose punctuation mark.
Context: ...for clarity and correctness. 1. view : For stateful queries - Reads state, ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~90-~90: Loose punctuation mark.
Context: ...ew returns (uint256); ``` 2. pure : For stateless queries - Neither read...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~106-~106: Loose punctuation mark.
Context: ... amount) external; ``` 4. payable : State mutating operation that can recei...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8731a9e and 5be2439.

📒 Files selected for processing (12)
  • x/evm/embeds/HACKING.md (1 hunks)
  • x/evm/embeds/README.md (1 hunks)
  • x/evm/embeds/abi/IFunToken.json (3 hunks)
  • x/evm/embeds/artifacts/contracts/ERC20Minter.sol/ERC20Minter.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json (3 hunks)
  • x/evm/embeds/artifacts/contracts/TestERC20TransferThenPrecompileSend.sol/TestERC20TransferThenPrecompileSend.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestFunTokenPrecompileLocalGas.sol/TestFunTokenPrecompileLocalGas.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestInfiniteRecursionERC20.sol/TestInfiniteRecursionERC20.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestNativeSendThenPrecompileSend.sol/TestNativeSendThenPrecompileSend.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestPrecompileSelfCallRevert.sol/TestPrecompileSelfCallRevert.json (1 hunks)
  • x/evm/embeds/contracts/ERC20Minter.sol (1 hunks)
  • x/evm/embeds/contracts/IFunToken.sol (2 hunks)
✅ Files skipped from review due to trivial changes (7)
  • x/evm/embeds/contracts/ERC20Minter.sol
  • x/evm/embeds/artifacts/contracts/TestERC20TransferThenPrecompileSend.sol/TestERC20TransferThenPrecompileSend.json
  • x/evm/embeds/artifacts/contracts/TestNativeSendThenPrecompileSend.sol/TestNativeSendThenPrecompileSend.json
  • x/evm/embeds/artifacts/contracts/TestPrecompileSelfCallRevert.sol/TestPrecompileSelfCallRevert.json
  • x/evm/embeds/README.md
  • x/evm/embeds/artifacts/contracts/TestFunTokenPrecompileLocalGas.sol/TestFunTokenPrecompileLocalGas.json
  • x/evm/embeds/artifacts/contracts/ERC20Minter.sol/ERC20Minter.json
🧰 Additional context used
🪛 LanguageTool
x/evm/embeds/HACKING.md

[uncategorized] ~34-~34: Loose punctuation mark.
Context: ...mments. ### NatSpec Fields - @notice: Used to explain to end users what the f...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~34-~34: To form a complete sentence, be sure to include a subject.
Context: ...in to end users what the function does. Should be written in plain English and focus o...

(MISSING_IT_THERE)


[uncategorized] ~36-~36: Loose punctuation mark.
Context: ...ublic and external functions. - @param: Describes a function parameter. Should ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~38-~38: Loose punctuation mark.
Context: ...ters, especially in interfaces. - @dev: Provides additional details for develop...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~40-~40: Loose punctuation mark.
Context: ...t is crucial for developers. - @return: Describes what a function returns. ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~41-~41: Possible missing comma found.
Context: ... a function returns. Best practice: Use for all functions that return values, e...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~82-~82: Loose punctuation mark.
Context: ...for clarity and correctness. 1. view : For stateful queries - Reads state, ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~90-~90: Loose punctuation mark.
Context: ...ew returns (uint256); ``` 2. pure : For stateless queries - Neither read...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~106-~106: Loose punctuation mark.
Context: ... amount) external; ``` 4. payable : State mutating operation that can recei...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e-evm
🔇 Additional comments (13)
x/evm/embeds/contracts/IFunToken.sol (7)

9-12: LGTM! Clear and concise interface documentation.

The interface documentation clearly describes its purpose and functionality.


Line range hint 13-23: LGTM! Well-documented function with clear parameter descriptions.

The sendToBank function documentation is comprehensive, including parameter descriptions and return value explanation.


35-47: LGTM! Function signature updated with view modifier.

The balance function is correctly marked as view since it only reads state. The return types are well-defined.


50-58: LGTM! Function signature updated with view modifier.

The bankBalance function is correctly marked as view since it only reads state. The return types are well-defined.


60-67: LGTM! Function signature updated with view modifier.

The whoAmI function is correctly marked as view since it only reads state. The documentation and parameter descriptions are clear.


69-84: LGTM! Comprehensive function documentation.

The sendToEvm function documentation is thorough, including detailed parameter descriptions and explaining the underlying logic.


Line range hint 87-98: LGTM! Clear function documentation.

The bankMsgSend function documentation clearly describes its purpose and parameters.

x/evm/embeds/abi/IFunToken.json (3)

81-81: LGTM! Correct stateMutability update.

The balance function's stateMutability is correctly updated to "view" to match the interface.


122-122: LGTM! Correct stateMutability update.

The bankBalance function's stateMutability is correctly updated to "view" to match the interface.


240-240: LGTM! Correct stateMutability update.

The whoAmI function's stateMutability is correctly updated to "view" to match the interface.

x/evm/embeds/artifacts/contracts/TestInfiniteRecursionERC20.sol/TestInfiniteRecursionERC20.json (1)

312-313: LGTM! Updated contract bytecode.

The bytecode has been updated but maintains the same functionality as indicated by the unchanged ABI.

x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json (1)

85-85: Appropriate state mutability updates for read-only functions.

The changes from "nonpayable" to "view" for balance, bankBalance, and whoAmI functions are correct since these functions only read state without modifying it. This change:

  • More accurately reflects the functions' behavior
  • Enables gas optimizations
  • Allows these functions to be called from other view functions

Let's verify that these functions don't modify state by checking their implementations:

Also applies to: 126-126, 244-244

✅ Verification successful

Verified: State mutability changes are correct

The interface implementation confirms that balance, bankBalance, and whoAmI functions are properly marked as view since they only return data without modifying state:

  • balance: Returns balances and token metadata
  • bankBalance: Returns bank balance and account info
  • whoAmI: Returns address resolution data
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that these functions don't modify state
# Expected: Function bodies should only contain read operations

ast-grep --pattern 'function $_($$) {
  $$$
  $write
  $$$
}' -l solidity

Length of output: 192


Script:

#!/bin/bash
# Find and display the Solidity interface file
fd -e sol "IFunToken" --exec cat {}

Length of output: 3925

x/evm/embeds/HACKING.md (1)

1-8: Well-structured documentation with clear navigation!

The table of contents is well-organized and provides easy navigation to all major sections.

@Unique-Divine Unique-Divine merged commit 04bd7c2 into main Jan 16, 2025
8 checks passed
@Unique-Divine Unique-Divine deleted the solidity-hygiene branch January 16, 2025 20:56
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.

1 participant