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(evm): proper eth tx logs emission for funtoken operations #2212

Merged
merged 2 commits into from
Feb 18, 2025

Conversation

onikonychev
Copy link
Contributor

Fixes:

  • funtoken precompile sendToBank call duplicated logs due to outdated code
  • ConvertCoinToEvm for erc20 born coins did not emit Transfer tx log
  • CreateFunToken from coin did not emit log of contract creation

Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

📝 Walkthrough

Walkthrough

This pull request updates the changelog to document a fix for Ethereum transaction logs in FunToken operations. It removes the unused BigPow function from the ERC20 test file, adjusts keeper functions (including contract calls and message processing) to modify event emission and block bloom updates, and enhances tests by adding event assertions and required imports. Additionally, the response handling in precompiled FunToken operations is streamlined by removing unnecessary response tracking.

Changes

File(s) Change Summary
CHANGELOG.md Added a new unreleased entry documenting a fix for proper Ethereum transaction logs emission for FunToken operations.
x/evm/evmtest/erc20.go Removed the BigPow function used for multiplying big integers.
x/evm/keeper/call_contract.go Removed block gas update and tx log emission in CallContractWithInput; now returns evmResp without extra processing.
x/evm/keeper/funtoken_from_coin.go,
x/evm/keeper/msg_server.go
Modified keeper methods to capture evmResp, emit transaction logs via the event manager, and update the block bloom filter appropriately.
x/evm/keeper/funtoken_from_coin_test.go,
x/evm/keeper/funtoken_from_erc20_test.go
Added new import (gethcommon), enhanced test assertions to verify event logging (ownership and transfer events), and updated context initialization.
x/evm/precompile/funtoken.go Removed the evmResponses slice and simplified the handling of responses in the Transfer and Burn methods, retaining only error management.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MsgServer
    participant Keeper
    participant EVMContract
    participant EventManager

    Client->>MsgServer: ConvertCoinToEvm Request
    MsgServer->>Keeper: Process ConvertCoinToEvm
    Keeper->>EVMContract: Call ERC20 Transfer/Mint
    EVMContract-->>Keeper: Return evmResp (logs)
    Keeper->>EventManager: Emit EventTxLog with evmResp logs
    Keeper->>EventManager: Update Block Bloom Filter
    Keeper-->>MsgServer: Return evmResp, nil error
    MsgServer-->>Client: Send Response
Loading

Possibly related PRs

Suggested labels

x: evm

Suggested reviewers

  • Unique-Divine
  • k-yang

Poem

In the code fields I hop so free,
Logging events under the Ethereum tree.
BigPow is gone, as clear as day,
With blooms updated in a new way.
I'm a bunny coding with glee—
EVM logs leap with joy from me!
🐰🚀


📜 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 5b23321 and 62cc65e.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • x/evm/evmtest/erc20.go (0 hunks)
  • x/evm/keeper/call_contract.go (0 hunks)
  • x/evm/keeper/funtoken_from_coin.go (2 hunks)
  • x/evm/keeper/funtoken_from_coin_test.go (5 hunks)
  • x/evm/keeper/funtoken_from_erc20_test.go (3 hunks)
  • x/evm/keeper/msg_server.go (3 hunks)
  • x/evm/precompile/funtoken.go (2 hunks)
💤 Files with no reviewable changes (2)
  • x/evm/keeper/call_contract.go
  • x/evm/evmtest/erc20.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e-evm
🔇 Additional comments (7)
x/evm/keeper/funtoken_from_coin.go (1)

105-121: LGTM! Proper event emission for contract deployment.

The changes correctly capture and emit the contract deployment logs, including the OwnershipTransferred event, and update the block bloom filter. This enhances the visibility and traceability of contract deployments.

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

171-172: LGTM! Fixed duplicate logs emission.

The changes correctly fix the duplicate logs issue by only capturing the necessary information from the Transfer and Burn operations, discarding the responses that were causing duplicate log emissions.

Also applies to: 190-191

x/evm/keeper/funtoken_from_erc20_test.go (1)

275-332: LGTM! Enhanced test coverage for event emission.

The changes add comprehensive test coverage for event emission, verifying both the high-level EventConvertCoinToEvm and the low-level EventTxLog events with proper data validation.

x/evm/keeper/msg_server.go (1)

568-572: LGTM! Proper event emission for coin conversion operations.

The changes ensure that both convertCoinToEvmBornCoin and convertCoinToEvmBornERC20 functions properly emit transaction logs and update the block bloom filter, enhancing the visibility and traceability of coin conversion operations.

Also applies to: 669-673

x/evm/keeper/funtoken_from_coin_test.go (2)

143-172: LGTM! The test case properly verifies the OwnershipTransferred event.

The test case correctly verifies that the EventTxLog event is emitted with the OwnershipTransferred event, including proper validation of the event signature, topics, and data.


229-258: LGTM! The test case properly verifies the Transfer event.

The test case correctly verifies that the EventTxLog event is emitted with the Transfer event, including proper validation of the event signature, topics, and data.

CHANGELOG.md (1)

50-50: LGTM! The changelog entry is properly formatted and accurately describes the changes.

The entry follows the changelog format guidelines and correctly references the PR number and the fix for proper eth tx logs emission.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

Comment on lines -228 to -232
for _, resp := range evmResponses {
for _, log := range resp.Logs {
startResult.StateDB.AddLog(log.ToEthereum())
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this produced duplicates.

Copy link
Member

Choose a reason for hiding this comment

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

I thought we added this in https://github.com/NibiruChain/nibiru/pull/2093/files#diff-199132a0cc4ad1df87325761675688436e1e9dc09d8b24908631937349e12f89 because we were missing logs, how did we end up with duplicates?

Comment on lines -85 to -94

// Success, update block gas used and bloom filter
if commit {
k.updateBlockBloom(ctx, evmResp, uint64(txConfig.LogIndex))

err = ctx.EventManager().EmitTypedEvent(&evm.EventTxLog{Logs: evmResp.Logs})
if err != nil {
return nil, errors.Wrap(err, "error emitting tx logs")
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TxLogs is now emitted properly at the end of the execution, not on each CallContract separately

Comment on lines +117 to +122
// Emit the logs from the EVM Contract deploy execution
err = ctx.EventManager().EmitTypedEvent(&evm.EventTxLog{Logs: evmResp.Logs})
if err == nil {
k.updateBlockBloom(ctx, evmResp, uint64(0))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

emits OwnershipTransferred(address,address) log for the newly deployed contract.

@onikonychev onikonychev marked this pull request as ready for review February 14, 2025 18:59
@onikonychev onikonychev requested a review from a team as a code owner February 14, 2025 18:59
@Unique-Divine Unique-Divine merged commit 6b4aa19 into main Feb 18, 2025
11 checks passed
@Unique-Divine Unique-Divine deleted the fix/funtoken-tx-logs branch February 18, 2025 19:38
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.

4 participants