-
Notifications
You must be signed in to change notification settings - Fork 908
feat(precompile): add gov precompile (vote only) #2858
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
Conversation
WalkthroughThe recent update introduces a governance precompile feature that facilitates voting transactions within the Evmos blockchain framework. This enhancement allows users to engage in governance activities through a precompiled contract, streamlining the voting process. Additional changes include the removal of automatic withdrawal of staking rewards, upgrades to the IBC-Go library, and modifications to account management types. The Cosmos-SDK version has also been updated. These changes collectively aim to improve the platform's usability and governance capabilities. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
… into GAtom22/gov-precompile
There was a problem hiding this 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
Outside diff range and nitpick comments (2)
precompiles/gov/gov_test.go (1)
41-138
: Excellent test coverage for the successful vote transaction scenario!The
TestRun
function thoroughly tests the execution of the precompile'sRun
method for a successful vote transaction. It sets up the necessary input data, constructs an Ethereum transaction, initializes the EVM context, and runs the precompile. The test verifies the expected outcomes, ensuring that successful executions return valid results.To further enhance the test coverage, consider adding a test case for failure scenarios, such as:
- Invalid input data
- Insufficient gas limit
- Unauthorized caller
This will help ensure that the precompile handles error cases gracefully and returns appropriate error messages.
app/app.go (1)
527-540
: Significant change:app.GovKeeper
added to static precompiles setupThe addition of
app.GovKeeper
as a parameter toevmkeeper.NewAvailableStaticPrecompiles
is a notable change that enhances the integration between the EVM and the governance module. This modification suggests that governance functionality is now included in the static precompiles setup, potentially enabling new governance-related capabilities within the EVM.Developers and users of the Evmos application should be aware of this change and consider its implications on their interactions with the governance system. It may now be possible to interact with governance proposals or execute governance-related actions through smart contracts, which could introduce new possibilities and considerations for governance participation.
Please ensure that the documentation and any relevant guides are updated to reflect this change and provide clarity on how it impacts the use of the governance system in conjunction with the EVM.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (17)
- CHANGELOG.md (1 hunks)
- app/app.go (1 hunks)
- precompiles/gov/IGov.sol (1 hunks)
- precompiles/gov/abi.json (1 hunks)
- precompiles/gov/errors.go (1 hunks)
- precompiles/gov/events.go (1 hunks)
- precompiles/gov/events_test.go (1 hunks)
- precompiles/gov/gov.go (1 hunks)
- precompiles/gov/gov_test.go (1 hunks)
- precompiles/gov/integration_test.go (1 hunks)
- precompiles/gov/setup_test.go (1 hunks)
- precompiles/gov/tx.go (1 hunks)
- precompiles/gov/tx_test.go (1 hunks)
- precompiles/gov/types.go (1 hunks)
- x/evm/keeper/static_precompiles.go (4 hunks)
- x/evm/types/params.go (1 hunks)
- x/evm/types/precompiles.go (2 hunks)
Additional comments not posted (31)
precompiles/gov/errors.go (1)
5-16
: LGTM!The error constants are well-defined, covering important scenarios related to governance operations. The error messages are clear, concise, and properly formatted using placeholders for dynamic values. Exporting these constants allows them to be used in other packages, promoting code reuse and maintainability.
x/evm/types/precompiles.go (2)
17-17
: LGTM!The addition of the
GovPrecompileAddress
constant is valid and follows the existing pattern for precompile addresses.
32-32
: Verify the precompile implementation.Adding the
GovPrecompileAddress
to theAvailableStaticPrecompiles
slice is necessary and done correctly. However, please ensure that the corresponding precompile implementation is provided and functions as intended.Run the following script to verify the precompile implementation:
Verification successful
Governance precompile implementation verified and approved.
The governance precompile is correctly implemented in
precompiles/gov/gov.go
. Key points:
- The
Precompile
struct implements thevm.PrecompiledContract
interface.- The
Run
method serves as the entry point for executing the precompile's functionality.- The
GovPrecompileAddress
is properly set in theNewPrecompile
function.- Currently supports the
VoteMethod
, with more methods planned for future PRs.The implementation follows the expected structure for a precompiled contract in the EVM, ensuring that the governance precompile will be recognized and accessible within the system as intended.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the governance precompile implementation. # Test: Search for the precompile implementation. Expect: The implementation to be found. rg --type go -A 10 $'func \(gp GovPrecompile\) Run'Length of output: 52
Script:
#!/bin/bash # Description: Search for governance precompile implementation # Search for any mentions of "GovPrecompile" echo "Searching for GovPrecompile mentions:" rg --type go "GovPrecompile" # Search for governance-related precompile implementations echo -e "\nSearching for governance-related precompile implementations:" rg --type go "func \(.*\) Run.*governance" # Search for files that might contain the precompile implementation echo -e "\nSearching for potential precompile implementation files:" fd -e go "(gov|governance).*precompile"Length of output: 783
Script:
#!/bin/bash # Description: Examine the contents of precompiles/gov/gov.go # Display the contents of precompiles/gov/gov.go echo "Contents of precompiles/gov/gov.go:" cat precompiles/gov/gov.go # Search for potential Run function or similar implementation echo -e "\nSearching for potential Run function or similar implementation:" rg --type go -A 10 "func \(.*\) (Run|Execute|Call)" precompiles/gov/gov.go # Search for struct definition that might implement the precompile echo -e "\nSearching for struct definition:" rg --type go "type.*struct" precompiles/gov/gov.goLength of output: 4913
precompiles/gov/events.go (1)
25-47
: LGTM!The
EmitVoteEvent
function correctly emits an event on a Vote transaction. The function prepares the event topics and data, and adds a log entry to the state database. The implementation is accurate and enhances the governance module by enabling the tracking of voting events.precompiles/gov/tx.go (1)
24-54
: Excellent implementation of the governance voting precompile!The
Vote
function is well-structured and effectively integrates Ethereum's capabilities with Cosmos SDK governance mechanisms. It correctly handles the construction of the vote message, performs the necessary checks on the caller's address, and utilizes the governance message server to process the vote.The inclusion of smart contracts in the voting process enhances the versatility and inclusivity of the governance system. The function also demonstrates best practices by appropriately handling errors and emitting events for transparency.
Overall, this implementation is a valuable addition to the Evmos blockchain's governance functionality.
precompiles/gov/abi.json (2)
6-30
: LGTM!The
Vote
event captures all the necessary information about a vote cast, including the voter's address, proposal ID, and the chosen option. The parameter types are appropriate for their intended use.
31-64
: LGTM!The
vote
function has a well-defined signature that captures all the necessary information for a voting operation. The use of an enum for theoption
parameter provides type safety and clarity. Themetadata
parameter allows flexibility for voters to provide additional context about their vote. The boolean return value provides a clear indication of the success or failure of the voting operation.precompiles/gov/types.go (3)
18-21
: LGTM!The
EventSetWithdrawAddress
struct is well-defined with appropriate field names and types to capture the event data for the SetWithdrawAddress transaction.
24-28
: LGTM!The
EventVote
struct is well-defined with appropriate field names and types to capture the event data for the Vote transaction.
31-64
: LGTM!The
NewMsgVote
function is well-implemented with proper validation checks on the input arguments. It creates a newMsgVote
instance only if all the required data is provided and is of the correct type. The function handles errors appropriately and returns theMsgVote
object, the voter's address, and anil
error upon successful validation.precompiles/gov/IGov.sol (5)
1-2
: LGTM!The SPDX license identifier and Solidity version pragma are correctly specified.
4-13
: LGTM!The constant
GOV_PRECOMPILE_ADDRESS
and the instanceGOV_CONTRACT
are correctly defined, allowing interaction with the governance precompile contract using theIGov
interface.
15-29
: LGTM!The enum
VoteOption
is well-defined with clear and self-explanatory voting options.
35-44
: LGTM!The event
Vote
is well-defined with relevant parameters, and thevoter
parameter is correctly marked asindexed
for efficient event filtering.
48-59
: LGTM!The function
vote
is well-defined with relevant parameters and is correctly marked asexternal
. Returning a boolean value to indicate the success of the vote is a good practice.precompiles/gov/setup_test.go (1)
1-76
: LGTM!The code segment introduces a well-structured test suite for the governance precompile functionality. It follows the standard practices for setting up a test suite using the
testify
package.The
PrecompileTestSuite
struct encapsulates the necessary components for testing, and theSetupTest
method initializes the test environment with a sample governance proposal and the precompile instance.The code segment does not contain any apparent issues with the logic or syntax. It provides a solid foundation for testing the governance precompile functionality.
precompiles/gov/events_test.go (1)
18-86
: Excellent test coverage for the voting event functionality!The
TestVoteEvent
function is a well-structured and comprehensive test suite for the voting event functionality of the governance precompile. It covers both the success and error scenarios, ensuring thorough testing of the voting mechanism.Some notable strengths of this test function include:
- Clear and readable structure with setup, execution, and verification phases.
- Table-driven test cases that allow for easy addition of new test cases and improve readability.
- Appropriate assertions to verify the expected behavior and event details.
- Use of constants for method names and event types, enhancing code maintainability.
- Utilization of helper functions for common tasks like unpacking event logs, promoting code reuse and reducing duplication.
Overall, this test function provides a solid foundation for ensuring the reliability of the voting event functionality and facilitates future additions and modifications.
precompiles/gov/tx_test.go (1)
18-129
: Excellent test coverage for theVote
method!The
TestVote
function provides a comprehensive set of test cases to validate the behavior of theVote
method in various scenarios. The test cases cover important aspects such as invalid input handling, address verification, and successful voting.Some key strengths of the test function:
- Well-structured and follows a clear pattern for defining and executing test cases.
- Each test case is properly named and includes setup (malleate), validation (postCheck), and expected error conditions.
- Uses the
testutil.NewPrecompileContract
helper function to set up the precompile contract for each test case.- Properly asserts the expected outcomes using the
s.Require()
assertions.The test function provides good coverage and helps ensure the correctness and robustness of the
Vote
method. Great job!precompiles/gov/gov_test.go (1)
16-39
: LGTM!The
TestIsTransaction
function is well-structured and covers the necessary test cases. It correctly verifies that theIsTransaction
method of the precompile identifies theVoteMethod
as a transaction and marks an invalid method as not a transaction.precompiles/gov/gov.go (1)
1-142
: LGTM! The code segment introduces a well-structured and modular precompiled contract for governance functionalities.The implementation follows best practices and effectively handles key aspects such as:
- Loading the ABI from an embedded JSON file for seamless interaction with the EVM.
- Initializing the precompile instance with necessary configurations like gas settings and approval expiration.
- Calculating the required gas for executing methods and handling insufficient input length scenarios.
- Orchestrating the execution of governance methods, managing gas consumption, and handling errors gracefully.
- Distinguishing between transaction and query methods, currently supporting the voting operation.
- Providing a precompile-specific logger for better traceability during execution.
The code segment is modular, with clear separation of concerns and responsibilities, making it maintainable and extensible.
precompiles/gov/integration_test.go (3)
86-100
: LGTM!The test case correctly checks the behavior when the provided gas limit is too low. It verifies that the precompile returns an out-of-gas error and ensures that the tally result remains unchanged.
102-111
: LGTM!The test case correctly checks the behavior when the origin address is different than the voter. It verifies that the precompile returns the expected error with the correct error message and addresses.
113-129
: LGTM!The test case correctly checks the behavior of a successful vote. It verifies that the precompile returns no error and emits the expected event. It also ensures that the tally result is updated correctly after the vote.
x/evm/keeper/static_precompiles.go (3)
14-14
: LGTM!The import statement for the
govkeeper
package is necessary and looks good.
20-20
: LGTM!The import statement for the
govprecompile
package is necessary and looks good.
46-46
: Excellent work!The changes to introduce the new governance precompile are implemented correctly:
- The
NewAvailableStaticPrecompiles
function is updated to accept thegovKeeper
parameter.- The
govPrecompile
instance is created using thegovKeeper
andauthzKeeper
.- Error handling is done appropriately by panicking with a descriptive error message if the precompile instantiation fails.
- The new
govPrecompile
is added to theprecompiles
map, making it available for use within the EVM.These changes expand the capabilities of the EVM by allowing governance-related operations to be executed through precompiles.
Also applies to: 93-97, 108-108
x/evm/types/params.go (1)
36-36
: Approve the addition of the governance precompile address.The code change looks good and adds the
GovPrecompileAddress
to the list of default active precompiles.However, it would be helpful to provide more context about the specific functionality and capabilities of the governance precompile.
- What are the key features and operations supported by the governance precompile?
- How does the introduction of this precompile enhance the overall governance capabilities of the Evmos platform?
- Are there any potential security or performance implications that need to be considered with the addition of this precompile?
Providing this additional information in the PR description or linked documentation would help reviewers better understand the impact and scope of this change.
CHANGELOG.md (4)
47-47
: LGTM!The addition of the governance precompile for voting transactions in the precompiles module looks good. It's appropriately categorized as a state machine breaking change.
Line range hint
1-46
: Looks good!The unreleased section of the changelog is well structured and documents the various changes across different modules appropriately. The categorization of the changes into improvements, state machine breaking changes, and bug fixes provides good clarity.
Tools
Markdownlint
44-44: Expected: 120; Actual: 136
Line length(MD013, line-length)
Line range hint
48-91
: Looks good!The changelog for the v19.2.0 release is well documented. The improvements and state machine breaking changes are clearly listed and categorized appropriately.
Tools
Markdownlint
44-44: Expected: 120; Actual: 136
Line length(MD013, line-length)
Line range hint
92-97
: Looks good!The changelog for the v19.1.0 release is well documented. The listed improvements are clear and concise.
Tools
Markdownlint
44-44: Expected: 120; Actual: 136
Line length(MD013, line-length)
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
… into GAtom22/gov-precompile
* feat(precompile): add gov precompile (vote only) * run make format * add changelog entry * fix linter * fix event parsing * minor fix * remove unused * feat: add votes query for a single proposal * feat: add single voter vote request * run make format * fix: remove comments * fix * apply review comments * refactor events * Update precompiles/gov/query.go Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * fix conflict * Apply suggestions from code review Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * small refactor * add invalid vote option test * run make format * add getVote in Run func * run make format * add comments * Update CHANGELOG.md Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * fix compilation * fix error * fix test * fix queries unit tests * add queries integration tests * fix changelog * Update CHANGELOG.md Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> --------- Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> Co-authored-by: GAtom22 <GAtom22@users.noreply.github.com> Co-authored-by: stepit <stefanofrancesco.pitton@gmail.com> Co-authored-by: Vlad <vladislav.varadinov@gmail.com> Co-authored-by: Vvaradinov <Vvaradinov@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> (cherry picked from commit 4c59847) # Conflicts: # CHANGELOG.md
) * feat(precompile): add gov precompile (vote only) (#2858) * feat(precompile): add gov precompile (vote only) * run make format * add changelog entry * fix linter * fix event parsing * minor fix * remove unused * feat: add votes query for a single proposal * feat: add single voter vote request * run make format * fix: remove comments * fix * apply review comments * refactor events * Update precompiles/gov/query.go Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * fix conflict * Apply suggestions from code review Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * small refactor * add invalid vote option test * run make format * add getVote in Run func * run make format * add comments * Update CHANGELOG.md Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> * fix compilation * fix error * fix test * fix queries unit tests * add queries integration tests * fix changelog * Update CHANGELOG.md Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> --------- Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com> Co-authored-by: GAtom22 <GAtom22@users.noreply.github.com> Co-authored-by: stepit <stefanofrancesco.pitton@gmail.com> Co-authored-by: Vlad <vladislav.varadinov@gmail.com> Co-authored-by: Vvaradinov <Vvaradinov@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> (cherry picked from commit 4c59847) # Conflicts: # CHANGELOG.md * fix chlog * fix chlog * fix chlog * add utils func used in gov tests --------- Co-authored-by: Tom <54514587+GAtom22@users.noreply.github.com> Co-authored-by: tom <tomasguerraalda@hotmail.com>
Description
Closes: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
Reviewers Checklist
All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.
I have...
Unreleased
section inCHANGELOG.md
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests