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(evm-precompile): Emit EVM events created to reflect the ABCI events that occur outside the EVM to make sure that block explorers and indexers can find indexed ABCI event information. #2125

Merged
merged 12 commits into from
Dec 30, 2024

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Dec 14, 2024

Purpose / Abstract

feat(evm-precompile): Emit EVM events created to reflect the ABCI events that occur outside the EVM to make sure that block explorers and indexers can find indexed ABCI event information.

Summary by CodeRabbit

Based on the comprehensive summary of changes, here are the release notes:

  • New Features

    • Added support for emitting EVM events that reflect ABCI events
    • Enhanced event logging capabilities for block explorers and indexers
  • Improvements

    • Updated Node.js version to latest LTS (Jod)
    • Improved bash logging with color and formatting support
    • Refined protobuf and Solidity artifact generation
    • Enhanced error handling in precompile contracts
  • Bug Fixes

    • Ensured gas consumption depends only on base keeper
    • Corrected address encoding for EIP155 compatibility
  • Testing

    • Added more bank extension and EVM ABCI integration tests
    • Expanded test coverage for precompile contract functionality
  • Documentation

    • Improved inline documentation for various components
    • Completed third-party audit preparations

@Unique-Divine Unique-Divine requested a review from a team as a code owner December 14, 2024 01:43
Copy link
Contributor

coderabbitai bot commented Dec 14, 2024

Walkthrough

This pull request introduces significant enhancements to the Nibiru EVM ecosystem, focusing on improving event emission, precompile functionality, and development environment configuration. The changes span multiple files across the project, introducing new interfaces, updating contract artifacts, modifying precompile implementations, and adding utility functions for handling ABCI events within the Ethereum Virtual Machine (EVM) context.

Changes

File Change Summary
.nvmrc Updated Node.js version to lts/jod
CHANGELOG.md Added entries for EVM event emission, gas consumption improvements, and address encoding
contrib/bashlib.sh Enhanced logging functions with ANSI color support
justfile Renamed and added recipes for build and generation processes
x/evm/embeds/contracts/ Updated contract interfaces and artifacts with new events and type references
x/evm/precompile/ Added new utility functions for ABCI event handling and emission

Assessment against linked issues

Objective Addressed Explanation
Emit ABCI events as EVM events [#2121]

Possibly related PRs

Sequence Diagram

sequenceDiagram
    participant Precompile
    participant EVM
    participant ABCI
    participant StateDB

    Precompile->>ABCI: Execute transaction
    ABCI-->>Precompile: Generate events
    Precompile->>EVM: Convert ABCI events
    EVM->>StateDB: Add event logs
    StateDB-->>EVM: Confirm log addition
Loading

Poem

🐰 Hop, hop, through the EVM's maze,
Where ABCI events now blaze!
Logs dancing with colorful might,
Precompiles shining ever so bright! 🌟
A rabbit's code, both swift and keen,
Makes blockchain magic yet unseen! 🔮

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 feat(evm-precompile):Emit EVM events created to reflect the ABCI events that occur outside the EVM to make sure that block explorers and indexers can find indexed ABCI event information. feat(evm-precompile): Emit EVM events created to reflect the ABCI events that occur outside the EVM to make sure that block explorers and indexers can find indexed ABCI event information. Dec 14, 2024
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: 4

🧹 Outside diff range and nitpick comments (6)
x/evm/keeper/keeper_test.go (2)

22-23: Use specific log level Info for clarity

In the SetupTest method, it's better to specify the log level explicitly for clarity and consistency. Using log.Info().Msgf instead of log.Log().Msgf makes it clear that the message is informational.

Apply the following diff to update the log level:

 func (s *Suite) SetupTest() {
-	log.Log().Msgf("SetupTest %v", s.T().Name())
+	log.Info().Msgf("SetupTest %v", s.T().Name())
 }

21-23: Avoid cluttering test output with logs

While logging can be helpful during development, consider whether logging the setup of each test is necessary. Excessive logging can clutter test output, making it harder to identify failures. If the logs are for debugging purposes, you might want to control them with a verbosity flag or remove them before finalizing the tests.

x/evm/embeds/contracts/NibiruEvmUtils.sol (1)

12-23: Consider enhancing type safety for event attributes

The event design with bytes attrs provides flexibility but might make it harder for consumers to parse the data correctly. Consider:

  1. Adding helper functions for encoding/decoding common attribute types
  2. Documenting the expected attribute format for each eventType

Would you like me to propose a set of helper functions for common attribute types?

contrib/bashlib.sh (1)

32-51: LGTM: Consistent logging improvements

The addition of -e flag to enable ANSI color codes is applied consistently across all logging functions. Consider adding a test to verify color output functionality.

Add this test function to verify color output:

test_color_output() {
  # Capture output with color codes
  local output=$(log_debug "test message")
  # Verify color codes are present
  [[ "$output" == *$'\033'* ]] || { echo "Color codes not working"; exit 1; }
}
x/evm/precompile/nibiru_evm_utils_test.go (1)

60-118: Consider adding more test cases for EmitEventAbciEvent

While the current test verifies basic event emission functionality, consider adding test cases for:

  • Events with empty attributes
  • Events with malformed data
  • Maximum event size limits
  • Error conditions

Here's a suggested test case structure:

 func (s *UtilsSuite) TestEmitEventAbciEvent() {
+    testCases := []struct {
+        name        string
+        setupEvents func(ctx sdk.Context) []abci.Event
+        wantLogs    []*gethcore.Log
+        wantErr     bool
+    }{
+        {
+            name: "empty event attributes",
+            setupEvents: func(ctx sdk.Context) []abci.Event {
+                return []abci.Event{{
+                    Type:       "test_event",
+                    Attributes: []abci.EventAttribute{},
+                }}
+            },
+            wantLogs: []*gethcore.Log{
+                {
+                    // Expected log structure for empty attributes
+                },
+            },
+        },
+        // Add more test cases here
+    }
x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json (1)

6-24: Consider documenting event parameters

Add NatSpec documentation to explain:

  • Purpose and structure of eventType
  • Expected format of attrs
  • Example usage
 {
   "anonymous": false,
+  "documentation": {
+    "details": "Emitted when an ABCI event occurs. The eventType parameter indicates the ABCI event type, and attrs contains the JSON-encoded attributes.",
+    "params": {
+      "eventType": "The type of ABCI event (e.g., 'coin_received', 'message')",
+      "attrs": "JSON-encoded event attributes"
+    }
+  },
   "inputs": [
     {
       "indexed": true,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7921ecf and 0711426.

📒 Files selected for processing (21)
  • .nvmrc (1 hunks)
  • CHANGELOG.md (1 hunks)
  • contrib/bashlib.sh (1 hunks)
  • justfile (1 hunks)
  • x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/NibiruEvmUtils.sol/INibiruEvm.json (1 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/TestNativeSendThenPrecompileSend.sol/TestNativeSendThenPrecompileSend.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestPrecompileSelfCallRevert.sol/TestPrecompileSelfCallRevert.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/Wasm.sol/IWasm.json (4 hunks)
  • x/evm/embeds/contracts/IFunToken.sol (1 hunks)
  • x/evm/embeds/contracts/NibiruEvmUtils.sol (1 hunks)
  • x/evm/embeds/contracts/Wasm.sol (1 hunks)
  • x/evm/keeper/keeper_test.go (2 hunks)
  • x/evm/keeper/msg_server.go (0 hunks)
  • x/evm/precompile/funtoken.go (2 hunks)
  • x/evm/precompile/funtoken_test.go (3 hunks)
  • x/evm/precompile/nibiru_evm_utils.go (1 hunks)
  • x/evm/precompile/nibiru_evm_utils_test.go (1 hunks)
  • x/evm/precompile/wasm.go (2 hunks)
💤 Files with no reviewable changes (1)
  • x/evm/keeper/msg_server.go
✅ Files skipped from review due to trivial changes (6)
  • .nvmrc
  • x/evm/embeds/artifacts/contracts/TestERC20TransferThenPrecompileSend.sol/TestERC20TransferThenPrecompileSend.json
  • x/evm/embeds/artifacts/contracts/TestPrecompileSelfCallRevert.sol/TestPrecompileSelfCallRevert.json
  • x/evm/embeds/artifacts/contracts/TestFunTokenPrecompileLocalGas.sol/TestFunTokenPrecompileLocalGas.json
  • x/evm/embeds/artifacts/contracts/NibiruEvmUtils.sol/INibiruEvm.json
  • x/evm/embeds/artifacts/contracts/TestNativeSendThenPrecompileSend.sol/TestNativeSendThenPrecompileSend.json
🔇 Additional comments (13)
x/evm/embeds/contracts/Wasm.sol (1)

8-68: Ensure correct import path and interface integration

The import statement import "./NibiruEvmUtils.sol"; brings in INibiruEvm, which IWasm now extends. Verify that the imported file exists at the specified path and that no circular dependencies are introduced. The inheritance and updated method signatures appear consistent, and integration with INibiruEvm enhances functionality.

Run the following script to ensure the import path is correct and the code compiles without errors:

✅ Verification successful

Import path and interface integration are correctly implemented

The verification confirms:

  • NibiruEvmUtils.sol exists at the correct relative path
  • INibiruEvm interface is properly defined in NibiruEvmUtils.sol with the required BankCoin struct
  • IWasm correctly extends INibiruEvm
  • No circular dependencies were found as there are no imports of Wasm.sol in other files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `Wasm.sol` compiles successfully with the new import.

# Assuming you have `solc` installed and the Solidity files in `./contracts` directory.
solc --overwrite --abi --bin -o ./build ./contracts/Wasm.sol

Length of output: 157


Script:

#!/bin/bash
# Let's verify the import path and interface integration through file existence and content analysis

# Check if the imported file exists
fd "NibiruEvmUtils.sol" 

# Check the content of both files to verify the interface inheritance
echo "=== Content of NibiruEvmUtils.sol ==="
rg -A 5 "interface INibiruEvm" 

echo "=== Content showing IWasm inheritance ==="
rg -A 5 "interface IWasm" 

# Check for potential circular dependencies
echo "=== Checking for potential circular imports ==="
rg "import.*Wasm.sol" 

Length of output: 1398

x/evm/precompile/funtoken.go (1)

Line range hint 63-95: ABCI event emission logic correctly implemented

The added logic in the Run method for emitting ABCI events to the EVM state database is appropriate. Capturing the index of existing events before execution and emitting new events afterward ensures only relevant events are processed. The conditional check !readonly correctly prevents event emission during read-only calls.

x/evm/embeds/contracts/NibiruEvmUtils.sol (1)

16-20: Verify event type format compatibility with block explorers

The documentation mentions two event type formats:

  1. Snake case (e.g., "pending_ethereum_tx")
  2. Protobuf message names (e.g., "eth.evm.v1.EventEthereumTx")
✅ Verification successful

Based on the search results, I can see that both event type formats mentioned in the documentation are actively used in the codebase:

  1. Snake case format is used in various places, particularly for module-specific events
  2. Protobuf message format (e.g. "eth.evm.v1.EventEthereumTx") is used extensively in the EVM module

Let me verify one more aspect to ensure complete coverage:


Let me check one final aspect to see the actual event emission implementations:


Event type formats are correctly documented and consistently used

The documentation accurately reflects the two event type formats used in the codebase:

  1. Snake case format (e.g., "pending_ethereum_tx") is used for CometBFT indexer events, as seen in evm.PendingEthereumTxEvent
  2. Protobuf message format (e.g., "eth.evm.v1.EventEthereumTx") is used for typed events, as evidenced by numerous protobuf event definitions in the codebase

The implementation consistently follows these conventions across different modules, ensuring compatibility with block explorers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for consistent event type usage across the codebase
echo "Searching for event type declarations..."
rg -A 1 'eventType.*=.*"[^"]*"' 

# Check for event type string literals
echo "Checking event type format consistency..."
rg '"[a-z_]+\.[a-z_]+\.v[0-9]+\.[A-Za-z]+"' 
rg '"[a-z_]+"'

Length of output: 65864


Script:

# Check for event emission in Go code
rg 'EventTypeKey.*=.*"[^"]*"' 
rg 'ctx\.EventManager\(\)\.EmitEvent\('

Length of output: 256


Script:

# Check the event emission implementations
rg -A 5 'ctx\.EventManager\(\)\.EmitEvent\(' 

Length of output: 1455

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

7-12: LGTM: Clean integration of ABCI event capabilities

The inheritance from INibiruEvm is a clean way to add ABCI event capabilities while maintaining the existing token functionality. The import statement is correctly placed, and the interface hierarchy is well-structured.

x/evm/precompile/nibiru_evm_utils_test.go (1)

26-58: LGTM: TestAttrsToJSON has good test coverage

The test cases effectively verify the JSON conversion logic with edge cases:

  • Handling of repeated keys
  • Multiple unique attributes
  • JSON structure validation
x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json (1)

6-24: Verify event parameter indexing strategy

The current indexing strategy allows searching by eventType but not attrs. Consider if this meets the requirements for block explorers and indexers.

✅ Verification successful

Event indexing strategy is appropriate

The current indexing strategy (indexed eventType, non-indexed attrs) aligns with both the codebase patterns and technical constraints:

  1. The same event structure is used in NibiruEvmUtils.sol: event AbciEvent(string indexed eventType, bytes attrs)
  2. The indexing strategy is appropriate because:
    • eventType being indexed enables efficient filtering/searching of specific event types
    • bytes type parameters are typically not indexed due to their variable size nature and gas costs
    • Other events in the codebase (TestEvent, ValueUpdateAttempted) follow similar patterns of indexing fixed-size parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other contracts in the codebase follow similar indexing patterns
ast-grep --pattern 'event $name($$$) {
  $$$
}'

# Check if there are any existing events with bytes as indexed parameters
ast-grep --pattern 'event $name($$$) {
  indexed bytes $varname
  $$$
}'

Length of output: 124


Script:

#!/bin/bash
# Let's try a different approach to find events in Solidity files
# First, find all Solidity files
fd -e sol -x cat {} | grep -A 5 "event.*{.*"

# Also search for any files containing "event" to ensure we don't miss anything
rg "event.*{" -A 5

Length of output: 1108


Script:

#!/bin/bash
# Let's try a more specific search in the actual source files
# First, let's find the actual Solidity source files
fd -e sol -x realpath {} | grep -v "artifacts"

# Then search for events with proper regex
rg "event\s+\w+\s*\([^)]*\)" -A 5

# Also check the specific contract file
cat x/evm/embeds/contracts/IFunToken.sol

Length of output: 4291

x/evm/embeds/artifacts/contracts/Wasm.sol/IWasm.json (2)

6-24: LGTM: Well-structured event declaration for ABCI events

The new AbciEvent is well-designed with:

  • Indexed eventType field for efficient filtering
  • Non-indexed attrs field for flexible attribute storage

50-50: LGTM: Consistent type refactoring across functions

The change from IWasm.BankCoin[] to INibiruEvm.BankCoin[] promotes code reuse by utilizing a common type.

Also applies to: 93-93, 149-149

x/evm/precompile/wasm.go (2)

49-50: LGTM: Efficient event tracking implementation

Capturing the initial event count before operations allows precise tracking of new events.


79-86: LGTM: Well-placed conditional event emission

The implementation:

  • Correctly skips event emission for read-only transactions
  • Captures all events by emitting after operations complete
  • Uses proper event range based on tracked start index
x/evm/precompile/funtoken_test.go (2)

25-25: LGTM: Enhanced test coverage

Added UtilsSuite to the test suite improves test coverage.


228-231: LGTM: Proper fee collector funding

Using sdkmath.NewInt ensures precise handling of large numbers in the SDK context.

CHANGELOG.md (1)

54-54: LGTM! Well-formatted changelog entry.

The changelog entry for PR #2125 is properly formatted, placed in the correct section, and clearly describes the feature's purpose of emitting EVM events to reflect ABCI events for block explorer visibility.

emittingAddr gethcommon.Address,
) {
blockNumber := uint64(ctx.BlockHeight())
event := embeds.SmartContract_Wasm.ABI.Events[EvmEventAbciEvent]
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for missing event definition

In the EmitEventAbciEvents function, there is no check to ensure that the AbciEvent is present in the ABI. If the event definition is missing, it could lead to a runtime panic. Consider adding error handling to verify that the event is found before proceeding.

Apply this diff to add the check:

 event := embeds.SmartContract_Wasm.ABI.Events[EvmEventAbciEvent]
+if event == nil {
+    // Handle the error appropriately, e.g., log or return an error
+    return
+}

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +60 to +77
for i, attr := range attrs {
// Keys must be unique to guarantee valid JSON object
if keysSeen.Has(attr.Key) {
continue
}
keysSeen.Add(attr.Key)

if i > 0 {
buf.WriteByte(',')
}

// Quote key and value
_, _ = fmt.Fprintf(&buf, `"%s":"%s"`, attr.Key, attr.Value)
}
buf.WriteByte('}')

return buf.Bytes()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect comma placement when skipping duplicate keys

In the AttrsToJSON function, the current logic for inserting commas between JSON key-value pairs uses the loop index i, which counts all attributes, including those skipped due to duplicate keys. This can lead to improperly formatted JSON with extra commas when duplicate keys are present.

To ensure valid JSON, track the number of entries actually added to the buffer instead of using the loop index.

Apply the following diff to correct the issue:

 var buf bytes.Buffer
 buf.WriteByte('{')
+count := 0
 for _, attr := range attrs {
     // Keys must be unique to guarantee valid JSON object
     if keysSeen.Has(attr.Key) {
         continue
     }
     keysSeen.Add(attr.Key)

-    if i > 0 {
+    if count > 0 {
         buf.WriteByte(',')
     }
+    count++

     // Quote key and value
     _, _ = fmt.Fprintf(&buf, `"%s":"%s"`, attr.Key, attr.Value)
 }
 buf.WriteByte('}')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for i, attr := range attrs {
// Keys must be unique to guarantee valid JSON object
if keysSeen.Has(attr.Key) {
continue
}
keysSeen.Add(attr.Key)
if i > 0 {
buf.WriteByte(',')
}
// Quote key and value
_, _ = fmt.Fprintf(&buf, `"%s":"%s"`, attr.Key, attr.Value)
}
buf.WriteByte('}')
return buf.Bytes()
}
var buf bytes.Buffer
buf.WriteByte('{')
count := 0
for _, attr := range attrs {
// Keys must be unique to guarantee valid JSON object
if keysSeen.Has(attr.Key) {
continue
}
keysSeen.Add(attr.Key)
if count > 0 {
buf.WriteByte(',')
}
count++
// Quote key and value
_, _ = fmt.Fprintf(&buf, `"%s":"%s"`, attr.Key, attr.Value)
}
buf.WriteByte('}')
return buf.Bytes()
}

x/evm/precompile/nibiru_evm_utils.go Show resolved Hide resolved
Comment on lines +28 to +41
# Generate Solidity artifacts for x/evm/embeds
gen-embeds:
#!/usr/bin/env bash
source contrib/bashlib.sh

embeds_dir="x/evm/embeds"
log_info "Begin to compile Solidity in $embeds_dir"
which_ok npm
log_info "Using system node version: $(npm exec -- node -v)"

cd "$embeds_dir" || (log_error "path $embeds_dir not found" && exit)
npx hardhat compile
log_success "Compiled Solidity in $embeds_dir"

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling in gen-embeds recipe

The recipe should handle common failure scenarios:

  • Node.js version mismatch
  • Missing dependencies
  • Compilation errors
 gen-embeds:
   #!/usr/bin/env bash
   source contrib/bashlib.sh
 
   embeds_dir="x/evm/embeds"
   log_info "Begin to compile Solidity in $embeds_dir"
-  which_ok npm
+  if ! which_ok npm; then
+    log_error "npm not found. Please install Node.js"
+    exit 1
+  fi
+
+  if [ ! -f "package.json" ]; then
+    log_error "package.json not found in $embeds_dir"
+    exit 1
+  fi
+
   log_info "Using system node version: $(npm exec -- node -v)"
 
   cd "$embeds_dir" || (log_error "path $embeds_dir not found" && exit)
+  npm install || (log_error "Failed to install dependencies" && exit 1)
   npx hardhat compile
   log_success "Compiled Solidity in $embeds_dir"

Committable suggestion skipped: line range outside the PR's diff.

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/artifacts/contracts/Wasm.sol/IWasm.json (1)

50-50: BankCoin struct references standardized across interfaces.
Switching from IWasm.BankCoin[] to INibiruEvm.BankCoin[] is a sensible refactor that consolidates data structures into the INibiruEvm interface and promotes reusability of the BankCoin definition. Ensure external code references are updated accordingly.

Also applies to: 93-93, 149-149

CHANGELOG.md (2)

Line range hint 1-24: Consider standardizing the version header format.

While the changelog is well-organized overall, consider standardizing the version header format. Some versions use ## [v1.0.0] while others use ## v0.15.0 (without brackets). Maintaining consistency in formatting helps with readability.


Line range hint 25-50: Consider refining change categorization.

The changelog uses multiple categories to classify changes, which is good practice. However, consider:

  1. Avoiding duplicate entries across categories
  2. Using consistent category names across versions
  3. Clearly distinguishing between "State Machine Breaking" and "API Breaking" changes

This will help users better understand the impact of each change.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0711426 and 7e3fbcf.

📒 Files selected for processing (14)
  • CHANGELOG.md (1 hunks)
  • x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/NibiruEvmUtils.sol/INibiruEvm.json (1 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/TestNativeSendThenPrecompileSend.sol/TestNativeSendThenPrecompileSend.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/TestPrecompileSelfCallRevert.sol/TestPrecompileSelfCallRevert.json (1 hunks)
  • x/evm/embeds/artifacts/contracts/Wasm.sol/IWasm.json (4 hunks)
  • x/evm/embeds/contracts/NibiruEvmUtils.sol (1 hunks)
  • x/evm/precompile/funtoken.go (2 hunks)
  • x/evm/precompile/nibiru_evm_utils.go (1 hunks)
  • x/evm/precompile/nibiru_evm_utils_test.go (1 hunks)
  • x/evm/precompile/wasm.go (2 hunks)
  • x/evm/statedb/statedb.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • x/evm/embeds/artifacts/contracts/TestFunTokenPrecompileLocalGas.sol/TestFunTokenPrecompileLocalGas.json
  • x/evm/embeds/artifacts/contracts/IFunToken.sol/IFunToken.json
  • x/evm/embeds/artifacts/contracts/TestPrecompileSelfCallRevert.sol/TestPrecompileSelfCallRevert.json
  • x/evm/precompile/wasm.go
  • x/evm/embeds/artifacts/contracts/TestERC20TransferThenPrecompileSend.sol/TestERC20TransferThenPrecompileSend.json
  • x/evm/embeds/artifacts/contracts/TestNativeSendThenPrecompileSend.sol/TestNativeSendThenPrecompileSend.json
  • x/evm/precompile/nibiru_evm_utils_test.go
  • x/evm/precompile/nibiru_evm_utils.go
  • x/evm/precompile/funtoken.go
🔇 Additional comments (6)
x/evm/statedb/statedb.go (2)

124-126: Clarify usage context in docstring.
The new comment for AddLog is informative and well-structured. It explains how TxConfig is used to populate important fields in the event log. This docstring helps readers understand the source of these fields without having to dig into TxConfig. Good job!


137-137: Doc comment consistency.
The comment for the Logs() method now explicitly mentions "event logs," promoting clarity and uniformity in naming across the file. This minor change helps future maintainers quickly identify the purpose of this method.

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

6-23: Event definition is clear and well-formed.
The newly introduced AbciEvent in this contract artifact provides a direct mapping to ABCI events. The usage of an indexed eventType helps indexers filter events quickly based on their type. No issues found.

x/evm/embeds/contracts/NibiruEvmUtils.sol (1)

4-23: Interface design is consistent and extensible.
Defining a separate interface INibiruEvm with the BankCoin struct and the AbciEvent event adheres to good modular design and improves maintainability. Documentation is thorough, making it clear how the event can be used by EVM logs and indexers.

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

6-24: New event aligns with the ABCI-EVM integration.
Adding the AbciEvent to IWasm ensures uniformity across different contracts that need to relay ABCI events. The indexed eventType field is consistent with the approach in other interfaces.

CHANGELOG.md (1)

54-54: LGTM! The changelog entry follows best practices.

The entry clearly describes:

  • The type of change (feat)
  • The affected module (evm-precompile)
  • The change description
  • The rationale/impact of the change

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

Attention: Patch coverage is 95.71429% with 3 lines in your changes missing coverage. Please review.

Project coverage is 65.09%. Comparing base (1a256f2) to head (7e3fbcf).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
x/evm/precompile/nibiru_evm_utils.go 94.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2125      +/-   ##
==========================================
+ Coverage   65.00%   65.09%   +0.08%     
==========================================
  Files         273      274       +1     
  Lines       21661    21731      +70     
==========================================
+ Hits        14080    14145      +65     
- Misses       6608     6613       +5     
  Partials      973      973              
Files with missing lines Coverage Δ
x/evm/precompile/funtoken.go 59.15% <100.00%> (+1.26%) ⬆️
x/evm/precompile/wasm.go 64.24% <100.00%> (+1.95%) ⬆️
x/evm/statedb/statedb.go 90.42% <ø> (ø)
x/evm/precompile/nibiru_evm_utils.go 94.00% <94.00%> (ø)

... and 1 file with indirect coverage changes

@Unique-Divine Unique-Divine merged commit 666a58d into main Dec 30, 2024
16 checks passed
@Unique-Divine Unique-Divine deleted the ud/evm-event branch December 30, 2024 05:53
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.

feat(evm-precompile): Emit ABCI events as EVM events
1 participant