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

feat: add support stateful precompiles #66

Merged
merged 10 commits into from
Jul 23, 2024
Merged

Conversation

fbac
Copy link
Contributor

@fbac fbac commented Jul 18, 2024

Major changes

  • Add support for stateful precompiled contracts. This support comes from the cronos maintained ethermint changes:
(evm) https://github.com/crypto-org-chain/ethermint/pull/328 Support precompile interface.
(statedb) https://github.com/crypto-org-chain/ethermint/pull/333 Support native action in statedb, prepare for precompiles.
(precompile) https://github.com/crypto-org-chain/ethermint/pull/338 Fix simulation of precompile using context.
(precompile) https://github.com/crypto-org-chain/ethermint/pull/342 Problem: native action don't support mem keys
(precompile) https://github.com/crypto-org-chain/ethermint/pull/343 Problem: no api to convert native events to logs
(precompile) https://github.com/crypto-org-chain/ethermint/pull/344 Fix error handling in precompile context.
(precompile) https://github.com/crypto-org-chain/ethermint/pull/346 Add support for new precompile context.
(precompile) https://github.com/crypto-org-chain/ethermint/pull/347 Problem: miss contract in ExtStateDB interface
(precompile) https://github.com/crypto-org-chain/ethermint/pull/359 Problem: no efficient way to execute read-only native actions
(precompile) https://github.com/crypto-org-chain/ethermint/pull/371 Add StateDB itself into native context for precompiles to emit evm logs directly.
(precompile) https://github.com/crypto-org-chain/ethermint/pull/380 Allow init precompiled contract with rules when new evm.
(precompile) [#383](https://github.com/crypto-org-chain/ethermint/pull/383) Allow init precompiled contract with ctx.

Minor changes

Summary by CodeRabbit

  • New Features

    • Support for initializing precompiled contracts in the EVM module.
    • Introduced a CacheKVStore for faster read/write operations.
    • Added benchmarking utilities for performance testing in cachekv.
    • New methods for managing and tracing multiple stores in cachemulti.
    • Implemented transient storage functionality in the statedb package.
    • Streamlined maintainer information in the CODEOWNERS file.
    • Enhanced application store management with consolidated key mappings.
  • Refactor

    • Simplified and optimized EVM contract handling.
    • Improved transaction log parsing for better error handling.
    • Enhanced state management and event handling in the StateDB.
  • Documentation

    • Updated store/cachekv/README.md detailing CacheKVStore functionalities and performance improvements.
  • Tests

    • Added extensive tests for CacheKVStore operations and iterators.
    • Benchmarked various CacheKVStore scenarios to ensure robustness.
    • Introduced tests for managing multiple stores in cachemulti.

dongsam and others added 3 commits July 18, 2024 23:37
- (evm) crypto-org-chain#328 Support precompile interface.
- (statedb) crypto-org-chain#333 Support native action in statedb, prepare for precompiles.
- (precompile) crypto-org-chain#338 Fix simulation of precompile using context.
- (precompile) crypto-org-chain#342 Problem: native action don't support mem keys
- (precompile) crypto-org-chain#343 Problem: no api to convert native events to logs
- (precompile) crypto-org-chain#344 Fix error handling in precompile context.
- (precompile) crypto-org-chain#346 Add support for new precompile context.
- (precompile) crypto-org-chain#347 Problem: miss contract in ExtStateDB interface
- (precompile) crypto-org-chain#359 Problem: no efficient way to execute read-only native actions
- (precompile) crypto-org-chain#371 Add StateDB itself into native context for precompiles to emit evm logs directly.
- (precompile) crypto-org-chain#380 Allow init precompiled contract with rules when new evm.
* Problem: no access to ctx params in precompile

* Update CHANGELOG.md

Signed-off-by: mmsqe <[email protected]>

---------

Signed-off-by: mmsqe <[email protected]>
Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
@fbac fbac requested review from skosito and lumtis July 18, 2024 21:42
@github-actions github-actions bot added the C:CLI label Jul 18, 2024
Copy link

coderabbitai bot commented Jul 18, 2024

Walkthrough

The recent updates significantly enhance the evm module, introducing a precompile interface for initializing contracts with specified rules. Key improvements include a refactor for clarity, updates to the EVMKeeper interface, and optimizations to the CacheKVStore for improved performance. Additionally, the introduction of a B-tree structure and benchmarking functions further boosts efficiency, while dependency updates strengthen the project's foundation, resulting in a more robust and efficient codebase.

Changes

File/Path Change Summary
CHANGELOG.md Summarized all changes.
app/ante/* Refactored initialization in eth.go, updated EVMKeeper in interfaces.go, and simplified logic in app.go.
go.mod Updated dependencies, including tidwall/btree and zeta-chain/go-ethereum.
rpc/backend/utils.go Enhanced transaction log parsing and error handling.
store/cachekv/* Detailed cache management implemented, with benchmarks, helper functions, and tests for CacheKVStore and CacheStack, alongside a new BTree structure.
store/cachemulti/* Implemented and tested a Store struct for managing multiple branched stores.
x/evm/keeper/* Updated Keeper struct for custom contract handling and refined NewEVM function.
x/evm/statedb/* Enhanced StateDB with new methods for caching and executing native actions; updated mocks for testing.
.github/CODEOWNERS Streamlined maintainer list by removing comments and consolidating entries.

Assessment against linked issues

Objective Addressed Explanation
Support stateful precompiled contracts (#65)
Import upstream changes for contract support (#65)
Create a new version with the changes (#65) Unclear if versioning is explicitly addressed.

Poem

In code's vast and endless sea,
New features bloom for all to see,
Precompiled contracts set to fly,
With custom rules, they now comply.
B-trees stand tall in cache we trust,
Performance gained, as we adjust.
Here's to code that's swift and bright,
A coderabbit's pure delight!


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.

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.

store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
x/evm/statedb/transient_storage.go Dismissed Show dismissed Hide dismissed
x/evm/keeper/state_transition.go Fixed Show fixed Hide fixed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
app/app.go Dismissed Show dismissed Hide dismissed
app/app.go Fixed Show fixed Hide fixed
app/app.go Fixed Show fixed Hide fixed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
store/cachemulti/store.go Dismissed Show dismissed Hide dismissed
Copy link

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

Outside diff range, codebase verification and nitpick comments (3)
x/evm/statedb/native.go (1)

15-17: Consider adding a comment explaining the purpose of this method.

The Dirtied method returns a nil pointer. If this is a placeholder or a stub, it should be documented.

x/evm/types/tracer.go (1)

48-48: Function DefaultActivePrecompiles not found in the codebase.

The function DefaultActivePrecompiles used in x/evm/types/tracer.go on line 48 does not exist in the codebase. This indicates a potential issue with the usage of this function.

  • x/evm/types/tracer.go line 48: preCompiles := vm.DefaultActivePrecompiles(cfg.Rules(big.NewInt(height), cfg.MergeNetsplitBlock != nil))

Please verify the intended function and correct the usage accordingly.

Analysis chain

LGTM! Verify the correct usage of vm.DefaultActivePrecompiles.

The change to use vm.DefaultActivePrecompiles instead of vm.ActivePrecompiles appears to be correct.

However, ensure that vm.DefaultActivePrecompiles is the intended function and is correctly used throughout the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `vm.DefaultActivePrecompiles` in the codebase.

# Test: Search for the usage of `vm.DefaultActivePrecompiles`. Expect: Correct usage in relevant files.
rg --type go 'vm.DefaultActivePrecompiles'

Length of output: 171


Script:

#!/bin/bash
# Description: Verify the definition of `vm.DefaultActivePrecompiles` in the codebase.

# Test: Search for the definition of `vm.DefaultActivePrecompiles`. Expect: Correct definition and return value.
ast-grep --lang go --pattern 'func DefaultActivePrecompiles($_) $_' 

Length of output: 69


Script:

#!/bin/bash
# Description: Verify the definition of `vm.DefaultActivePrecompiles` in the codebase.

# Test: Search for the definition of `vm.DefaultActivePrecompiles`. Expect: Correct definition and return value.
rg --type go 'func DefaultActivePrecompiles'

Length of output: 46


Script:

#!/bin/bash
# Description: List all functions in the `vm` package to identify any similar or related functions to `DefaultActivePrecompiles`.

# Test: List all functions in the `vm` package. Expect: Identify any similar or related functions.
rg --type go --files-with-matches 'package vm' | xargs rg --type go 'func '

Length of output: 312617

store/cachekv/store_test.go (1)

38-38: Fix typo in comment.

The comment has a typo: "shoudn't" should be "shouldn't".

-  // update it in cache, shoudn't change mem
+  // update it in cache, shouldn't change mem
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 61d0400 and 42780b7.

Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • x/evm/migrations/v4/types/evm.pb.go is excluded by !**/*.pb.go
  • x/evm/migrations/v5/types/evm.pb.go is excluded by !**/*.pb.go
Files selected for processing (28)
  • CHANGELOG.md (2 hunks)
  • app/ante/eth.go (2 hunks)
  • app/ante/interfaces.go (2 hunks)
  • app/app.go (2 hunks)
  • go.mod (5 hunks)
  • rpc/backend/utils.go (1 hunks)
  • store/cachekv/README.md (1 hunks)
  • store/cachekv/bench_helper_test.go (1 hunks)
  • store/cachekv/benchmark_test.go (1 hunks)
  • store/cachekv/internal/btree.go (1 hunks)
  • store/cachekv/internal/btree_test.go (1 hunks)
  • store/cachekv/internal/memiterator.go (1 hunks)
  • store/cachekv/internal/mergeiterator.go (1 hunks)
  • store/cachekv/store.go (1 hunks)
  • store/cachekv/store_bench_test.go (1 hunks)
  • store/cachekv/store_test.go (1 hunks)
  • store/cachemulti/store.go (1 hunks)
  • store/cachemulti/store_test.go (1 hunks)
  • x/evm/keeper/keeper.go (5 hunks)
  • x/evm/keeper/state_transition.go (6 hunks)
  • x/evm/statedb/interfaces.go (1 hunks)
  • x/evm/statedb/mock_test.go (3 hunks)
  • x/evm/statedb/native.go (1 hunks)
  • x/evm/statedb/statedb.go (6 hunks)
  • x/evm/statedb/statedb_test.go (21 hunks)
  • x/evm/statedb/transient_storage.go (1 hunks)
  • x/evm/types/interfaces.go (1 hunks)
  • x/evm/types/tracer.go (1 hunks)
Additional context used
golangci-lint
x/evm/statedb/transient_storage.go

24-24: type transientStorage is unused

(unused)


27-27: func newTransientStorage is unused

(unused)


32-32: func transientStorage.Set is unused

(unused)


40-40: func transientStorage.Get is unused

(unused)


49-49: func transientStorage.Copy is unused

(unused)

x/evm/statedb/statedb.go

[warning] 93-93: unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _

(revive)


78-78: field transientStorage is unused

(unused)


84-84: field evmDenom is unused

(unused)


85-85: field err is unused

(unused)

GitHub Check: gosec
x/evm/statedb/transient_storage.go

[failure] 51-56: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

store/cachemulti/store.go

[failure] 128-130: the value in the range statement should be _ unless copying a map: want: for key := range m
the value in the range statement should be _ unless copying a map: want: for key := range m


[failure] 119-121: the value in the range statement should be _ unless copying a map: want: for key := range m
the value in the range statement should be _ unless copying a map: want: for key := range m


[failure] 64-66: the value in the range statement should be _ unless copying a map: want: for key := range m
the value in the range statement should be _ unless copying a map: want: for key := range m


[failure] 142-148: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 3


[failure] 45-54: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

x/evm/keeper/state_transition.go

[failure] 77-80: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

GitHub Check: Run golangci-lint
x/evm/statedb/transient_storage.go

[failure] 24-24:
type transientStorage is unused (unused)


[failure] 27-27:
func newTransientStorage is unused (unused)


[failure] 32-32:
func transientStorage.Set is unused (unused)


[failure] 40-40:
func transientStorage.Get is unused (unused)


[failure] 49-49:
func transientStorage.Copy is unused (unused)

x/evm/statedb/statedb.go

[warning] 93-93:
unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 78-78:
field transientStorage is unused (unused)


[failure] 84-84:
field evmDenom is unused (unused)


[failure] 85-85:
field err is unused (unused)

GitHub Check: CodeQL
store/cachemulti/store.go

[warning] 45-54: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 64-66: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 72-74: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 119-121: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 128-130: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 142-148: Iteration over map
Iteration over map may be a possible source of non-determinism

app/app.go

[warning] 465-467: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 468-470: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 471-473: Iteration over map
Iteration over map may be a possible source of non-determinism

LanguageTool
store/cachekv/README.md

[uncategorized] ~3-~3: You might be missing the article “a” here.
Context: ...tore specification A CacheKVStore is cache wrapper for a KVStore. It extends the...

(AI_EN_LECTOR_MISSING_DETERMINER_A)


[uncategorized] ~15-~15: Possible missing comma found.
Context: ...ould revisit these goals with time (for instance it's unclear that all disk writes need ...

(AI_HYDRA_LEO_MISSING_COMMA)


[style] ~15-~15: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...tance it's unclear that all disk writes need to be buffered to the end of the block), b...

(REP_NEED_TO_VB)


[grammar] ~34-~34: Probable usage error. Use “and” after ‘both’.
Context: ...ys that are cached from read operations as well as ‘dirty’ keys which map to a value that ...

(BOTH_AS_WELL_AS)


[style] ~34-~34: Did you mean ‘different from’? ‘Different than’ is often considered colloquial style.
Context: ...o a value that is potentially different than what is in the underlying KVStore. V...

(DIFFERENT_THAN)


[grammar] ~51-~51: The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard.
Context: ...be updated in the parent KVStore upon a write. Keys are mapped to an empty struct to ...

(A_INFINITIVE)


[style] ~93-~93: ‘taking into account’ might be wordy. Consider a shorter alternative.
Context: ...irs from the underlying KVStore while taking into account updated values from the cache. In the...

(EN_WORDINESS_PREMIUM_TAKING_INTO_ACCOUNT)


[locale-violation] ~134-~134: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...removing each key from unsortedCache. Afterwards, unsorted is sorted. Lastly, it itera...

(AFTERWARDS_US)


[grammar] ~140-~140: The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.
Context: ...et in unsortedCache. To avoid wasting the compute spent sorting, we should ensure that a ...

(A_INFINITIVE)


[uncategorized] ~140-~140: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ing, we should ensure that a reasonable amount of values are removed from `unsortedCac...

(AMOUNTOF_TO_NUMBEROF)


[grammar] ~140-~140: Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)
Context: ...sure that a reasonable amount of values are removed from unsortedCache. If the le...

(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)

Markdownlint
store/cachekv/README.md

10-10: Expected: 4; Actual: 2
Unordered list indentation

(MD007, ul-indent)


11-11: Expected: 4; Actual: 2
Unordered list indentation

(MD007, ul-indent)


73-73: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


79-79: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


85-85: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


93-93: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


132-132: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


136-136: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


138-138: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


140-140: null
Files should end with a single newline character

(MD047, single-trailing-newline)

Additional comments not posted (134)
x/evm/statedb/native.go (2)

10-13: LGTM!

The struct definition nativeChange looks good and is appropriate for its purpose.


19-21: LGTM! But verify the implementations of restoreNativeState and nativeEvents.

The Revert method appears to correctly revert the state changes. Ensure that restoreNativeState and nativeEvents are correctly implemented elsewhere.

Verification successful

Let's verify the implementation of the restoreNativeState function to ensure it is correctly defined and used.


Let's search for any function related to restoring the native state, including potential variations in naming.


LGTM! The Revert method is correctly implemented.

The restoreNativeState function and the nativeEvents field are correctly defined and used within the codebase.

  • restoreNativeState is implemented in x/evm/statedb/statedb.go.
  • nativeEvents is correctly managed throughout the codebase.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementations of `restoreNativeState` and `nativeEvents`.

# Test: Search for the implementations. Expect: Correct implementations of `restoreNativeState` and `nativeEvents`.
rg --type go 'func restoreNativeState' -A 10
rg --type go 'nativeEvents' -A 10

Length of output: 3162


Script:

#!/bin/bash
# Description: Verify the implementation of `restoreNativeState`.

# Test: Search for the implementation of `restoreNativeState`. Expect: Correct implementation of `restoreNativeState`.
rg --type go 'func restoreNativeState' -A 20

Length of output: 46


Script:

#!/bin/bash
# Description: Verify the implementation of `restoreNativeState` or similarly named functions.

# Test: Search for any function related to restoring the native state. Expect: Correct implementation of such a function.
rg --type go 'restore' -A 20

Length of output: 5537

store/cachemulti/store_test.go (1)

13-24: LGTM!

The test function TestStoreGetKVStore is well-written and covers the expected behavior.

store/cachekv/bench_helper_test.go (3)

5-8: LGTM!

The helper function randSlice correctly generates a random byte slice using the crypto/rand package.


11-19: LGTM!

The helper function incrementByteSlice correctly increments a byte slice as if it were a big-endian integer.


23-43: LGTM!

The helper functions generateSequentialKeys and generateRandomKeys correctly generate slices of sequential and random keys, respectively.

x/evm/statedb/interfaces.go (1)

27-29: LGTM!

The added methods StoreKeys and GetParams in the Keeper interface are essential and well-defined.

app/ante/interfaces.go (1)

45-45: Verify compatibility of NewEVM return type change.

The return type of the NewEVM method has been changed from evm.EVM to *vm.EVM. Ensure that all implementations and usages of this method are compatible with the new return type.

store/cachekv/internal/memiterator.go (8)

25-65: LGTM!

The newMemIterator method is correctly implemented and initializes the iterator based on the provided parameters.


67-69: LGTM!

The Domain method is correctly implemented and returns the expected values.


71-73: LGTM!

The Close method is correctly implemented and releases the iterator as expected.


76-80: LGTM!

The Error method is correctly implemented and returns the expected error.


83-85: LGTM!

The Valid method is correctly implemented and returns the expected validity.


87-99: LGTM!

The Next method is correctly implemented and advances the iterator as expected.


101-109: LGTM!

The keyInRange method is correctly implemented and performs the range check as expected.


119-123: LGTM!

The assertValid method is correctly implemented and performs the validity assertion as expected.

store/cachekv/internal/btree.go (10)

28-31: LGTM!

The NewBTree method is correctly implemented and initializes the BTree instance.


33-38: LGTM!

The init method is correctly implemented and sets up the BTree with the desired options.


40-45: LGTM!

The Set method is correctly implemented and inserts the key-value pair as expected.


47-56: LGTM!

The Get method is correctly implemented and retrieves the value as expected.


59-63: LGTM!

The Delete method is correctly implemented and deletes the key-value pair as expected.


66-70: LGTM!

The Iterator method is correctly implemented and creates the iterator as expected.


73-77: LGTM!

The ReverseIterator method is correctly implemented and creates the reverse iterator as expected.


80-91: LGTM!

The ScanDirtyItems method is correctly implemented and iterates over the dirty entries as expected.


94-103: LGTM!

The Copy method is correctly implemented and performs the copy operation as expected.


118-120: LGTM!

The newItem method is correctly implemented and creates the item as expected.

x/evm/types/interfaces.go (1)

52-53: LGTM! Verify the implementation of new methods.

The addition of IsSendEnabledCoins and BlockedAddr to the BankKeeper interface appears to be correct.

However, ensure that these methods are correctly implemented in the relevant structs.

x/evm/statedb/mock_test.go (6)

6-9: LGTM! New imports are necessary and correctly used.

The new imports for evmtypes and storetypes are necessary and correctly used in the file.


30-31: LGTM! New fields are correctly added to MockKeeper.

The new fields keys and eventConverters are correctly added to the MockKeeper struct.


34-39: LGTM! The NewMockKeeperWith function correctly initializes MockKeeper.

The NewMockKeeperWith function correctly initializes the MockKeeper struct with keys and eventConverters.


43-45: LGTM! The NewMockKeeper function correctly calls NewMockKeeperWith.

The NewMockKeeper function correctly initializes the MockKeeper struct by calling NewMockKeeperWith with nil parameters.


47-57: LGTM! New methods are correctly defined.

The new methods GetParams, StoreKeys, and EventConverters are correctly defined and consistent with the rest of the MockKeeper struct.


135-143: LGTM! The Clone method correctly clones MockKeeper.

The Clone method correctly clones the MockKeeper struct, including the new fields keys and eventConverters.

store/cachekv/benchmark_test.go (3)

1-61: LGTM! Benchmark tests are correctly defined.

The benchmark tests DoBenchmarkDeepCacheStack and specific depth benchmarks are correctly defined and cover the necessary cases.


63-70: LGTM! CacheStack struct is correctly defined.

The CacheStack struct is correctly defined and integrates well within the file.


72-133: LGTM! CacheStack methods are correctly defined.

The CacheStack methods CurrentStore, Reset, IsEmpty, Commit, CommitToRevision, Snapshot, and RevertToSnapshot are correctly defined and consistent with the rest of the struct.

store/cachekv/store_bench_test.go (5)

135-149: LGTM!

The wrapper functions for benchmark tests are correctly implemented.


17-43: Verify the existence and correctness of helper functions.

Ensure that the randSlice and generateSequentialKeys functions are defined and correctly implemented.

Verification successful

Helper functions are correctly implemented.

The randSlice and generateSequentialKeys functions are defined and correctly implemented in store/cachekv/bench_helper_test.go.

  • randSlice generates a random byte slice of a given size.
  • generateSequentialKeys generates a sequence of keys starting from a given key.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of helper functions.

# Test: Search for the function definitions. Expect: Definitions of `randSlice` and `generateSequentialKeys`.
rg --type go 'func randSlice|func generateSequentialKeys'

Length of output: 237


Script:

#!/bin/bash
# Extract the implementations of `randSlice` and `generateSequentialKeys` from `store/cachekv/bench_helper_test.go`.
rg --type go -A 10 'func randSlice' store/cachekv/bench_helper_test.go
rg --type go -A 20 'func generateSequentialKeys' store/cachekv/bench_helper_test.go

Length of output: 1003


46-64: Verify the existence and correctness of helper functions.

Ensure that the randSlice and generateSequentialKeys functions are defined and correctly implemented.

Verification successful

Verify the correctness of helper functions.

Ensure that the randSlice and generateSequentialKeys functions are correctly implemented.


Helper functions are correctly implemented.

The randSlice and generateSequentialKeys functions are correctly defined and implemented.

  • randSlice generates a random slice of bytes.
  • generateSequentialKeys produces sequential keys starting from a given key.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of helper functions.

# Test: Search for the function definitions. Expect: Definitions of `randSlice` and `generateSequentialKeys`.
rg --type go 'func randSlice|func generateSequentialKeys'

Length of output: 237


Script:

#!/bin/bash
# Description: Extract the implementations of `randSlice` and `generateSequentialKeys`.

# Extract the implementation of `randSlice`.
rg --type go --context 10 'func randSlice' store/cachekv/bench_helper_test.go

# Extract the implementation of `generateSequentialKeys`.
rg --type go --context 10 'func generateSequentialKeys' store/cachekv/bench_helper_test.go

Length of output: 954


98-133: Verify the existence and correctness of helper functions.

Ensure that the randSlice and generateSequentialKeys functions are defined and correctly implemented.

Verification successful

Review the implementations of helper functions.

The randSlice and generateSequentialKeys functions are defined in store/cachekv/bench_helper_test.go. Let's review their implementations to ensure correctness.


Verified: Helper functions are correctly implemented.

The randSlice and generateSequentialKeys functions are defined and correctly implemented in store/cachekv/bench_helper_test.go. They are suitable for their usage in the benchmark function.

  • randSlice generates a random byte slice of a specified size.
  • generateSequentialKeys generates a specified number of sequential byte slices starting from a given key.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of helper functions.

# Test: Search for the function definitions. Expect: Definitions of `randSlice` and `generateSequentialKeys`.
rg --type go 'func randSlice|func generateSequentialKeys'

Length of output: 237


Script:

#!/bin/bash
# Extract and review the implementations of randSlice and generateSequentialKeys.

# Extract the implementation of randSlice.
rg --type go -A 10 'func randSlice' store/cachekv/bench_helper_test.go

# Extract the implementation of generateSequentialKeys.
rg --type go -A 15 'func generateSequentialKeys' store/cachekv/bench_helper_test.go

Length of output: 882


68-92: Verify the existence and correctness of helper functions.

Ensure that the randSlice and generateRandomKeys functions are defined and correctly implemented.

Verification successful

Helper functions are correctly implemented.

The randSlice and generateRandomKeys functions are defined and correctly implemented in store/cachekv/bench_helper_test.go.

  • randSlice generates a random byte slice of a specified size.
  • generateRandomKeys creates a specified number of random keys using randSlice.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of helper functions.

# Test: Search for the function definitions. Expect: Definitions of `randSlice` and `generateRandomKeys`.
rg --type go 'func randSlice|func generateRandomKeys'

Length of output: 225


Script:

#!/bin/bash
# Description: Extract and review the implementations of `randSlice` and `generateRandomKeys`.

# Extract the implementation of `randSlice`.
rg --type go -A 10 'func randSlice' store/cachekv/bench_helper_test.go

# Extract the implementation of `generateRandomKeys`.
rg --type go -A 15 'func generateRandomKeys' store/cachekv/bench_helper_test.go

Length of output: 617

store/cachekv/store.go (14)

21-27: LGTM!

The NewStore method is correctly implemented.


29-32: LGTM!

The GetStoreType method is correctly implemented.


34-45: LGTM!

The Clone method is correctly implemented.


47-55: LGTM!

The swapCache method is correctly implemented.


57-65: LGTM!

The Restore method is correctly implemented.


93-97: LGTM!

The Has method is correctly implemented.


108-122: LGTM!

The Write method is correctly implemented.


124-127: LGTM!

The CacheWrap method is correctly implemented.


129-132: LGTM!

The CacheWrapWithTrace method is correctly implemented.


137-145: LGTM!

The Iterator and ReverseIterator methods are correctly implemented.


175-179: LGTM!

The setCacheValue method is correctly implemented.


99-106: LGTM! But verify the helper function.

The Delete method is correctly implemented.

Ensure that the types.AssertValidKey function is defined and correctly implemented.


82-91: LGTM! But verify the helper functions.

The Set method is correctly implemented.

Ensure that the types.AssertValidKey and types.AssertValidValue functions are defined and correctly implemented.


67-80: LGTM! But verify the helper function.

The Get method is correctly implemented.

Ensure that the types.AssertValidKey function is defined and correctly implemented.

store/cachekv/internal/btree_test.go (3)

11-45: LGTM!

The test function TestGetSetDelete is well-structured and covers various CRUD operations and edge cases for BTree.


47-187: LGTM!

The test function TestDBIterator is comprehensive and covers various iterator scenarios, including forward and reverse iterators and edge cases.


190-208: LGTM!

The helper function verifyIterator correctly verifies the iterator's output against the expected values.

rpc/backend/utils.go (1)

260-270: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to ParseTxLogsFromEvent match the new signature.

Verification successful

Function usage verified.

The function ParseTxLogsFromEvent is only used within the rpc/backend/utils.go file, and all instances match the new signature.

  • rpc/backend/utils.go: Lines 260-270
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `ParseTxLogsFromEvent` match the new signature.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go -A 5 $'ParseTxLogsFromEvent'

Length of output: 994


Script:

#!/bin/bash
# Description: Verify if there are any other occurrences of the function `ParseTxLogsFromEvent` in the entire codebase.

# Test: Search for the function usage in the entire codebase. Expect: Only occurrences of the new signature.
rg 'ParseTxLogsFromEvent'

Length of output: 313

store/cachekv/README.md (1)

51-51: Correct grammatical error.

Use "an" before "write".

- will need to be updated in the parent `KVStore` upon a write.
+ will need to be updated in the parent `KVStore` upon an update.

Likely invalid or redundant comment.

Tools
LanguageTool

[grammar] ~51-~51: The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard.
Context: ...be updated in the parent KVStore upon a write. Keys are mapped to an empty struct to ...

(A_INFINITIVE)

go.mod (3)

38-38: LGTM!

The new dependency github.com/tidwall/btree has been correctly added.


139-139: LGTM!

The indirect dependency github.com/holiman/uint256 has been correctly updated.


229-229: LGTM!

The replacement of github.com/ethereum/go-ethereum with github.com/zeta-chain/go-ethereum has been correctly implemented.

app/ante/eth.go (2)

253-253: LGTM! Simplified initialization.

The change simplifies the initialization of evmKeeper within the struct creation, improving readability.


308-308: LGTM! Improved readability.

The change from evm.Context().CanTransfer to evm.Context.CanTransfer streamlines the code and improves readability.

x/evm/keeper/keeper.go (5)

41-42: LGTM! Useful addition for custom precompiled contracts.

The CustomContractFn type facilitates the customization of precompiled contracts.


44-44: LGTM! Improves readability and modularity.

The EventConverter type alias improves code readability and modularity.


82-88: LGTM! Restructured for better support of custom contracts and store keys.

The changes to the Keeper struct support custom contract functions and store keys, improving flexibility and modularity.


102-104: LGTM! Updated function signature.

The changes to the NewKeeper function ensure that the new fields customContractFns and keys are properly initialized.


134-136: LGTM! Provides access to store keys.

The StoreKeys function improves access to store keys in the Keeper struct.

x/evm/keeper/state_transition.go (3)

19-21: LGTM! Necessary imports for new functionality.

The added imports for bytes and sort packages are necessary for the new functionality in the NewEVM function.


Line range hint 55-92: LGTM! Improved handling of precompiled contracts.

The changes to the NewEVM function, including the return type and additional contract handling and sorting logic, improve the handling of precompiled contracts.

Tools
GitHub Check: gosec

[failure] 77-80: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2


Line range hint 359-369: LGTM! Streamlined code.

The updates to the references from evm.Config() to evm.Config and from evm.Context().BlockNumber to evm.Context.BlockNumber streamline the code and improve readability.

x/evm/statedb/statedb.go (13)

30-31: LGTM! Necessary imports for new functionality.

The added imports for cachemulti and evmtypes packages are necessary for the new functionality in the StateDB struct.


34-34: LGTM! Improves readability and consistency.

The StateDBContextKey constant improves code readability and consistency.


36-36: LGTM! Improves readability and modularity.

The EventConverter type alias improves code readability and modularity.


Line range hint 54-85: LGTM! Enhanced functionality for state management and event handling.

The changes to the StateDB struct, including the new fields, enhance its functionality for state management and event handling.

Tools
golangci-lint

[warning] 93-93: unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _

(revive)


78-78: field transientStorage is unused

(unused)


84-84: field evmDenom is unused

(unused)


85-85: field err is unused

(unused)

GitHub Check: Run golangci-lint

[warning] 93-93:
unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 78-78:
field transientStorage is unused (unused)


[failure] 84-84:
field evmDenom is unused (unused)


[failure] 85-85:
field err is unused (unused)


93-107: LGTM! Proper initialization of new fields.

The changes to the NewWithParams function ensure proper initialization of the new fields in the StateDB struct.

Tools
golangci-lint

[warning] 93-93: unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _

(revive)

GitHub Check: Run golangci-lint

[warning] 93-93:
unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _ (revive)


109-111: LGTM! Provides access to native events.

The NativeEvents function improves access to native events in the StateDB struct.


113-117: LGTM! Necessary for managing native cache store.

The cacheMultiStore function is necessary for managing the native cache store in the StateDB struct.


338-340: LGTM! Improves state management and isolation.

The cloneNativeState function improves state management and isolation in the StateDB struct.


342-345: LGTM! Ensures proper state restoration.

The restoreNativeState function ensures proper state restoration in the StateDB struct.


347-364: LGTM! Improved handling of native actions and event emission.

The ExecuteNativeAction function improves the handling of native actions and event emission in the StateDB struct.


366-369: LGTM! Improved isolation and management of read-only native actions.

The CacheContext function improves the isolation and management of read-only native actions in the StateDB struct.


524-530: LGTM! Ensures proper state commitment and event emission.

The Commit function ensures proper state commitment and event emission in the StateDB struct.


557-579: LGTM! Improved handling of native events.

The emitNativeEvents function improves the handling of native events in the StateDB struct.

store/cachekv/store_test.go (9)

17-22: LGTM!

The newCacheKVStore function correctly sets up a two-layer cache store to emulate real-world scenarios.


70-76: LGTM!

The TestCacheKVStoreNoNilSet function correctly tests for panics when setting invalid keys or values.


78-105: LGTM!

The TestCacheKVStoreNested function correctly tests nested cache store scenarios and their interactions.


107-160: LGTM!

The TestCacheKVIteratorBounds function correctly tests various iterator bounds scenarios for the cache store.


162-217: LGTM!

The TestCacheKVReverseIteratorBounds function correctly tests various reverse iterator bounds scenarios for the cache store.


219-265: LGTM!

The TestCacheKVMergeIteratorBasics function correctly tests basic merge iterator functionality for the cache store.


267-291: LGTM!

The TestCacheKVMergeIteratorDeleteLast function correctly tests merge iterator functionality when deleting the last item.


293-325: LGTM!

The TestCacheKVMergeIteratorDeletes function correctly tests merge iterator functionality when deleting items.


327-356: LGTM!

The TestCacheKVMergeIteratorChunks function correctly tests merge iterator functionality with chunks of data.

x/evm/statedb/statedb_test.go (18)

Line range hint 55-135: LGTM!

The TestAccount function correctly tests various account-related scenarios in the state database.


Line range hint 141-150: LGTM!

The TestAccountOverride function correctly tests account override scenarios in the state database.


164-172: LGTM!

The TestDBError function correctly tests error scenarios in the state database.


180-210: LGTM!

The TestBalance function correctly tests various balance-related scenarios in the state database.


Line range hint 254-273: LGTM!

The TestState function correctly tests various state-related scenarios in the state database.


Line range hint 298-315: LGTM!

The TestCode function correctly tests various code-related scenarios in the state database.


Line range hint 368-399: LGTM!

The TestRevertSnapshot function correctly tests various snapshot revert scenarios in the state database.


Line range hint 409-421: LGTM!

The TestNestedSnapshot function correctly tests nested snapshot scenarios in the state database.


427-430: LGTM!

The TestInvalidSnapshotId function correctly tests invalid snapshot ID scenarios in the state database.


500-501: LGTM!

The TestAccessList function correctly tests various access list scenarios in the state database.


514-515: LGTM!

The TestLog function correctly tests various logging scenarios in the state database.


567-568: LGTM!

The TestRefund function correctly tests various refund scenarios in the state database.


Line range hint 586-602: LGTM!

The TestIterateStorage function correctly tests various storage iteration scenarios in the state database.


614-756: LGTM!

The TestNativeAction function correctly tests various native action execution scenarios in the state database.


Line range hint 757-764: LGTM!

The CollectContractStorage function correctly collects contract storage from the state database.


773-790: LGTM!

The cloneRawState function correctly clones the raw state from the multi-store.


792-833: LGTM!

The newTestKeeper function correctly sets up a new test keeper.


835-854: LGTM!

The setupTestEnv function correctly sets up the test environment.

app/app.go (2)

473-477: LGTM!

The EvmKeeper initialization correctly uses the combined keys map and all required parameters are passed.


Line range hint 478-481:
LGTM!

The IBC Keeper initialization and configuration are correct.

Tools
GitHub Check: CodeQL

[warning] 465-467: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 468-470: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 471-473: Iteration over map
Iteration over map may be a possible source of non-determinism

CHANGELOG.md (2)

40-42: LGTM!

The new feature entry for supporting the precompile interface in the evm module is clear and follows the specified format.


61-62: LGTM!

The new improvement entries for initializing precompiled contracts with rules and context in the precompile module are clear and follow the specified format.

store/cachemulti/store.go (7)

79-84: LGTM!

The function is correctly implemented.


86-100: LGTM!

The function is correctly implemented.


102-105: LGTM!

The function is correctly implemented.


166-173: LGTM!

The function is correctly implemented.


142-148: Optimize map iteration.

The map iteration can be optimized by using _ for the value when it is not needed.

-	for key, store := range cms.stores {
+	for key := range cms.stores {

Likely invalid or redundant comment.

Tools
GitHub Check: gosec

[failure] 142-148: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 3

GitHub Check: CodeQL

[warning] 142-148: Iteration over map
Iteration over map may be a possible source of non-determinism


45-54: Optimize map iteration.

The map iteration can be optimized by using _ for the value when it is not needed.

-	for key, store := range stores {
+	for key := range stores {

Likely invalid or redundant comment.

Tools
GitHub Check: gosec

[failure] 45-54: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

GitHub Check: CodeQL

[warning] 45-54: Iteration over map
Iteration over map may be a possible source of non-determinism


72-74: Optimize map iteration.

The map iteration can be optimized by using _ for the value when it is not needed.

-	for k, v := range cms.stores {
+	for k := range cms.stores {

Likely invalid or redundant comment.

Tools
GitHub Check: CodeQL

[warning] 72-74: Iteration over map
Iteration over map may be a possible source of non-determinism

store/cachekv/internal/mergeiterator.go (10)

27-36: LGTM!

The function is correctly implemented.


38-42: LGTM!

The function is correctly implemented.


44-47: LGTM!

The function is correctly implemented.


49-74: LGTM!

The function is correctly implemented.


76-104: LGTM!

The function is correctly implemented.


106-134: LGTM!

The function is correctly implemented.


136-144: LGTM!

The function is correctly implemented.


146-154: LGTM!

The function is correctly implemented.


156-162: LGTM!

The function is correctly implemented.


164-171: LGTM!

The function is correctly implemented.

app/app.go Show resolved Hide resolved
store/cachekv/README.md Outdated Show resolved Hide resolved
store/cachekv/README.md Outdated Show resolved Hide resolved
store/cachemulti/store.go Show resolved Hide resolved
store/cachemulti/store.go Show resolved Hide resolved
store/cachemulti/store.go Show resolved Hide resolved
Copy link

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

Outside diff range, codebase verification and nitpick comments (17)
x/evm/types/interfaces.go (1)

52-53: Missing Implementations for IsSendEnabledCoins and BlockedAddr Methods

The methods IsSendEnabledCoins and BlockedAddr are declared in the BankKeeper interface but do not have corresponding implementations in the codebase. This needs to be addressed to ensure the interface is fully functional.

  • IsSendEnabledCoins method is declared but not implemented.
  • BlockedAddr method is declared but not implemented.

Please implement these methods to align with the interface requirements.

Analysis chain

Verify the correctness of the new methods in BankKeeper.

Ensure that the new methods IsSendEnabledCoins and BlockedAddr are correctly defined and align with the existing interface methods.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the new methods in `BankKeeper`.

# Test: Search for the definition and usage of `IsSendEnabledCoins` and `BlockedAddr`. Expect: Ensure the methods are correctly defined and used.
rg --type go 'IsSendEnabledCoins|BlockedAddr'

Length of output: 389


Script:

#!/bin/bash
# Description: Verify the implementation and usage of the new methods in `BankKeeper`.

# Test: Search for the implementation of `IsSendEnabledCoins` and `BlockedAddr`.
rg --type go 'func (.*) IsSendEnabledCoins' -A 10
rg --type go 'func (.*) BlockedAddr' -A 10

# Test: Search for the usage of `IsSendEnabledCoins` and `BlockedAddr` in the codebase.
rg --type go 'IsSendEnabledCoins'
rg --type go 'BlockedAddr'

Length of output: 917


Script:

#!/bin/bash
# Description: Verify the implementation of the new methods in `BankKeeper`.

# Test: Search for the implementation of `IsSendEnabledCoins`.
rg --type go 'func (.*) IsSendEnabledCoins' -A 20

# Test: Search for the implementation of `BlockedAddr`.
rg --type go 'func (.*) BlockedAddr' -A 20

Length of output: 1028

store/cachekv/store.go (1)

147-170: Consider renaming isoSortedCache for better readability.

The variable name isoSortedCache could be improved for readability. Consider renaming it to something more descriptive, such as sortedCacheSnapshot.

- isoSortedCache := store.cache.Copy()
+ sortedCacheSnapshot := store.cache.Copy()
store/cachekv/README.md (12)

15-15: Consider rephrasing for variety.

The phrase "need to be buffered" is used multiple times. Consider rephrasing for variety.

- need to be buffered to the end of the block
+ need to be buffered until the end of the block
Tools
LanguageTool

[style] ~15-~15: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...tance it's unclear that all disk writes need to be buffered to the end of the block), b...

(REP_NEED_TO_VB)


34-34: Use "and" after "both".

The correct phrasing is "both keys and values".

- both keys that are cached from read operations as well as ‘dirty’ keys
+ both keys and values that are cached from read operations as well as ‘dirty’ keys
Tools
LanguageTool

[grammar] ~34-~34: Probable usage error. Use “and” after ‘both’.
Context: ...ys that are cached from read operations as well as ‘dirty’ keys which map to a value that ...

(BOTH_AS_WELL_AS)


[style] ~34-~34: Did you mean ‘different from’? ‘Different than’ is often considered colloquial style.
Context: ...o a value that is potentially different than what is in the underlying KVStore. V...

(DIFFERENT_THAN)


34-34: Consider using "different from".

The phrase "different than" is often considered colloquial. Consider using "different from".

- different than what is in the underlying `KVStore`
+ different from what is in the underlying `KVStore`
Tools
LanguageTool

[grammar] ~34-~34: Probable usage error. Use “and” after ‘both’.
Context: ...ys that are cached from read operations as well as ‘dirty’ keys which map to a value that ...

(BOTH_AS_WELL_AS)


[style] ~34-~34: Did you mean ‘different from’? ‘Different than’ is often considered colloquial style.
Context: ...o a value that is potentially different than what is in the underlying KVStore. V...

(DIFFERENT_THAN)


51-51: Check the usage of "write".

The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard.

- updated in the parent `KVStore` upon a write
+ updated in the parent `KVStore` upon writing
Tools
LanguageTool

[grammar] ~51-~51: The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard.
Context: ...be updated in the parent KVStore upon a write. Keys are mapped to an empty struct to ...

(A_INFINITIVE)


93-93: Consider a shorter alternative.

The phrase "taking into account" might be wordy. Consider a shorter alternative.

- while taking into account updated values from the cache
+ while considering updated values from the cache
Tools
LanguageTool

[style] ~93-~93: ‘taking into account’ might be wordy. Consider a shorter alternative.
Context: ...irs from the underlying KVStore while taking into account updated values from the cache. In the...

(EN_WORDINESS_PREMIUM_TAKING_INTO_ACCOUNT)

Markdownlint

93-93: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


134-134: Use "afterward" for American English.

In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.

- Afterwards, `unsorted` is sorted.
+ Afterward, `unsorted` is sorted.
Tools
LanguageTool

[locale-violation] ~134-~134: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...removing each key from unsortedCache. Afterwards, unsorted is sorted. Lastly, it itera...

(AFTERWARDS_US)


140-140: Check the usage of "compute".

The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.

- To avoid wasting the compute spent sorting
+ To avoid wasting the computation spent sorting
Tools
LanguageTool

[grammar] ~140-~140: The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.
Context: ...et in unsortedCache. To avoid wasting the compute spent sorting, we should ensure that a ...

(A_INFINITIVE)


[uncategorized] ~140-~140: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ing, we should ensure that a reasonable amount of values are removed from `unsortedCac...

(AMOUNTOF_TO_NUMBEROF)


[grammar] ~140-~140: Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)
Context: ...sure that a reasonable amount of values are removed from unsortedCache. If the le...

(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)

Markdownlint

140-140: null
Files should end with a single newline character

(MD047, single-trailing-newline)


140-140: Use "number of" for countable nouns.

‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.

- a reasonable amount of values
+ a reasonable number of values
Tools
LanguageTool

[grammar] ~140-~140: The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.
Context: ...et in unsortedCache. To avoid wasting the compute spent sorting, we should ensure that a ...

(A_INFINITIVE)


[uncategorized] ~140-~140: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ing, we should ensure that a reasonable amount of values are removed from `unsortedCac...

(AMOUNTOF_TO_NUMBEROF)


[grammar] ~140-~140: Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)
Context: ...sure that a reasonable amount of values are removed from unsortedCache. If the le...

(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)

Markdownlint

140-140: null
Files should end with a single newline character

(MD047, single-trailing-newline)


140-140: Possible verb agreement error.

Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)

- amount of values are removed
+ amount of values is removed
Tools
LanguageTool

[grammar] ~140-~140: The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.
Context: ...et in unsortedCache. To avoid wasting the compute spent sorting, we should ensure that a ...

(A_INFINITIVE)


[uncategorized] ~140-~140: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ing, we should ensure that a reasonable amount of values are removed from `unsortedCac...

(AMOUNTOF_TO_NUMBEROF)


[grammar] ~140-~140: Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)
Context: ...sure that a reasonable amount of values are removed from unsortedCache. If the le...

(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)

Markdownlint

140-140: null
Files should end with a single newline character

(MD047, single-trailing-newline)


10-10: Fix unordered list indentation.

The unordered list indentation is inconsistent. Expected: 4; Actual: 2

- * Buffer all writes to the parent store, so they can be dropped if they need to be reverted
- * Allow iteration over contiguous spans of keys
+    * Buffer all writes to the parent store, so they can be dropped if they need to be reverted
+    * Allow iteration over contiguous spans of keys

Also applies to: 11-11

Tools
Markdownlint

10-10: Expected: 4; Actual: 2
Unordered list indentation

(MD007, ul-indent)


73-73: Remove trailing spaces.

Trailing spaces are present. Expected: 0 or 2; Actual: 1

- New values are written by setting or updating the value of a key in `cache`. `Set` does not write to `parent`. 
+ New values are written by setting or updating the value of a key in `cache`. `Set` does not write to `parent`.

Also applies to: 79-79, 85-85, 93-93, 132-132, 136-136, 138-138

Tools
Markdownlint

73-73: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


140-140: Ensure file ends with a single newline character.

Files should end with a single newline character.

- This amortizes the cost of processing elements across multiple calls.
+ This amortizes the cost of processing elements across multiple calls.
+
Tools
LanguageTool

[grammar] ~140-~140: The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.
Context: ...et in unsortedCache. To avoid wasting the compute spent sorting, we should ensure that a ...

(A_INFINITIVE)


[uncategorized] ~140-~140: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ing, we should ensure that a reasonable amount of values are removed from `unsortedCac...

(AMOUNTOF_TO_NUMBEROF)


[grammar] ~140-~140: Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)
Context: ...sure that a reasonable amount of values are removed from unsortedCache. If the le...

(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)

Markdownlint

140-140: null
Files should end with a single newline character

(MD047, single-trailing-newline)

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

102-104: The customContractFns parameter is missing in evmkeeper.NewKeeper function calls.

The updated NewKeeper function signature includes the customContractFns parameter, which is not passed in the following instances:

  • x/evm/statedb/statedb_test.go
  • app/app.go

Please ensure that the customContractFns parameter is correctly passed in these function calls.

Analysis chain

LGTM! But verify the usage of NewKeeper function.

The update to the function signature is necessary and correctly implemented. Ensure that the function is correctly called with the new parameters.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewKeeper` function in the codebase.

# Test: Search for the usage of `NewKeeper`. Expect: Correct initialization and usage with new parameters.
rg --type go -A 5 $'NewKeeper'

Length of output: 6764


Script:

#!/bin/bash
# Description: Verify the usage of `evmkeeper.NewKeeper` function in the codebase with the updated parameters.

# Test: Search for the usage of `evmkeeper.NewKeeper` and extract sufficient context to verify parameter usage.
rg --type go -A 10 $'evmkeeper.NewKeeper'

Length of output: 1359


Script:

#!/bin/bash
# Description: Verify the usage of `customContractFns` parameter in `evmkeeper.NewKeeper` function.

# Test: Search for the `customContractFns` parameter in the context of `evmkeeper.NewKeeper` usage.
rg --type go -A 10 'customContractFns' | rg -B 10 'evmkeeper.NewKeeper'

Length of output: 69


Script:

#!/bin/bash
# Description: Extract the full function call of `evmkeeper.NewKeeper` in the identified files to verify the parameters.

# Test: Extract the full function call of `evmkeeper.NewKeeper` in `x/evm/statedb/statedb_test.go`.
rg --type go -A 10 -B 5 'evmkeeper.NewKeeper' x/evm/statedb/statedb_test.go

# Test: Extract the full function call of `evmkeeper.NewKeeper` in `app/app.go`.
rg --type go -A 10 -B 5 'evmkeeper.NewKeeper' app/app.go

Length of output: 1139

store/cachekv/store_test.go (1)

38-38: Fix the typo in the comment.

The comment on line 38 has a typo: "shoudn't" should be "shouldn't".

-  // update it in cache, shoudn't change mem
+  // update it in cache, shouldn't change mem
x/evm/statedb/statedb_test.go (1)

Line range hint 55-127:
Add comments to the test cases for clarity.

The test cases in the TestAccount function could benefit from additional comments to explain the purpose of each test case.

+  // Test case for non-existent account
   {"non-exist account", func(db *statedb.StateDB, cms sdk.MultiStore) {
      suite.Require().Equal(false, db.Exist(address))
      suite.Require().Equal(true, db.Empty(address))
      suite.Require().Equal(big.NewInt(0), db.GetBalance(address))
      suite.Require().Equal([]byte(nil), db.GetCode(address))
      suite.Require().Equal(common.Hash{}, db.GetCodeHash(address))
      suite.Require().Equal(uint64(0), db.GetNonce(address))
   }},
+  // Test case for empty account
   {"empty account", func(db *statedb.StateDB, cms sdk.MultiStore) {
      db.CreateAccount(address)
      suite.Require().NoError(db.Commit())

      ctx, keeper := newTestKeeper(suite.T(), cms)
      acct := keeper.GetAccount(ctx, address)
      suite.Require().Equal(statedb.NewEmptyAccount(), acct)
      suite.Require().False(acct.IsContract())

      db = statedb.New(ctx, keeper, txConfig)
      suite.Require().Equal(true, db.Exist(address))
      suite.Require().Equal(true, db.Empty(address))
      suite.Require().Equal(big.NewInt(0), db.GetBalance(address))
      suite.Require().Equal([]byte(nil), db.GetCode(address))
      suite.Require().Equal(common.BytesToHash(emptyCodeHash), db.GetCodeHash(address))
      suite.Require().Equal(uint64(0), db.GetNonce(address))
   }},
+  // Test case for account suicide
   {"suicide", func(db *statedb.StateDB, cms sdk.MultiStore) {
      // non-exist account.
      suite.Require().False(db.Suicide(address))
      suite.Require().False(db.HasSuicided(address))

      // create a contract account
      db.CreateAccount(address)
      db.SetCode(address, []byte("hello world"))
      db.AddBalance(address, big.NewInt(100))
      db.SetState(address, key1, value1)
      db.SetState(address, key2, value2)
      codeHash := db.GetCodeHash(address)
      suite.Require().NoError(db.Commit())

      ctx, keeper := newTestKeeper(suite.T(), cms)
      suite.Require().NotEmpty(keeper.GetCode(ctx, codeHash))

      // suicide
      db = statedb.New(ctx, keeper, txConfig)
      suite.Require().False(db.HasSuicided(address))
      suite.Require().True(db.Suicide(address))

      // check dirty state
      suite.Require().True(db.HasSuicided(address))
      // balance is cleared
      suite.Require().Equal(big.NewInt(0), db.GetBalance(address))
      // but code and state are still accessible in dirty state
      suite.Require().Equal(value1, db.GetState(address, key1))
      suite.Require().Equal([]byte("hello world"), db.GetCode(address))

      suite.Require().NoError(db.Commit())

      ctx, keeper = newTestKeeper(suite.T(), cms)
      // not accessible from StateDB anymore
      db = statedb.New(ctx, keeper, txConfig)
      suite.Require().False(db.Exist(address))

      // and cleared in keeper too
      suite.Require().Nil(keeper.GetAccount(ctx, address))
      // code is not deleted when contract suicided.
      suite.Require().NotEmpty(keeper.GetCode(ctx, codeHash))
   }},
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 61d0400 and 42780b7.

Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • x/evm/migrations/v4/types/evm.pb.go is excluded by !**/*.pb.go
  • x/evm/migrations/v5/types/evm.pb.go is excluded by !**/*.pb.go
Files selected for processing (28)
  • CHANGELOG.md (2 hunks)
  • app/ante/eth.go (2 hunks)
  • app/ante/interfaces.go (2 hunks)
  • app/app.go (2 hunks)
  • go.mod (5 hunks)
  • rpc/backend/utils.go (1 hunks)
  • store/cachekv/README.md (1 hunks)
  • store/cachekv/bench_helper_test.go (1 hunks)
  • store/cachekv/benchmark_test.go (1 hunks)
  • store/cachekv/internal/btree.go (1 hunks)
  • store/cachekv/internal/btree_test.go (1 hunks)
  • store/cachekv/internal/memiterator.go (1 hunks)
  • store/cachekv/internal/mergeiterator.go (1 hunks)
  • store/cachekv/store.go (1 hunks)
  • store/cachekv/store_bench_test.go (1 hunks)
  • store/cachekv/store_test.go (1 hunks)
  • store/cachemulti/store.go (1 hunks)
  • store/cachemulti/store_test.go (1 hunks)
  • x/evm/keeper/keeper.go (5 hunks)
  • x/evm/keeper/state_transition.go (6 hunks)
  • x/evm/statedb/interfaces.go (1 hunks)
  • x/evm/statedb/mock_test.go (3 hunks)
  • x/evm/statedb/native.go (1 hunks)
  • x/evm/statedb/statedb.go (6 hunks)
  • x/evm/statedb/statedb_test.go (21 hunks)
  • x/evm/statedb/transient_storage.go (1 hunks)
  • x/evm/types/interfaces.go (1 hunks)
  • x/evm/types/tracer.go (1 hunks)
Additional context used
golangci-lint
x/evm/statedb/transient_storage.go

24-24: type transientStorage is unused

(unused)


27-27: func newTransientStorage is unused

(unused)


32-32: func transientStorage.Set is unused

(unused)


40-40: func transientStorage.Get is unused

(unused)


49-49: func transientStorage.Copy is unused

(unused)

x/evm/statedb/statedb.go

[warning] 93-93: unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _

(revive)


78-78: field transientStorage is unused

(unused)


84-84: field evmDenom is unused

(unused)


85-85: field err is unused

(unused)

GitHub Check: gosec
x/evm/statedb/transient_storage.go

[failure] 51-56: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

store/cachemulti/store.go

[failure] 128-130: the value in the range statement should be _ unless copying a map: want: for key := range m
the value in the range statement should be _ unless copying a map: want: for key := range m


[failure] 119-121: the value in the range statement should be _ unless copying a map: want: for key := range m
the value in the range statement should be _ unless copying a map: want: for key := range m


[failure] 64-66: the value in the range statement should be _ unless copying a map: want: for key := range m
the value in the range statement should be _ unless copying a map: want: for key := range m


[failure] 142-148: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 3


[failure] 45-54: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

x/evm/keeper/state_transition.go

[failure] 77-80: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

GitHub Check: Run golangci-lint
x/evm/statedb/transient_storage.go

[failure] 24-24:
type transientStorage is unused (unused)


[failure] 27-27:
func newTransientStorage is unused (unused)


[failure] 32-32:
func transientStorage.Set is unused (unused)


[failure] 40-40:
func transientStorage.Get is unused (unused)


[failure] 49-49:
func transientStorage.Copy is unused (unused)

x/evm/statedb/statedb.go

[warning] 93-93:
unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 78-78:
field transientStorage is unused (unused)


[failure] 84-84:
field evmDenom is unused (unused)


[failure] 85-85:
field err is unused (unused)

GitHub Check: CodeQL
store/cachemulti/store.go

[warning] 45-54: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 64-66: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 72-74: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 119-121: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 128-130: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 142-148: Iteration over map
Iteration over map may be a possible source of non-determinism

app/app.go

[warning] 465-467: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 468-470: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 471-473: Iteration over map
Iteration over map may be a possible source of non-determinism

LanguageTool
store/cachekv/README.md

[style] ~15-~15: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...tance it's unclear that all disk writes need to be buffered to the end of the block), b...

(REP_NEED_TO_VB)


[grammar] ~34-~34: Probable usage error. Use “and” after ‘both’.
Context: ...ys that are cached from read operations as well as ‘dirty’ keys which map to a value that ...

(BOTH_AS_WELL_AS)


[style] ~34-~34: Did you mean ‘different from’? ‘Different than’ is often considered colloquial style.
Context: ...o a value that is potentially different than what is in the underlying KVStore. V...

(DIFFERENT_THAN)


[grammar] ~51-~51: The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard.
Context: ...be updated in the parent KVStore upon a write. Keys are mapped to an empty struct to ...

(A_INFINITIVE)


[style] ~93-~93: ‘taking into account’ might be wordy. Consider a shorter alternative.
Context: ...irs from the underlying KVStore while taking into account updated values from the cache. In the...

(EN_WORDINESS_PREMIUM_TAKING_INTO_ACCOUNT)


[locale-violation] ~134-~134: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...removing each key from unsortedCache. Afterwards, unsorted is sorted. Lastly, it itera...

(AFTERWARDS_US)


[grammar] ~140-~140: The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.
Context: ...et in unsortedCache. To avoid wasting the compute spent sorting, we should ensure that a ...

(A_INFINITIVE)


[uncategorized] ~140-~140: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ing, we should ensure that a reasonable amount of values are removed from `unsortedCac...

(AMOUNTOF_TO_NUMBEROF)


[grammar] ~140-~140: Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)
Context: ...sure that a reasonable amount of values are removed from unsortedCache. If the le...

(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)

Markdownlint
store/cachekv/README.md

10-10: Expected: 4; Actual: 2
Unordered list indentation

(MD007, ul-indent)


11-11: Expected: 4; Actual: 2
Unordered list indentation

(MD007, ul-indent)


73-73: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


79-79: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


85-85: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


93-93: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


132-132: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


136-136: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


138-138: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


140-140: null
Files should end with a single newline character

(MD047, single-trailing-newline)

Additional comments not posted (128)
x/evm/statedb/native.go (3)

10-13: LGTM!

The nativeChange struct is well-defined and appropriate for its intended functionality.


15-17: LGTM!

The Dirtied method is straightforward and correctly implemented.


19-21: LGTM!

The Revert method is correctly implemented and aligns with the intended functionality.

store/cachemulti/store_test.go (1)

13-24: LGTM!

The TestStoreGetKVStore function is well-defined and correctly tests the GetStore and GetKVStore methods.

store/cachekv/bench_helper_test.go (4)

5-8: LGTM!

The randSlice function correctly generates a random byte slice of the given size.


11-19: LGTM!

The incrementByteSlice function correctly implements the byte slice increment operation.


23-33: LGTM!

The generateSequentialKeys function correctly generates sequential keys starting from the given key.


37-43: LGTM!

The generateRandomKeys function correctly generates random, unsorted keys.

x/evm/statedb/interfaces.go (2)

19-22: LGTM!

The import statements are appropriate for the changes made in the file.


27-29: LGTM!

The StoreKeys and GetParams methods are well-defined and appropriate for the Keeper interface.

x/evm/statedb/transient_storage.go (4)

40-45: Flag unused method.

The Get method is currently unused. If this is intentional, consider adding a comment explaining why. Otherwise, ensure it is utilized within the codebase.

Tools
golangci-lint

40-40: func transientStorage.Get is unused

(unused)

GitHub Check: Run golangci-lint

[failure] 40-40:
func transientStorage.Get is unused (unused)


27-27: Flag unused function.

The newTransientStorage function is currently unused. If this is intentional, consider adding a comment explaining why. Otherwise, ensure it is utilized within the codebase.

Verification successful

Flag unused function.

The newTransientStorage function is currently unused. If this is intentional, consider adding a comment explaining why. Otherwise, ensure it is utilized within the codebase.

  • newTransientStorage function definition found in x/evm/statedb/transient_storage.go but no usage detected.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `newTransientStorage` is used in the codebase.

# Test: Search for the function usage. Expect: No occurrences or valid usage.
rg --type go -A 5 $'newTransientStorage'

Length of output: 583

Tools
golangci-lint

27-27: func newTransientStorage is unused

(unused)

GitHub Check: Run golangci-lint

[failure] 27-27:
func newTransientStorage is unused (unused)


24-24: Flag unused type.

The transientStorage type is currently unused. If this is intentional, consider adding a comment explaining why. Otherwise, ensure it is utilized within the codebase.

Tools
golangci-lint

24-24: type transientStorage is unused

(unused)

GitHub Check: Run golangci-lint

[failure] 24-24:
type transientStorage is unused (unused)


32-37: Flag unused method.

The Set method is currently unused. If this is intentional, consider adding a comment explaining why. Otherwise, ensure it is utilized within the codebase.

Verification successful

Flag unused method.

The Set method is currently unused. If this is intentional, consider adding a comment explaining why. Otherwise, ensure it is utilized within the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `Set` method is used in the codebase.

# Test: Search for the method usage. Expect: No occurrences or valid usage.
rg --type go -A 5 $'Set'

Length of output: 264646

Tools
golangci-lint

32-32: func transientStorage.Set is unused

(unused)

GitHub Check: Run golangci-lint

[failure] 32-32:
func transientStorage.Set is unused (unused)

app/ante/interfaces.go (1)

45-45: Verify method usage for NewEVM.

The NewEVM method now returns a pointer to vm.EVM. Ensure that all usages of this method are updated to handle the new return type.

store/cachekv/internal/memiterator.go (9)

25-65: LGTM!

The newMemIterator function is correctly implemented and follows best practices.


67-69: LGTM!

The Domain method is correctly implemented and follows best practices.


71-73: LGTM!

The Close method is correctly implemented and follows best practices.


76-80: LGTM!

The Error method is correctly implemented and follows best practices.


83-85: LGTM!

The Valid method is correctly implemented and follows best practices.


87-99: LGTM!

The Next method is correctly implemented and follows best practices.


101-109: LGTM!

The keyInRange method is correctly implemented and follows best practices.


111-113: LGTM!

The Key method is correctly implemented and follows best practices.


115-117: LGTM!

The Value method is correctly implemented and follows best practices.

store/cachekv/internal/btree.go (10)

28-31: LGTM!

The NewBTree function is correctly implemented and follows best practices.


33-38: LGTM!

The init method is correctly implemented and follows best practices.


40-45: LGTM!

The Set method is correctly implemented and follows best practices.


47-56: LGTM!

The Get method is correctly implemented and follows best practices.


59-63: LGTM!

The Delete method is correctly implemented and follows best practices.


66-70: LGTM!

The Iterator method is correctly implemented and follows best practices.


73-77: LGTM!

The ReverseIterator method is correctly implemented and follows best practices.


80-91: LGTM!

The ScanDirtyItems method is correctly implemented and follows best practices.


94-103: LGTM!

The Copy method is correctly implemented and follows best practices.


106-110: LGTM!

The item type is correctly defined and follows best practices.

x/evm/types/tracer.go (1)

48-48: Verify the correctness of using vm.DefaultActivePrecompiles.

Ensure that vm.DefaultActivePrecompiles is the intended replacement for vm.ActivePrecompiles and that it correctly initializes the preCompiles.

x/evm/statedb/mock_test.go (5)

30-31: Verify the correctness of the new fields in MockKeeper.

Ensure that the new fields keys and eventConverters are correctly added and do not introduce any issues.

Verification successful

Verify the correctness of the new fields in MockKeeper.

The fields keys and eventConverters are correctly added and utilized in the x/evm/statedb/mock_test.go file.

  • keys is used in the NewMockKeeperWith function and other places within the same file.
  • eventConverters is also used in the NewMockKeeperWith function and other places within the same file.

These additions appear to be correct and do not introduce any issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the new fields in `MockKeeper`.

# Test: Search for the definition and usage of `keys` and `eventConverters`. Expect: Ensure the fields are correctly added and used.
rg --type go 'keys|eventConverters'

Length of output: 14871


47-49: Verify the correctness of the new method GetParams.

Ensure that the new method GetParams is correctly defined and used.


135-143: Verify the correctness of the updated method Clone.

Ensure that the updated method Clone is correctly defined and used.


43-45: Verify the correctness of the refactored constructor NewMockKeeper.

Ensure that the refactored constructor NewMockKeeper is correctly defined and used.

Verification successful

The refactored constructor NewMockKeeper is correctly defined and used.

  • The NewMockKeeper function calls NewMockKeeperWith with nil arguments, which is handled correctly.
  • The NewMockKeeperWith function initializes the MockKeeper with default values when nil arguments are provided.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the refactored constructor `NewMockKeeper`.

# Test: Search for the definition and usage of `NewMockKeeper`. Expect: Ensure the constructor is correctly defined and used.
rg --type go 'NewMockKeeper'

Length of output: 305


Script:

#!/bin/bash
# Description: Verify the implementation of `NewMockKeeperWith` and the usage of `NewMockKeeper`.

# Search for the implementation of `NewMockKeeperWith`.
rg --type go 'func NewMockKeeperWith' -A 10

# Search for the usage of `NewMockKeeper`.
rg --type go 'NewMockKeeper\(\)'

Length of output: 828


34-39: Verify the correctness of the new constructor NewMockKeeperWith.

Ensure that the new constructor NewMockKeeperWith is correctly defined and used.

Verification successful

The constructor NewMockKeeperWith is correctly defined and used within mock_test.go.

However, there are no direct test functions in mock_test.go to validate its correctness. Ensure that this constructor is adequately tested in the future to avoid potential issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the new constructor `NewMockKeeperWith`.

# Test: Search for the definition and usage of `NewMockKeeperWith`. Expect: Ensure the constructor is correctly defined and used.
rg --type go 'NewMockKeeperWith'

Length of output: 247


Script:

#!/bin/bash
# Description: Verify the correctness of the new constructor `NewMockKeeperWith`.

# Test: Search for additional usages of `NewMockKeeperWith` across the entire codebase.
rg 'NewMockKeeperWith'

Length of output: 237


Script:

#!/bin/bash
# Description: Verify the test cases in `mock_test.go` to ensure they are correctly defined and executed.

# Test: Search for test functions in `mock_test.go`.
rg --type go 'func Test' x/evm/statedb/mock_test.go

Length of output: 53


Script:

#!/bin/bash
# Description: List all functions in `mock_test.go` to identify any custom test functions or other relevant code.

# List all functions in `mock_test.go`.
rg --type go --no-heading --line-number --column 'func ' x/evm/statedb/mock_test.go

Length of output: 1297


Script:

#!/bin/bash
# Description: Search for test functions across the entire codebase to ensure that the `NewMockKeeperWith` constructor is adequately tested.

# Search for test functions across the entire codebase.
rg --type go --no-heading --line-number --column 'func Test'

Length of output: 11777

store/cachekv/benchmark_test.go (6)

125-133: Verify the correctness of the method RevertToSnapshot.

Ensure that the method RevertToSnapshot is correctly defined and does not introduce any issues.


13-45: Verify the correctness of the benchmark test DoBenchmarkDeepCacheStack.

Ensure that the benchmark test DoBenchmarkDeepCacheStack is correctly defined and does not introduce any issues.

Verification successful

The benchmark test DoBenchmarkDeepCacheStack is correctly defined and used.

The CacheStack struct and its methods Reset, Snapshot, and CurrentStore are appropriately defined and utilized within the benchmark test. No issues were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the benchmark test `DoBenchmarkDeepCacheStack`.

# Test: Search for the definition and usage of `DoBenchmarkDeepCacheStack`. Expect: Ensure the benchmark test is correctly defined and used.
rg --type go 'DoBenchmarkDeepCacheStack'

Length of output: 392


Script:

#!/bin/bash
# Description: Verify the definition and usage of `CacheStack` and its methods `Reset`, `Snapshot`, and `CurrentStore`.

# Test: Search for the definition and usage of `CacheStack`.
rg --type go 'CacheStack'

# Test: Search for the definition and usage of `Reset` method.
rg --type go 'Reset'

# Test: Search for the definition and usage of `Snapshot` method.
rg --type go 'Snapshot'

# Test: Search for the definition and usage of `CurrentStore` method.
rg --type go 'CurrentStore'

Length of output: 16004


47-49: Verify the correctness of the benchmark test BenchmarkDeepCacheStack1.

Ensure that the benchmark test BenchmarkDeepCacheStack1 is correctly defined and does not introduce any issues.

Verification successful

Verify the correctness of the DoBenchmarkDeepCacheStack function used in BenchmarkDeepCacheStack1.

Ensure that the DoBenchmarkDeepCacheStack function is correctly defined and used.


Verify the implementation of the DoBenchmarkDeepCacheStack function.

Ensure that the DoBenchmarkDeepCacheStack function is correctly implemented and does not introduce any issues.


The benchmark test BenchmarkDeepCacheStack1 is correctly defined and does not introduce any issues.

  • The DoBenchmarkDeepCacheStack function is correctly implemented and used within BenchmarkDeepCacheStack1.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the benchmark test `BenchmarkDeepCacheStack1`.

# Test: Search for the definition and usage of `BenchmarkDeepCacheStack1`. Expect: Ensure the benchmark test is correctly defined and used.
rg --type go 'BenchmarkDeepCacheStack1'

Length of output: 275


Script:

#!/bin/bash
# Description: Verify the correctness of the `DoBenchmarkDeepCacheStack` function used in `BenchmarkDeepCacheStack1`.

# Test: Search for the definition and usage of `DoBenchmarkDeepCacheStack`. Expect: Ensure the function is correctly defined and used.
rg --type go 'DoBenchmarkDeepCacheStack'

Length of output: 392


Script:

#!/bin/bash
# Description: Verify the implementation of the `DoBenchmarkDeepCacheStack` function.

# Test: Retrieve the implementation of `DoBenchmarkDeepCacheStack`. Expect: Ensure the function is correctly implemented.
ast-grep --lang go --pattern 'func DoBenchmarkDeepCacheStack(b *testing.B, depth int) {
  $$$
}'

Length of output: 2065


55-57: Verify the correctness of the benchmark test BenchmarkDeepCacheStack10.

Ensure that the benchmark test BenchmarkDeepCacheStack10 is correctly defined and does not introduce any issues.

Verification successful

The benchmark test BenchmarkDeepCacheStack10 is correctly defined and does not introduce any issues.

  • The function DoBenchmarkDeepCacheStack is correctly implemented for benchmarking.
  • The function BenchmarkDeepCacheStack10 correctly calls DoBenchmarkDeepCacheStack with the appropriate depth.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the benchmark test `BenchmarkDeepCacheStack10`.

# Test: Search for the definition and usage of `BenchmarkDeepCacheStack10`. Expect: Ensure the benchmark test is correctly defined and used.
rg --type go 'BenchmarkDeepCacheStack10'

Length of output: 119


Script:

#!/bin/bash
# Description: Verify the implementation and usage of `DoBenchmarkDeepCacheStack`.

# Test: Search for the definition and usage of `DoBenchmarkDeepCacheStack`. Expect: Ensure the function is correctly defined and used.
rg --type go 'DoBenchmarkDeepCacheStack'

Length of output: 392


Script:

#!/bin/bash
# Description: Extract the implementation details of `DoBenchmarkDeepCacheStack`.

# Extract the implementation of `DoBenchmarkDeepCacheStack` from `store/cachekv/benchmark_test.go`.
rg --type go -A 20 'func DoBenchmarkDeepCacheStack' store/cachekv/benchmark_test.go

Length of output: 575


Script:

#!/bin/bash
# Description: Extract the complete implementation details of `DoBenchmarkDeepCacheStack`.

# Extract more lines from the implementation of `DoBenchmarkDeepCacheStack` from `store/cachekv/benchmark_test.go`.
rg --type go -A 40 'func DoBenchmarkDeepCacheStack' store/cachekv/benchmark_test.go

Length of output: 995


59-61: Verify the correctness of the benchmark test BenchmarkDeepCacheStack13.

Ensure that the benchmark test BenchmarkDeepCacheStack13 is correctly defined and does not introduce any issues.


51-53: Verify the correctness of the benchmark test BenchmarkDeepCacheStack3.

Ensure that the benchmark test BenchmarkDeepCacheStack3 is correctly defined and does not introduce any issues.

store/cachekv/store_bench_test.go (4)

46-64: Ensure the availability of randSlice and generateSequentialKeys functions.

The functions randSlice and generateSequentialKeys are used but not defined in this file. Ensure they are available in the codebase.


98-133: Ensure the availability of randSlice and generateSequentialKeys functions.

The functions randSlice and generateSequentialKeys are used but not defined in this file. Ensure they are available in the codebase.


17-43: Ensure the availability of randSlice and generateSequentialKeys functions.

The functions randSlice and generateSequentialKeys are used but not defined in this file. Ensure they are available in the codebase.

Verification successful

Verified: The functions randSlice and generateSequentialKeys are available in the codebase.

The functions randSlice and generateSequentialKeys are defined in store/cachekv/bench_helper_test.go.

  • randSlice: Defined at store/cachekv/bench_helper_test.go:1
  • generateSequentialKeys: Defined at store/cachekv/bench_helper_test.go:2
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the availability of `randSlice` and `generateSequentialKeys` functions.

# Test: Search for the function definitions. Expect: Definitions of `randSlice` and `generateSequentialKeys`.
rg --type go 'func randSlice|func generateSequentialKeys'

Length of output: 237


68-92: Ensure the availability of randSlice and generateRandomKeys functions.

The functions randSlice and generateRandomKeys are used but not defined in this file. Ensure they are available in the codebase.

Verification successful

The functions randSlice and generateRandomKeys are available in the codebase.

  • randSlice is defined in store/cachekv/bench_helper_test.go.
  • generateRandomKeys is defined in store/cachekv/bench_helper_test.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the availability of `randSlice` and `generateRandomKeys` functions.

# Test: Search for the function definitions. Expect: Definitions of `randSlice` and `generateRandomKeys`.
rg --type go 'func randSlice|func generateRandomKeys'

Length of output: 225

store/cachekv/store.go (12)

21-27: LGTM!

The NewStore function correctly initializes the Store object.


29-32: LGTM!

The GetStoreType function correctly returns the store type.


34-45: LGTM!

The Clone function correctly creates a snapshot of the cache store.


47-55: LGTM!

The swapCache function correctly swaps out the internal cache store.


57-65: LGTM!

The Restore function correctly restores the store cache to a given snapshot.


67-80: LGTM!

The Get function correctly retrieves the value from the store.


82-91: LGTM!

The Set function correctly sets the value in the store.


93-97: LGTM!

The Has function correctly checks the existence of the key in the store.


99-106: LGTM!

The Delete function correctly deletes the key from the store.


108-122: LGTM!

The Write function correctly writes the cache to the parent store.


124-127: LGTM!

The CacheWrap function correctly wraps the store in a cache.


129-132: LGTM!

The CacheWrapWithTrace function correctly wraps the store in a cache with tracing.

go.mod (3)

38-38: LGTM! Dependency addition approved.

The addition of github.com/tidwall/btree is necessary for the new BTree implementation.


139-139: LGTM! Dependency re-addition approved.

The re-addition of github.com/holiman/uint256 as an indirect dependency is acceptable.


229-229: LGTM! Dependency replacement approved.

The replacement of github.com/ethereum/go-ethereum with github.com/zeta-chain/go-ethereum v1.10.26-spc is necessary for the new stateful precompiles support.

app/ante/eth.go (2)

253-253: LGTM!

The initialization logic for NewCanTransferDecorator is straightforward and correct.


308-308: LGTM! But verify the usage of evm.Context.

The change improves readability by simplifying the method call. Ensure that evm.Context is correctly initialized and used.

x/evm/keeper/keeper.go (4)

41-42: LGTM!

The addition of CustomContractFn is straightforward and correct.


44-44: LGTM!

The addition of EventConverter is straightforward and correct.


82-88: LGTM!

The addition of customContractFns and keys fields in the Keeper struct is necessary for the new functionality and is correctly implemented.


134-136: LGTM!

The addition of the StoreKeys method is straightforward and correct.

x/evm/keeper/state_transition.go (5)

19-21: LGTM!

The addition of bytes and sort imports is necessary and correct.


55-55: LGTM!

The modification to use a pointer type for evm.EVM is necessary and correct.


359-359: LGTM!

The update to references from evm.Config() to evm.Config simplifies the code and improves readability.


369-369: LGTM!

The update to references from evm.Context().BlockNumber to evm.Context.BlockNumber simplifies the code and improves readability.


74-92: LGTM! But verify the functionality of NewEVM function.

The update to the NewEVM function improves the handling of custom precompiled contracts and ensures that active contracts are sorted. Ensure that the logic is correctly implemented and does not introduce any issues.

Tools
GitHub Check: gosec

[failure] 77-80: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

x/evm/statedb/statedb.go (8)

30-31: LGTM!

The addition of cachemulti and evmtypes imports is necessary and correct.


34-34: LGTM!

The addition of StateDBContextKey constant is necessary and correct.


36-36: LGTM!

The addition of EventConverter is straightforward and correct.


Line range hint 54-85: LGTM!

The modifications and additions to the StateDB struct are necessary and correctly implemented.

Tools
golangci-lint

[warning] 93-93: unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _

(revive)


78-78: field transientStorage is unused

(unused)


84-84: field evmDenom is unused

(unused)


85-85: field err is unused

(unused)

GitHub Check: Run golangci-lint

[warning] 93-93:
unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _ (revive)


[failure] 78-78:
field transientStorage is unused (unused)


[failure] 84-84:
field evmDenom is unused (unused)


[failure] 85-85:
field err is unused (unused)


Line range hint 109-369: LGTM!

The addition of new methods in the StateDB struct is necessary and correctly implemented.


524-530: LGTM!

The modifications to the Commit method are necessary and correctly implemented.


557-579: LGTM!

The addition of emitNativeEvents method is necessary and correctly implemented.


90-107: LGTM! But verify the usage of NewWithParams function.

The refactoring of the New function to NewWithParams is necessary and correctly implemented. Ensure that the function is correctly called with the new argument.

Verification successful

Verified: The NewWithParams function is correctly refactored and used within the codebase.

The function NewWithParams is only used within x/evm/statedb/statedb.go, ensuring that the refactoring does not impact other parts of the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewWithParams` function in the codebase.

# Test: Search for the usage of `NewWithParams`. Expect: Correct initialization and usage with new argument.
rg --type go -A 5 $'NewWithParams'

Length of output: 593


Script:

#!/bin/bash
# Description: Verify the usage of `NewWithParams` function across the entire codebase.

# Test: Search for the usage of `NewWithParams`. Expect: Correct initialization and usage with new argument.
rg --type go 'NewWithParams'

Length of output: 251

Tools
golangci-lint

[warning] 93-93: unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _

(revive)

GitHub Check: Run golangci-lint

[warning] 93-93:
unused-parameter: parameter 'params' seems to be unused, consider removing or renaming it as _ (revive)

store/cachekv/store_test.go (20)

17-22: LGTM!

The newCacheKVStore function correctly initializes a two-layer cache store.


24-25: LGTM!

The keyFmt and valFmt functions correctly format keys and values as byte slices.


70-75: LGTM!

The TestCacheKVStoreNoNilSet function correctly tests that setting nil values panics.


78-105: LGTM!

The TestCacheKVStoreNested function correctly tests nested cache store operations and their effects.


162-217: LGTM!

The TestCacheKVReverseIteratorBounds function correctly tests reverse iterator bounds in the CacheKVStore.


219-265: LGTM!

The TestCacheKVMergeIteratorBasics function correctly tests basic merge iterator operations in the CacheKVStore.


267-291: LGTM!

The TestCacheKVMergeIteratorDeleteLast function correctly tests deleting the last item in the CacheKVStore.


293-325: LGTM!

The TestCacheKVMergeIteratorDeletes function correctly tests deleting items in the CacheKVStore.


327-356: LGTM!

The TestCacheKVMergeIteratorChunks function correctly tests merge iterator operations in chunks.


358-375: LGTM!

The TestCacheKVMergeIteratorDomain function correctly tests the domain of merge iterators.


377-390: LGTM!

The TestCacheKVMergeIteratorRandom function correctly tests random operations on merge iterators.


392-435: LGTM!

The TestNilEndIterator function correctly tests iterators with nil end bounds.


437-451: LGTM!

The TestIteratorDeadlock function correctly tests for deadlock issues in iterators.


471-494: LGTM!

The doOp function correctly performs random operations on the CacheKVStore.


496-519: LGTM!

The doRandomOp function correctly performs random operations on the CacheKVStore.


524-536: LGTM!

The assertIterateDomain function correctly asserts the iteration over the whole domain.


538-569: LGTM!

The assertIterateDomainCheck function correctly checks the iteration over the domain against a ground truth.


571-580: LGTM!

The assertIterateDomainCompare function correctly compares the iteration over the domain against a ground truth.


582-593: LGTM!

The checkIterators function correctly checks the equality of two iterators.


128-135: Verify the iteration over none scenario.

Ensure that the iteration over none scenario correctly handles cases where no keys are present.

Verification successful

The iteration over none scenario is correctly handled in the TestCacheKVIteratorBounds function.

The test ensures that when no keys are present, the iterator does not find any keys and the iteration count is zero, with no errors occurring when closing the iterator.

  • Lines: 128-135 in store/cachekv/store_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the iteration over none scenario in `TestCacheKVIteratorBounds`.

# Test: Search for the function usage. Expect: Correct handling of no keys.
rg --type go -A 5 $'TestCacheKVIteratorBounds'

Length of output: 349


Script:

#!/bin/bash
# Extract the complete implementation of the `TestCacheKVIteratorBounds` function from `store/cachekv/store_test.go`.
ast-grep --lang go --pattern $'func TestCacheKVIteratorBounds($_) {
  $$$
}' --after 100

Length of output: 8684

x/evm/statedb/statedb_test.go (1)

Line range hint 141-151:
LGTM!

The TestAccountOverride function correctly tests the balance carryover and nonce reset when an account is overwritten.

app/app.go (4)

477-477: Verify the correctness of allKeys initialization.

Ensure that the allKeys map contains all expected keys from keys, tkeys, and memKeys before initializing the EvmKeeper.


465-467: Duplicate Comment: Potential non-determinism in map iteration.

Iteration over maps may lead to non-deterministic order, which can be problematic in consensus-critical code. Consider sorting the keys before iteration to ensure deterministic behavior.

Tools
GitHub Check: CodeQL

[warning] 465-467: Iteration over map
Iteration over map may be a possible source of non-determinism


468-470: Duplicate Comment: Potential non-determinism in map iteration.

Iteration over maps may lead to non-deterministic order, which can be problematic in consensus-critical code. Consider sorting the keys before iteration to ensure deterministic behavior.

Tools
GitHub Check: CodeQL

[warning] 468-470: Iteration over map
Iteration over map may be a possible source of non-determinism


471-473: Duplicate Comment: Potential non-determinism in map iteration.

Iteration over maps may lead to non-deterministic order, which can be problematic in consensus-critical code. Consider sorting the keys before iteration to ensure deterministic behavior.

Tools
GitHub Check: CodeQL

[warning] 471-473: Iteration over map
Iteration over map may be a possible source of non-determinism

CHANGELOG.md (2)

40-43: LGTM!

The new feature entry for supporting the precompile interface in the evm module is clear and aligns with the PR objectives.


61-62: LGTM!

The improvement entries for allowing the initialization of precompiled contracts with rules and context are clear and align with the PR objectives.

store/cachemulti/store.go (10)

79-84: LGTM!

The method is straightforward and correctly sets the tracer for the MultiStore.


102-105: LGTM!

The method is straightforward and correctly returns whether tracing is enabled for the MultiStore.


107-110: LGTM!

The method correctly panics as this functionality is not supported for a cached multi-store.


112-115: LGTM!

The method is straightforward and correctly returns the type of the store.


151-154: LGTM!

The method is straightforward and correctly implements CacheWrapper.


156-159: LGTM!

The method is straightforward and correctly implements CacheWrapper with tracing.


161-164: LGTM!

The method is straightforward and correctly implements MultiStore.


166-173: LGTM!

The method correctly panics as this functionality is not supported for a cached multi-store.


175-182: LGTM!

The method is straightforward and correctly returns an underlying Store by key.


184-191: LGTM!

The method is straightforward and correctly returns an underlying KVStore by key.

store/cachekv/internal/mergeiterator.go (7)

27-36: LGTM!

The method is straightforward and correctly creates a new cacheMergeIterator object.


38-42: LGTM!

The method is straightforward and correctly returns the domain of the parent iterator.


44-47: LGTM!

The method is straightforward and correctly returns whether the iterator is valid.


136-144: LGTM!

The method is straightforward and correctly closes the iterator.


146-154: LGTM!

The method is straightforward and correctly returns an error if the iterator is invalid.


156-162: LGTM!

The method is straightforward and correctly asserts that the iterator is valid.


164-171: LGTM!

The method is straightforward and correctly compares two byte

app/app.go Show resolved Hide resolved
store/cachekv/internal/btree_test.go Show resolved Hide resolved
store/cachekv/internal/btree_test.go Show resolved Hide resolved
rpc/backend/utils.go Show resolved Hide resolved
x/evm/statedb/transient_storage.go Outdated Show resolved Hide resolved
store/cachemulti/store.go Show resolved Hide resolved
store/cachemulti/store.go Show resolved Hide resolved
store/cachekv/internal/mergeiterator.go Show resolved Hide resolved
store/cachekv/internal/mergeiterator.go Show resolved Hide resolved
store/cachekv/internal/mergeiterator.go Show resolved Hide resolved
Francisco de Borja Aranda Castillejo added 2 commits July 19, 2024 11:32
Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 42780b7 and 9d3f3e2.

Files selected for processing (3)
  • store/cachekv/README.md (1 hunks)
  • x/evm/statedb/statedb.go (6 hunks)
  • x/evm/statedb/transient_storage.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/evm/statedb/statedb.go
Additional context used
GitHub Check: gosec
x/evm/statedb/transient_storage.go

[failure] 56-61: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

LanguageTool
store/cachekv/README.md

[style] ~15-~15: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...tance it's unclear that all disk writes need to be buffered to the end of the block), b...

(REP_NEED_TO_VB)


[grammar] ~34-~34: Probable usage error. Use “and” after ‘both’.
Context: ...ys that are cached from read operations as well as ‘dirty’ keys which map to a value that ...

(BOTH_AS_WELL_AS)


[style] ~34-~34: Did you mean ‘different from’? ‘Different than’ is often considered colloquial style.
Context: ...o a value that is potentially different than what is in the underlying KVStore. V...

(DIFFERENT_THAN)


[grammar] ~51-~51: The verb ‘write’ does not usually follow articles like ‘a’. Check that ‘write’ is spelled correctly; using ‘write’ as a noun may be non-standard.
Context: ...be updated in the parent KVStore upon a write. Keys are mapped to an empty struct to ...

(A_INFINITIVE)


[style] ~93-~93: ‘taking into account’ might be wordy. Consider a shorter alternative.
Context: ...irs from the underlying KVStore while taking into account updated values from the cache. In the ...

(EN_WORDINESS_PREMIUM_TAKING_INTO_ACCOUNT)


[locale-violation] ~134-~134: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...removing each key from unsortedCache. Afterwards, unsorted is sorted. Lastly, it itera...

(AFTERWARDS_US)


[grammar] ~140-~140: The verb ‘compute’ does not usually follow articles like ‘the’. Check that ‘compute’ is spelled correctly; using ‘compute’ as a noun may be non-standard.
Context: ...et in unsortedCache. To avoid wasting the compute spent sorting, we should ensure that a ...

(A_INFINITIVE)


[uncategorized] ~140-~140: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ing, we should ensure that a reasonable amount of values are removed from `unsortedCac...

(AMOUNTOF_TO_NUMBEROF)


[grammar] ~140-~140: Possible verb agreement error. Did you mean “is”? (Some collective nouns can be treated as both singular and plural, so ‘are’ is not always incorrect.)
Context: ...sure that a reasonable amount of values are removed from unsortedCache. If the le...

(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)

x/evm/statedb/transient_storage.go Show resolved Hide resolved
x/evm/statedb/transient_storage.go Show resolved Hide resolved
x/evm/statedb/transient_storage.go Show resolved Hide resolved
x/evm/statedb/transient_storage.go Show resolved Hide resolved
x/evm/statedb/transient_storage.go Show resolved Hide resolved
store/cachekv/README.md Show resolved Hide resolved
store/cachekv/README.md Show resolved Hide resolved
store/cachekv/README.md Show resolved Hide resolved
store/cachekv/README.md Show resolved Hide resolved
store/cachekv/README.md Show resolved Hide resolved
@fbac
Copy link
Contributor Author

fbac commented Jul 19, 2024

  • Integration tests are failing due to nix being misconfigured on this fork.
  • Dependency review is failing due to vulncheck, this is the summary which should be ok:
Your code is affected by 8 vulnerabilities from 6 modules.
This scan also found 0 vulnerabilities in packages you import and 3
vulnerabilities in modules you require, but your code doesn't appear to call
these vulnerabilities.

Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9d3f3e2 and 4d0c720.

Files selected for processing (1)
  • .github/CODEOWNERS (1 hunks)
Files skipped from review due to trivial changes (1)
  • .github/CODEOWNERS

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

Uses zeta-chain/[email protected] which enables stateful precompiles.

Could we create a branch release/v.x and make a PR to this branch for these changes? We don't need to merge it immediately and can instead use commit as a tag in this repo, just so we have every changes made tracked through PRs

chore: adapted CODEOWNERS to protocol groups @ ZETA

Sounds good. In this case it is fine but in general it's a best practice to create a new PR for any independent changes even if it's just one line change

go.mod Outdated Show resolved Hide resolved
store/cachekv/README.md Show resolved Hide resolved
x/evm/keeper/keeper.go Show resolved Hide resolved
x/evm/keeper/state_transition.go Outdated Show resolved Hide resolved
Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

i think it would be nice to add more context to PR description, would make review easier

CHANGELOG.md Show resolved Hide resolved
app/ante/eth.go Show resolved Hide resolved
Co-authored-by: Lucas Bertrand <[email protected]>
Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4d0c720 and 7b0656a.

Files selected for processing (1)
  • go.mod (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • go.mod

Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
x/evm/keeper/state_transition.go Dismissed Show resolved Hide resolved
@fbac fbac requested review from gartnera, skosito and lumtis July 22, 2024 14:24
Copy link

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

Outside diff range, codebase verification and nitpick comments (1)
x/evm/keeper/state_transition.go (1)

Line range hint 55-108:
LGTM! But address the static analysis hint.

The changes to the NewEVM function are approved.

However, the static analysis tool suggests using _ for the value in the range statement unless copying a map. Consider updating the loop to:

for addr := range vm.DefaultPrecompiles(rules) {
	contracts[addr] = vm.DefaultPrecompiles(rules)[addr]
	active = append(active, addr)
}
- for addr, c := range vm.DefaultPrecompiles(rules) {
- 	contracts[addr] = c
- 	active = append(active, addr)
- }
+ for addr := range vm.DefaultPrecompiles(rules) {
+ 	contracts[addr] = vm.DefaultPrecompiles(rules)[addr]
+ 	active = append(active, addr)
+ }
Tools
GitHub Check: gosec

[failure] 82-85: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7b0656a and a5a3c14.

Files selected for processing (3)
  • x/evm/keeper/keeper.go (5 hunks)
  • x/evm/keeper/state_transition.go (6 hunks)
  • x/evm/statedb/statedb.go (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/evm/statedb/statedb.go
Additional context used
GitHub Check: gosec
x/evm/keeper/state_transition.go

[failure] 82-85: the value in the range statement should be _ unless copying a map: want: for key := range m
expected exactly 1 statement (either append, delete, or copying to another map) in a range with a map, got 2

Additional comments not posted (2)
x/evm/keeper/keeper.go (2)

137-139: LGTM!

The StoreKeys function is a simple getter for the keys field and is correctly implemented.


105-107: LGTM! But verify the usage of new fields.

The changes to the NewKeeper function signature are approved.

However, ensure that the new fields customContractFns and keys are correctly used in the codebase.

Verification successful

The new fields customContractFns and keys are correctly used.

The changes to the NewKeeper function signature and the addition of the new fields are correctly implemented and utilized in the codebase.

  • customContractFns is used in x/evm/keeper/state_transition.go.
  • keys is used in x/evm/keeper/keeper.go and x/evm/statedb/mock_test.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `customContractFns` and `keys` in the codebase.

# Test: Search for the usage of `customContractFns` and `keys`. Expect: Proper usage in the codebase.
rg --type go 'customContractFns|keys'

Length of output: 14812


Script:

#!/bin/bash
# Description: Gather detailed information about the `Keeper` struct, `NewKeeper` function, and methods using `customContractFns` and `keys`.

# Search for the definition of the `Keeper` struct
ast-grep --lang go --pattern 'type Keeper struct { $$$ }' 

# Search for the implementation of the `NewKeeper` function
ast-grep --lang go --pattern 'func NewKeeper($_, $_, $_, $_, $_, $_, $_) *Keeper { $$$ }'

# Search for methods using `customContractFns` within the `Keeper` struct
rg --type go 'k\.customContractFns'

# Search for methods using `keys` within the `Keeper` struct
rg --type go 'k\.keys'

Length of output: 4109

Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

this looks good to me overall, but i have a feeling that there are many changes that are tricky to understand and missing more documentation and context
even though it is cherry pick, if we can increase this that would be great, especially on higher level (for example, we dont need to document store, btree etc, but changes in evm module, app.go and similar would be great to provide more context if possible)

i am ok to merge and test this on more e2e level, both with integrating with zeta and having some concrete precompiles to see how this work in bigger picture

app/app.go Show resolved Hide resolved
store/cachekv/README.md Show resolved Hide resolved
x/evm/keeper/state_transition.go Show resolved Hide resolved
x/evm/keeper/state_transition.go Show resolved Hide resolved
x/evm/keeper/state_transition.go Show resolved Hide resolved
x/evm/keeper/state_transition.go Show resolved Hide resolved
x/evm/statedb/native.go Show resolved Hide resolved
x/evm/statedb/statedb.go Show resolved Hide resolved
x/evm/types/interfaces.go Show resolved Hide resolved
@lumtis lumtis changed the title Add support stateful precompiles feat: add support stateful precompiles Jul 23, 2024
@lumtis
Copy link
Member

lumtis commented Jul 23, 2024

Looks good to me

  • Changed the PR title to follow PR semantic
  • I think we can already create a draft branch in node to use this version and run all testing

@@ -257,20 +257,17 @@ func TxLogsFromEvents(events []abci.Event, msgIndex int) ([]*ethtypes.Log, error

// ParseTxLogsFromEvent parse tx logs from one event
func ParseTxLogsFromEvent(event abci.Event) ([]*ethtypes.Log, error) {
logs := make([]*evmtypes.Log, 0, len(event.Attributes))

Choose a reason for hiding this comment

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

logs := make([]*evmtypes.Log, 0, len(event.Attributes)) preallocates memory. Curious, why it was removed?


// Set sets the transient-storage `value` for `key` at the given `addr`.
//nolint
func (t transientStorage) Set(addr common.Address, key, value common.Hash) {

Choose a reason for hiding this comment

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

Consider making these methods unexported as transientStorage is unexported itself

Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a5a3c14 and 66c665b.

Files selected for processing (2)
  • x/evm/keeper/state_transition.go (6 hunks)
  • x/evm/statedb/native.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/evm/keeper/state_transition.go
  • x/evm/statedb/native.go

Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
Comment on lines +470 to +472
for k, v := range tkeys {
allKeys[k] = v
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +473 to +475
for k, v := range memKeys {
allKeys[k] = v
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66c665b and cd0b54c.

Files selected for processing (1)
  • app/app.go (2 hunks)
Additional context used
GitHub Check: CodeQL
app/app.go

[warning] 470-472: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 473-475: Iteration over map
Iteration over map may be a possible source of non-determinism

Comment on lines +464 to +475

// allKeys contain all the application stores, so it covers all the stateful precompiled contract use cases.
allKeys := make(map[string]storetypes.StoreKey, len(keys)+len(tkeys)+len(memKeys))
for k, v := range keys {
allKeys[k] = v
}
for k, v := range tkeys {
allKeys[k] = v
}
for k, v := range memKeys {
allKeys[k] = v
}
Copy link

Choose a reason for hiding this comment

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

Potential non-determinism due to map iteration.

Iteration over maps in Go can lead to non-deterministic behavior because the order of iteration is random. To ensure deterministic behavior, consider sorting the keys before iterating over the maps.

allKeys := make(map[string]storetypes.StoreKey, len(keys)+len(tkeys)+len(memKeys))

// Collect and sort keys
sortedKeys := make([]string, 0, len(keys))
for k := range keys {
	sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys)
for _, k := range sortedKeys {
	allKeys[k] = keys[k]
}

// Repeat for tkeys and memKeys
sortedTKeys := make([]string, 0, len(tkeys))
for k := range tkeys {
	sortedTKeys = append(sortedTKeys, k)
}
sort.Strings(sortedTKeys)
for _, k := range sortedTKeys {
	allKeys[k] = tkeys[k]
}

sortedMemKeys := make([]string, 0, len(memKeys))
for k := range memKeys {
	sortedMemKeys = append(sortedMemKeys, k)
}
sort.Strings(sortedMemKeys)
for _, k := range sortedMemKeys {
	allKeys[k] = memKeys[k]
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// allKeys contain all the application stores, so it covers all the stateful precompiled contract use cases.
allKeys := make(map[string]storetypes.StoreKey, len(keys)+len(tkeys)+len(memKeys))
for k, v := range keys {
allKeys[k] = v
}
for k, v := range tkeys {
allKeys[k] = v
}
for k, v := range memKeys {
allKeys[k] = v
}
// allKeys contain all the application stores, so it covers all the stateful precompiled contract use cases.
allKeys := make(map[string]storetypes.StoreKey, len(keys)+len(tkeys)+len(memKeys))
// Collect and sort keys
sortedKeys := make([]string, 0, len(keys))
for k := range keys {
sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys)
for _, k := range sortedKeys {
allKeys[k] = keys[k]
}
// Repeat for tkeys and memKeys
sortedTKeys := make([]string, 0, len(tkeys))
for k := range tkeys {
sortedTKeys = append(sortedTKeys, k)
}
sort.Strings(sortedTKeys)
for _, k := range sortedTKeys {
allKeys[k] = tkeys[k]
}
sortedMemKeys := make([]string, 0, len(memKeys))
for k := range memKeys {
sortedMemKeys = append(sortedMemKeys, k)
}
sort.Strings(sortedMemKeys)
for _, k := range sortedMemKeys {
allKeys[k] = memKeys[k]
}
Tools
GitHub Check: CodeQL

[warning] 470-472: Iteration over map
Iteration over map may be a possible source of non-determinism


[warning] 473-475: Iteration over map
Iteration over map may be a possible source of non-determinism

@fbac fbac merged commit 3106ecc into main Jul 23, 2024
25 of 27 checks passed
@fbac fbac deleted the add-support-stateful-precompiles branch July 23, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support stateful precompiled contracts
7 participants