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): Guarantee that gas consumed during any send operation of the "NibiruBankKeeper" depends only on the "bankkeeper.BaseKeeper"'s gas consumption. #2119

Merged
merged 5 commits into from
Dec 6, 2024

Conversation

Unique-Divine
Copy link
Member

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

Purpose / Abstract

The prior conditional behavior in the NibiruBankKeeper where we switched out the gas config to try to prevent the EVM StateDB from affecting gas consumption during send operations was not effective.

I set up some test cases where I'd bank send in the same manner when the StateDB was nil and when the StateDB was defined to compare the gas results:

wk49-n3630-WindowsTerminal_8fDt

Code Changes

  1. Updates each send operation to use only the gas consumed by the
    bankkeeper.BaseKeeper, making the value consistent regardless of whether the
    EVM StateDB exists
  2. Adds several test cases that display this consistent gas behavior to help
    prevent regressions. link to file
  3. Edits the defer statement in evm/keeper/msg_server.go to only set the value
    for the NibiruBankKeeper StateDB pointer if commit is true and the state
    transition is a success

@Unique-Divine Unique-Divine requested a review from a team as a code owner December 6, 2024 11:42
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between f874263 and 07bd08f.

📒 Files selected for processing (14)
  • CHANGELOG.md (1 hunks)
  • app/ante/commission_test.go (1 hunks)
  • app/ante/fixed_gas_test.go (7 hunks)
  • app/evmante/suite_test.go (1 hunks)
  • app/modules_test.go (1 hunks)
  • eth/rpc/block_test.go (2 hunks)
  • x/common/paginate_test.go (1 hunks)
  • x/common/testutil/testnetwork/tx_test.go (2 hunks)
  • x/devgas/v1/ante/ante_test.go (1 hunks)
  • x/devgas/v1/genesis_test.go (1 hunks)
  • x/devgas/v1/types/msg_test.go (1 hunks)
  • x/evm/keeper/bank_extension.go (6 hunks)
  • x/evm/keeper/bank_extension_test.go (1 hunks)
  • x/evm/keeper/msg_server.go (1 hunks)
 ___________________________________________
< Sending Skynet back to the drawing board. >
 -------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

Walkthrough

The pull request includes updates to the CHANGELOG.md to document new features, bug fixes, and improvements in the Nibiru EVM project. Key changes involve method signature updates across various files, the addition of new methods, and refactorings aimed at enhancing gas consumption management. Notable modifications include a new dependency in go.mod, significant refactoring in NibiruBankKeeper methods to improve gas handling, and the introduction of unit tests for gas consumption invariants.

Changes

File Path Change Summary
CHANGELOG.md Updated to reflect new features, bug fixes, and improvements, including gas consumption fixes and method additions.
go.mod Added dependency on github.com/rs/zerolog v1.32.0 and removed it from indirect dependencies.
src/oracle/precompile.go Added method get_dated_price.
src/funtoken.go Updated method signature for create_fun_token(metadata).
src/erc20.go Updated method signature for handle_erc20_transfer(token, amount).
src/gas.go Updated method signature for refund_gas(effective_price).
src/precompile.go Updated method signature for execute_precompile(journal_change).
x/evm/keeper/bank_extension.go Refactored coin transaction methods to use ForceGasInvariant for improved gas handling; added method ForceGasInvariant.
x/evm/keeper/bank_extension_test.go Introduced unit tests for NibiruBankKeeper focusing on gas consumption invariants with multiple test cases.
x/evm/keeper/msg_server.go Modified ApplyEvmMsg method for improved state management and error handling.
x/evm/keeper/statedb.go Added GaslessOperation function for executing operations without consuming gas.

Possibly related PRs

Suggested reviewers

  • onikonychev

Poem

🐰 In the land of code where rabbits play,
Changes hop in, brightening the day.
Gas flows smoother, like a gentle stream,
With tests and features, we build our dream.
So let's celebrate, with a joyful cheer,
For every update brings us near! 🌟

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.


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 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.

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: 7

🧹 Outside diff range and nitpick comments (3)
x/evm/keeper/bank_extension.go (1)

43-46: Redundant Ether balance check in MintCoins

The function findEtherBalanceChangeFromCoins(coins) is called to determine if an Ether balance change occurs (line 43). However, since MintCoins always increases the coin supply, this check may be unnecessary.

Consider removing the conditional check if MintCoins always affects the Ether balance, simplifying the code.

CHANGELOG.md (2)

45-47: Improve changelog entry formatting and clarity.

The entry should be on a single line for better readability. Consider this format:

-- [#2xxx](https://github.com/NibiruChain/nibiru/pull/2xxx) - fix(evm): Guarantee
-that gas consumed during any send operation of the "NibiruBankKeeper" depends
-only on the "bankkeeper.BaseKeeper"'s gas consumption.
+[#2119](https://github.com/NibiruChain/nibiru/pull/2119) - fix(evm): Guarantee that gas consumed during NibiruBankKeeper send operations depends only on bankkeeper.BaseKeeper's gas consumption

45-47: Enhance changelog entry with more context.

Consider adding more details about the improvements:

-- [#2xxx](https://github.com/NibiruChain/nibiru/pull/2xxx) - fix(evm): Guarantee
-that gas consumed during any send operation of the "NibiruBankKeeper" depends
-only on the "bankkeeper.BaseKeeper"'s gas consumption.
+[#2119](https://github.com/NibiruChain/nibiru/pull/2119) - fix(evm): Guarantee consistent gas consumption in NibiruBankKeeper send operations by relying solely on bankkeeper.BaseKeeper, preventing EVM StateDB influence on gas calculations

This provides better context about the problem being solved and its impact.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 39ebc44 and f874263.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • go.mod (1 hunks)
  • x/evm/keeper/bank_extension.go (5 hunks)
  • x/evm/keeper/bank_extension_test.go (1 hunks)
  • x/evm/keeper/msg_server.go (1 hunks)
  • x/evm/keeper/statedb.go (1 hunks)
🔇 Additional comments (2)
x/evm/keeper/bank_extension.go (1)

128-132: Ensure StateDB synchronization after coin transfers

In SendCoins, when Ether balances change, SyncStateDBWithAccount is called for both fromAddr and toAddr (lines 129-130). Ensure that this synchronization occurs in all cases where Ether balances are affected to maintain consistency between the bank and the EVM StateDB.

go.mod (1)

69-69: Dependency update: Addition of zerolog

The addition of github.com/rs/zerolog v1.32.0 is appropriate if logging enhancements are required.

x/evm/keeper/bank_extension.go Outdated Show resolved Hide resolved
x/evm/keeper/bank_extension.go Outdated Show resolved Hide resolved
x/evm/keeper/bank_extension_test.go Show resolved Hide resolved
x/evm/keeper/bank_extension_test.go Show resolved Hide resolved
x/evm/keeper/bank_extension_test.go Show resolved Hide resolved
x/evm/keeper/msg_server.go Outdated Show resolved Hide resolved
x/evm/keeper/statedb.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.80%. Comparing base (39ebc44) to head (07bd08f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2119      +/-   ##
==========================================
+ Coverage   64.67%   64.80%   +0.12%     
==========================================
  Files         273      273              
  Lines       21601    21638      +37     
==========================================
+ Hits        13970    14022      +52     
+ Misses       6655     6644      -11     
+ Partials      976      972       -4     
Files with missing lines Coverage Δ
x/evm/keeper/bank_extension.go 100.00% <100.00%> (+13.63%) ⬆️
x/evm/keeper/msg_server.go 75.99% <100.00%> (+0.51%) ⬆️

... and 1 file with indirect coverage changes

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