node icon indicating copy to clipboard operation
node copied to clipboard

feat!: add stateful precompiles support

Open fbac opened this issue 1 year ago • 7 comments

Description

Introduce the stateful precompiled contracts support into the ZetaChain node.

Closes https://github.com/zeta-chain/node/issues/2511 Closes https://github.com/zeta-chain/node/issues/2512 Closes https://github.com/zeta-chain/node/issues/2498

Summary

  • Minor cleanups in Makefile and go.mod: not related to the PR directly, but needed in order to cleanup the codebase and introduce subsequent changes.
  • No longer import evmos/ethermint, instead import zeta-chain/ethermint directly.
  • NewEVM now returns an instance of *vm.EVM, which is instantiated from go-ethereum/core/vm and supports stateful precompiled contracts.
  • simapp dependency was removed from zeta-chain/ethermint in https://github.com/zeta-chain/ethermint/commit/a8efba4649eaf8c8dfeb585f34ebb73792113b88, hence some parts of the code such as app/encoding.go still using types from simapp were failing. Replaced simapp types for zeta-chain/ethermint/types
  • Introduced the prototype contract, deployed in 0x0000000000000000000000000000000000000065
  • Introduced e2e tests for the prototype contract.
    • Modified localnet.yml and e2e tests to include a new user user_precompile
  • Introduced a new Makefile target make precompile to generate the abi and bindings for each precompile.

How Has This Been Tested?

  • [ ] Tested CCTX in localnet
  • [ ] Tested in development environment
  • [x] Go unit tests
  • [x] Go integration tests
  • [x] Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Introduced support for stateful precompiled contracts, enhancing contract management capabilities.
  • Bug Fixes

    • Updated various import paths to reflect the transition from Evmos to Zeta Chain, ensuring correct package resolution across the application.
  • Documentation

    • Updated license URLs in comments to point to the Zeta Chain repository.
    • Improved formatting and readability in several documentation files.
  • Chores

    • Consolidated and reorganized package dependencies in the project’s go.mod file to align with Zeta Chain's libraries.

fbac avatar Aug 05 '24 12:08 fbac

[!IMPORTANT]

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The recent changes primarily involve updating import paths across multiple files to transition from the evmos to the zeta-chain repository. This includes modifications to licensing information and the introduction of new variables in the Makefile. The updates aim to adapt the core node to support stateful precompiled contracts, streamline dependencies, and enhance the organization of code without altering core functionalities.

Changes

Files Change Summary
Makefile Added variables for package name, Go version, and GOPATH. Consolidated test commands and improved readability.
app/... (ante.go, fees.go, ...) Updated import paths to reference the zeta-chain repository instead of evmos, and amended licensing URLs.
cmd/... (zetacored/add_observer_list.go, ...) Changed import paths to zeta-chain for various modules, indicating a shift in dependency management.
rpc/... (backend/*.go) Modified imports and licensing comments to reflect the new source under zeta-chain.
go.mod Added new dependencies from zeta-chain, removed old ones, and updated existing package versions.

Sequence Diagram(s)

sequenceDiagram
    participant Node
    participant Contracts
    participant State
    Node->>Contracts: Request stateful precompiled contract
    Contracts->>State: Validate contract state
    State-->>Contracts: Return validation result
    Contracts-->>Node: Provide contract interaction result

Assessment against linked issues

Objective Addressed Explanation
Import the zeta-chain/ethermint release supporting stateful precompiles ( #2511 )
Integration with existing node code ( #2511 )
Cleanup go.mod ( #2511 )
No precompiled contracts should be initialized with the app ( #2511 ) The implementation does not specifically address initialization logic.
Import zeta-chain/go-ethereum release supporting stateful precompiles ( #2511 ) Unclear if the relevant code for Ethereum integration has been included.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

coderabbitai[bot] avatar Aug 05 '24 12:08 coderabbitai[bot]

Codecov Report

Attention: Patch coverage is 73.97260% with 38 lines in your changes missing coverage. Please review.

Project coverage is 66.83%. Comparing base (42eb4bd) to head (fffd126). Report is 1 commits behind head on develop.

Files Patch % Lines
precompiles/prototype/prototype.go 69.35% 33 Missing and 5 partials :warning:
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2633      +/-   ##
===========================================
+ Coverage    66.78%   66.83%   +0.05%     
===========================================
  Files          364      368       +4     
  Lines        20516    20662     +146     
===========================================
+ Hits         13702    13810     +108     
- Misses        6186     6219      +33     
- Partials       628      633       +5     
Files Coverage Δ
pkg/mempool/senders_with_nonce.go 87.50% <ø> (ø)
precompiles/precompiles.go 100.00% <100.00%> (ø)
precompiles/types/errors.go 100.00% <100.00%> (ø)
precompiles/types/types.go 100.00% <100.00%> (ø)
x/crosschain/keeper/evm_deposit.go 86.95% <ø> (ø)
x/crosschain/keeper/evm_hooks.go 84.42% <ø> (ø)
x/fungible/keeper/deposits.go 95.74% <ø> (ø)
x/fungible/keeper/evm.go 88.38% <ø> (ø)
x/fungible/keeper/evm_hooks.go 100.00% <ø> (ø)
x/fungible/keeper/v2_deposits.go 21.73% <ø> (ø)
... and 6 more

codecov[bot] avatar Aug 08 '24 10:08 codecov[bot]

It would be nice to add a simple contract and invoke it on the e2e side to demonstrate that this actually works?

Yes, that's going to be a second PR on top of this branch. This is just the base feature.

fbac avatar Aug 10 '24 11:08 fbac

Closing this PR as the review has been finalized. I'll open a second PR integrating the contracts into this branch.

fbac avatar Aug 14 '24 15:08 fbac

@fbac would be good to revolve conflicts first.

swift1337 avatar Aug 21 '24 12:08 swift1337

Seems we need to run make generate

lumtis avatar Aug 21 '24 14:08 lumtis

We will need to look into removing the test from the initial run in upgrade test, since precompile have been introduced in this release

lumtis avatar Aug 21 '24 16:08 lumtis

Seems we need to run make generate

@lumtis for make generate to work now we need solc and abigen installed for make precompiles to work in ci, which seems like an overhead to me since it adds some time, i added it to workflow action simplest way, will try to find better way if possible, at least to hardcode solc version - do we need to generate bindings for precompiles in this action?

EDIT: i added solc-select to action and some checks to script for solc/solc-select to make it a bit more robust

skosito avatar Aug 26 '24 21:08 skosito