feat: enable precompiled contracts
Description
-
Enable prototype precompiled contracts which suuports the following methods
-
bech32ToHexAddr(string bech32) view returns (address addr): Converts a bech32 address to hexadecimal address -
bech32ify(string prefix, address addr) view returns (string bech32): Converts a hex address to bech32 address -
getGasStabilityPoolBalance(int64 chainID) view returns (uint256 result): Returns the balance of the gas stability pool for a given chain ID -
Fix unit tests for all contracts prtotype,bank and staking
-
Refactor e2e tests to only run tests for the prototype contract . This will be availabel at the address
0x0000000000000000000000000000000000000065 -
Add an overview document
Closes : https://github.com/zeta-chain/node/issues/3840
How Has This Been Tested?
- [ ] Tested CCTX in localnet
- [ ] Tested in development environment
- [ ] Go unit tests
- [ ] Go integration tests
- [ ] Tested via GitHub Actions
Summary by CodeRabbit
- New Features
- Enabled stateful precompiled contracts, including staking and bank contracts, making them active by default.
- Bug Fixes
- Adjusted end-to-end tests to run precompiled contract tests by default and updated test references to reflect enabled staking precompiles.
- Tests
- Disabled tests that expected staking methods to be disabled, and ensured proper state cleanup after staking tests.
- Documentation
- Updated changelog to reflect the new feature of enabling precompiled contracts.
[!IMPORTANT]
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
📝 Walkthrough
Walkthrough
The changes collectively enable and activate stateful precompiled contracts—specifically the staking, prototype, and bank contracts—across the codebase. The relevant entries in the changelog and configuration files have been updated to reflect this activation. End-to-end and unit tests that previously checked for disabled contract methods have been commented out or replaced with tests that validate the now-enabled functionality. The staking contract logic has been modified to remove the early returns that previously disabled staking-related methods, allowing their execution. Command-line flags and test runners have been adjusted to include precompiled contract tests by default.
Changes
| File(s) | Change Summary |
|---|---|
| changelog.md | Added a new feature entry under "UNRELEASED" noting the enabling of precompiled contracts, referencing PR #3833. |
| cmd/zetae2e/local/local.go | Changed the default for the flagSkipPrecompiles flag to false, enabling precompiled contract tests by default. Uncommented logic and test names to include these tests. Added a log statement to display the skip flag's value. |
| e2e/e2etests/e2etests.go | Updated the test registration for "precompile_contracts_staking" to use TestPrecompilesStaking instead of the disabled test variant. |
| e2e/e2etests/test_precompiles_staking.go | Added a deferred cleanup call to CleanValidatorDelegations after its initial invocation in TestPrecompilesStaking, ensuring test state is restored post-execution. |
| precompiles/precompiles.go | Set the enabled flag to true for prototype.ContractAddress, staking.ContractAddress, and bank.ContractAddress in the EnabledStatefulContracts map, activating these precompiled contracts. |
| precompiles/staking/method_move_stake_test.go precompiles/staking/method_stake_test.go precompiles/staking/method_unstake_test.go |
Commented out the "should fail with error disabled" test cases in the respective staking method test files, effectively disabling tests that assert staking methods are disabled. Updated import statements accordingly and added comments referencing the relevant PR. |
| precompiles/staking/staking.go | Removed the early returns that blocked execution of Stake, Unstake, and MoveStake methods in the staking precompile contract. These methods now proceed with their staking logic as intended. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant CLI/TestRunner
participant PrecompileModule
participant StakingContract
participant StateDB
User->>CLI/TestRunner: Run E2E or unit tests
CLI/TestRunner->>PrecompileModule: Load enabled precompiles
PrecompileModule->>StakingContract: Enable staking, prototype, bank contracts
CLI/TestRunner->>StakingContract: Invoke Stake/Unstake/MoveStake methods
StakingContract->>StateDB: Execute native staking actions
StateDB-->>StakingContract: Return result
StakingContract-->>CLI/TestRunner: Return success or error
CLI/TestRunner-->>User: Report test results
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
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.
Codecov Report
Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
Project coverage is 65.05%. Comparing base (
101cbe9) to head (04ce12a). Report is 1 commits behind head on develop.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| precompiles/staking/method_get_rewards.go | 0.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #3833 +/- ##
===========================================
+ Coverage 64.40% 65.05% +0.64%
===========================================
Files 465 465
Lines 33716 33698 -18
===========================================
+ Hits 21714 21921 +207
+ Misses 10993 10754 -239
- Partials 1009 1023 +14
| Files with missing lines | Coverage Δ | |
|---|---|---|
| precompiles/precompiles.go | 37.93% <ø> (+17.24%) |
:arrow_up: |
| precompiles/staking/method_stake.go | 81.35% <ø> (+81.35%) |
:arrow_up: |
| precompiles/staking/staking.go | 88.04% <ø> (+15.76%) |
:arrow_up: |
| precompiles/types/errors.go | 92.85% <100.00%> (ø) |
|
| precompiles/staking/method_get_rewards.go | 39.68% <0.00%> (ø) |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
!!!WARNING!!!
nosec detected in the following files: e2e/e2etests/e2etests.go
Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.
Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.
Pay extra attention to the way #nosec is being used in the files listed above.
Why only #3840 attached? Doesn't it enable all precompile? #3833
THe bank and staking are not enabled yet https://github.com/zeta-chain/zeta-node/blob/3abd15b57cff07b6b29294b164dc2cf335724289/precompiles/precompiles.go#L24-L28
Closing as no longer considered for now