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: enable KromaZKTrie by default #78

Merged
merged 5 commits into from
Mar 1, 2024
Merged

feat: enable KromaZKTrie by default #78

merged 5 commits into from
Mar 1, 2024

Conversation

jyc228
Copy link
Collaborator

@jyc228 jyc228 commented Feb 29, 2024

Summary by CodeRabbit

  • New Features
    • Introduced Kroma ZKTrie, enhancing the trie data structure for state management.
    • Added new functions for improved trie path handling and key conversion.
  • Refactor
    • Renamed ExperimentalZkTrie to KromaZKTrie across various components to reflect the new naming convention.
    • Updated conditional logic and method calls to align with the Kroma ZKTrie implementation.
  • Bug Fixes
    • Enhanced error reporting in trie manipulation by including additional context in error messages.

@jyc228 jyc228 requested a review from a team February 29, 2024 15:12
@jyc228 jyc228 self-assigned this Feb 29, 2024
Copy link

coderabbitai bot commented Feb 29, 2024

Walkthrough

The overall change revolves around renaming the ExperimentalZkTrie to KromaZKTrie across various files, indicating a shift in the project's focus towards a specific implementation or concept known as "Kroma". This renaming affects configuration structures, method conditions, and logic flows, signifying a deeper integration of the Kroma ZK trie technology into the system. Additionally, enhancements in error reporting and key conversion functions suggest improvements in usability and technical depth.

Changes

Files Change Summary
cmd/geth/config.go, cmd/geth/main.go, cmd/utils/flags.go, core/blockchain.go, eth/backend.go, eth/ethconfig/config.go, trie/database.go Renamed ExperimentalZkTrie to KromaZKTrie in configurations and structs.
core/state/database.go, internal/ethapi/api.go, trie/merkle_trie.go Updated logic to check for Kroma ZK trie instead of ZK state trie.
miner/payload_building.go Adjusted timing logic for block processing based on Kroma chain configuration.
trie/iterator.go, trie/iterator_key.go, trie/iterator_test.go Introduced and updated key conversion functions and tests for trie data structure.
trie/zk/merkle_tree.go, trie/zk/tree_path.go Enhanced error reporting in MerkleTree and added functions for tree path creation and conversion in tree_path.go.

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 348e72e and 9317a3c.
Files ignored due to path filters (1)
  • docs/audits/2024-02-23_KromaZKTrie_Security_Audit_ChainLight.pdf is excluded by: !**/*.pdf
Files selected for processing (16)
  • cmd/geth/config.go (1 hunks)
  • cmd/geth/main.go (1 hunks)
  • cmd/utils/flags.go (1 hunks)
  • core/blockchain.go (1 hunks)
  • core/state/database.go (2 hunks)
  • eth/backend.go (1 hunks)
  • eth/ethconfig/config.go (1 hunks)
  • internal/ethapi/api.go (1 hunks)
  • miner/payload_building.go (1 hunks)
  • trie/database.go (2 hunks)
  • trie/iterator.go (3 hunks)
  • trie/iterator_key.go (1 hunks)
  • trie/iterator_test.go (2 hunks)
  • trie/merkle_trie.go (1 hunks)
  • trie/zk/merkle_tree.go (4 hunks)
  • trie/zk/tree_path.go (3 hunks)
Additional comments: 29
trie/iterator_key.go (2)
  • 20-22: The function BytesToZkIteratorKey correctly converts a byte slice to a common.Hash by first creating a TreePath from the bytes and then converting that path to a big integer, which is finally converted to a hash. This process seems logically sound and adheres to the expected behavior of converting raw bytes to a ZkIteratorKey. However, it's important to ensure that the zk.NewTreePathFromBytes(data) and common.BigToHash(...) functions are well-tested, especially in edge cases such as empty byte slices or very large data inputs.
  • 24-26: The function ZkIteratorKeyToZkHash converts a common.Hash (representing an iterator key) back to a ZkHash. It uses the zk.NewTreePathFromHashBig(key) to first convert the hash to a TreePath and then converts this path to a ZkHash. This function is crucial for reverse conversions and seems logically correct. However, similar to the BytesToZkIteratorKey function, it's important to ensure that the underlying functions (zk.NewTreePathFromHashBig and ToZkHash) are thoroughly tested. Additionally, the direct dereferencing of the pointer returned by ToZkHash() could potentially lead to a nil pointer dereference if ToZkHash() ever returns nil. It would be safer to check for nil before dereferencing.
trie/zk/tree_path.go (3)
  • 19-21: The function NewTreePathFromHashBig creates a TreePath from a common.Hash by converting the hash to a big.Int and then calling NewTreePathFromBig with the resulting big.Int and a bit length. This function is a convenient wrapper for creating tree paths directly from hashes, which is a common operation. The logic appears sound, but it's important to ensure that the len(hash)*8 correctly represents the desired bit length for all possible hash inputs.
  • 23-33: The function NewTreePathFromBig creates a TreePath from a *big.Int and a specified maximum level (bit length). It iteratively checks each bit of the big.Int and sets the corresponding byte in the result slice. This function is crucial for converting numeric representations into tree paths, which are used in trie operations. The logic seems correct, but it's important to ensure that the bit manipulation and slice indexing are thoroughly tested, especially for edge cases such as very large big.Int values or unusual maxLevel values.
  • 87-94: The method ToBigInt converts a TreePath back to a *big.Int. It iterates over the bytes of the TreePath, setting bits in the result big.Int accordingly. This method is essential for reverse conversions and seems logically correct. However, similar to NewTreePathFromBig, it's important to ensure that the bit manipulation is thoroughly tested, especially considering the reverse order of iteration (lastIdx-i). Additionally, the use of SetBit in a loop could potentially be optimized, as repeatedly calling SetBit might not be the most efficient way to construct a big.Int from bits.
trie/merkle_trie.go (1)
  • 83-83: The change from db.IsZkStateTrie() to db.IsKromaZK() in the NewMerkleStateTrie function reflects the renaming effort and the shift towards a more branded implementation of the Zero-Knowledge Trie. This change is crucial for ensuring that the correct trie type is initialized based on the database configuration. It's important to verify that all references to the old IsZkStateTrie method have been updated accordingly and that the new IsKromaZK method is correctly implemented to reflect the intended logic.
Verification successful

The verification process confirms that the method IsKromaZK has been implemented and replaces all instances of IsZkStateTrie in the codebase. This change aligns with the renaming effort and ensures that the correct trie type is initialized based on the database configuration. There are no remaining references to IsZkStateTrie, indicating a successful update across the relevant files.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that IsKromaZK method is implemented and replaces all instances of IsZkStateTrie.
rg 'IsKromaZK' --type go
# Ensure no remaining references to IsZkStateTrie exist.
rg 'IsZkStateTrie' --type go

Length of output: 347

eth/ethconfig/config.go (1)
  • 193-193: The renaming of the ExperimentalZkTree field to KromaZKTrie within the Config struct aligns with the broader renaming effort and the shift towards a more branded implementation of the Zero-Knowledge Trie feature. This change is straightforward and reflects the PR objectives accurately. It's important to ensure that all references to the old ExperimentalZkTree field have been updated accordingly throughout the codebase.
Verification successful

The renaming of the ExperimentalZkTree field to KromaZKTrie has been successfully applied throughout the codebase, with all references updated accordingly. No remnants of the old field name were found, confirming the thoroughness of the renaming effort. This change aligns with the objectives outlined in the PR and the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that KromaZKTrie field is used in place of ExperimentalZkTree throughout the codebase.
rg 'KromaZKTrie' --type go
# Ensure no remaining references to ExperimentalZkTree exist.
rg 'ExperimentalZkTree' --type go

Length of output: 747

miner/payload_building.go (1)
  • 237-243: The adjustment in the buildPayload function to set the termination timer based on the Kroma chain configuration is a critical change that ensures the payload building process is correctly timed according to the specific blockchain configuration. The logic to use a 2-second block time for the Kroma chain and a 12-second block time otherwise seems appropriate. However, it's important to ensure that the w.chainConfig.Kroma check accurately reflects whether the Kroma configuration is in use and that this logic is consistently applied across the codebase.
Verification successful

The usage of chainConfig.Kroma to determine block times and other Kroma-specific configurations is consistent across the codebase, as evidenced by its presence in multiple files and contexts. This suggests that the adjustment in miner/payload_building.go for setting the termination timer based on the Kroma chain configuration aligns with the broader pattern of handling Kroma-specific logic throughout the system. Therefore, the review comment regarding the critical change in the buildPayload function and the importance of ensuring correct timing for the payload building process is verified to be in line with the overall codebase strategy.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the chainConfig.Kroma check is consistently used to determine block times across the codebase.
rg 'chainConfig.Kroma' --type go

Length of output: 1085

core/state/database.go (2)
  • 179-179: The introduction of the IsKromaZK check in the OpenTrie method correctly aligns with the PR's objective to rename and update functionalities related to the ZkTrie feature. This change ensures that the trie initialization logic now supports the newly branded KromaZKTrie.
  • 200-200: Similar to the OpenTrie method, the addition of the IsKromaZK condition in the OpenStorageTrie method is consistent with the renaming efforts and the introduction of the KromaZKTrie. This ensures that storage tries also leverage the new trie type when specified.
cmd/geth/config.go (1)
  • 193-193: The renaming of the configuration flag from ExperimentalZkTree to KromaZKTrie within the makeFullNode function aligns with the PR's objective to rebrand the ZkTrie feature. This change correctly updates the configuration structure to reflect the new naming convention.
trie/zk/merkle_tree.go (2)
  • 264-264: Including the level (lvl) in the error message when encountering a hash node in the Delete method enhances error reporting by providing more context. This change should make debugging easier by indicating at which level in the trie the error occurred.
  • 354-354: Similarly, including the level (lvl) in the error message in the Prove method when encountering a hash node is a good practice for the same reasons mentioned for the Delete method. It improves error reporting by providing additional context useful for debugging.
trie/database.go (3)
  • 40-40: Renaming the ExperimentalZkTrie field to KromaZKTrie in the Config struct aligns with the PR's objective to rebrand the ZkTrie feature. This change should be reflected across all references to ensure consistency.
  • 382-382: The introduction of the IsKromaZK method, which checks both Zktrie and KromaZKTrie flags, is a logical step following the renaming. However, it's important to ensure that the logic within this method accurately reflects the intended behavior, especially since it returns true only if both Zktrie and KromaZKTrie are true. This might introduce a change in behavior depending on how these flags are used throughout the codebase.
Verification successful

The analysis of the script outputs reveals several key points regarding the usage of the IsKromaZK method and the individual Zktrie and KromaZKTrie flags within the codebase:

  1. Usage of IsKromaZK Method: The IsKromaZK method is used in several places (trie/merkle_trie.go, internal/ethapi/api.go, core/state/database.go) to determine the type of trie to use, specifically opting for a ZkMerkleStateTrie when both Zktrie and KromaZKTrie are true. This indicates that the method's logic is actively employed to switch between trie types based on the configuration.

  2. Separate Usage of Zktrie Flag: The Zktrie flag is used extensively across the codebase, not only in the definition of the IsKromaZK method but also in various configurations and checks. Its usage spans from database configurations to conditional logic for enabling specific trie types or functionalities. This widespread use underscores its importance in the system's configuration.

  3. Separate Usage of KromaZKTrie Flag: The KromaZKTrie flag, while not as extensively mentioned as Zktrie, is still significant. It appears in configuration settings and is part of the logic for determining the trie type in conjunction with Zktrie. Its presence alongside Zktrie in the IsKromaZK method suggests a deliberate design choice to couple these flags for specific functionality.

  4. Implications of Combining Flags: The introduction of the IsKromaZK method, which requires both Zktrie and KromaZKTrie to be true, does not seem to introduce unintended behavior based on the script outputs. Instead, it appears to be a deliberate mechanism to enable a specific trie type (ZkMerkleStateTrie) under certain conditions. This method's usage aligns with the instances where a specific configuration of trie is necessary, indicating that its logic is consistent with the intended behavior.

Given these observations, the introduction of the IsKromaZK method and its logic of requiring both Zktrie and KromaZKTrie to be true for certain operations seems to be a calculated decision to control the trie type used in specific scenarios. The method's usage across the codebase aligns with this logic, suggesting that it does not introduce unintended behavior but rather provides a means to enforce a specific configuration under defined conditions.

Based on the analysis, it can be concluded that the review comment's concern about potential unintended behavior due to the dual condition in IsKromaZK does not manifest in the codebase. The usage of this method and the conditions it checks for are consistent with its intended purpose.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the dual condition in IsKromaZK does not introduce unintended behavior.
# This script is a placeholder for the actual verification process, which should
# examine the usage of IsKromaZK and the implications of requiring both flags to be true.
echo "Manual verification needed to assess the impact of IsKromaZK logic on the codebase."

Length of output: 176



Script:

#!/bin/bash
# Search for usage of IsKromaZK method
echo "Searching for IsKromaZK method usage..."
rg "IsKromaZK" --context 2

# Search for separate usage of Zktrie and KromaZKTrie flags
echo -e "\nSearching for separate usage of Zktrie flag..."
rg "Zktrie" --context 2

echo -e "\nSearching for separate usage of KromaZKTrie flag..."
rg "KromaZKTrie" --context 2

Length of output: 31840

* 389-393: The `SetBackend` method's update to handle the `KromaZKTrie` configuration alongside the `Zktrie` flag is necessary following the renaming. However, it's crucial to ensure that this method's logic correctly applies the new configuration, especially since it now involves setting both `Zktrie` and `KromaZKTrie` flags. This change should be carefully reviewed to avoid any configuration inconsistencies or unintended behavior.
Verification successful

The SetBackend method in trie/database.go has been updated to correctly handle the Zktrie and KromaZKTrie configurations. It checks if the Zktrie flag's current state matches the passed argument and updates the database configuration accordingly, preserving the KromaZKTrie flag's current state. This implementation should ensure that the method does not introduce configuration inconsistencies or unintended behavior. The usage of both flags across the codebase further indicates their integration into the system's broader functionality. Based on this analysis, the update appears to be correctly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the updated SetBackend method correctly applies the new configuration
# without introducing inconsistencies or unintended behavior.
# This script is a placeholder for the actual verification process, which should
# examine the implementation and usage of SetBackend in the context of the new flags.
echo "Manual verification needed to assess the impact of SetBackend updates on the codebase."

Length of output: 182



Script:

#!/bin/bash
# Search for the SetBackend method definition to examine its implementation
rg "func \(.*\) SetBackend" -A 20
# Additionally, search for usages of Zktrie and KromaZKTrie flags to ensure consistency
rg "Zktrie|KromaZKTrie"

Length of output: 9888

cmd/geth/main.go (1)
  • 160-160: The renaming of utils.ExperimentalZkTrie to utils.KromaZKTrie is consistent with the PR's objective to rebrand the Zero-Knowledge Trie feature. This change should be reflected across all references in the codebase to ensure consistency. Please verify that all instances of ExperimentalZkTrie have been updated to KromaZKTrie throughout the entire project, not just in this file.
Verification successful

Given the absence of any output from the search for ExperimentalZkTrie within Go files, it suggests that the renaming to KromaZKTrie has been successfully applied across the Go codebase. To ensure thorough verification, it would be prudent to extend the search beyond Go files to include all file types, capturing any potential references in non-Go files such as configuration files or documentation.


The searches conducted, both within Go files and across all file types, did not find any remaining references to ExperimentalZkTrie. This indicates that the renaming to KromaZKTrie has been successfully completed throughout the entire project. There are no indications of overlooked references, suggesting a thorough and comprehensive renaming process.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to ExperimentalZkTrie to ensure complete renaming.
rg --type go 'ExperimentalZkTrie'

Length of output: 33



Script:

#!/bin/bash
# Extend the search for any remaining references to ExperimentalZkTrie across all file types.
rg 'ExperimentalZkTrie'

Length of output: 23

trie/iterator_test.go (2)
  • 631-631: The change from zk.NewTreePathFromHash to zk.NewTreePathFromHashBig in the context of verifying the correctness of the tree path during iteration seems logical given the PR's objectives. However, ensure that the NewTreePathFromHashBig function is thoroughly tested, especially for edge cases and large inputs, to prevent any potential issues with tree path generation.
  • 673-673: The replacement of zk.NewTreePathFromZkHash with BytesToZkIteratorKey(hash[:]).Bytes() introduces a new way of converting hash bytes to a Zk iterator key. This change aligns with the PR's objectives of enhancing trie handling and configuration. It's crucial to verify that the BytesToZkIteratorKey function correctly handles all expected input formats and that its implementation does not introduce any performance regressions or unexpected behavior, especially in edge cases.
eth/backend.go (1)
  • 211-211: The renaming of ExperimentalZkTrie to KromaZKTrie in the configuration assignment is consistent with the PR's objective to rebrand the Zero-Knowledge Trie feature. This change aligns with the broader effort to refine and integrate the ZkTrie technology more deeply into the project. Ensure that all references to the old ExperimentalZkTrie configuration across the codebase have been updated to KromaZKTrie to maintain consistency and avoid potential configuration errors.
Verification successful

The search for any remaining references to ExperimentalZkTrie in the Go files of the codebase did not yield any results, indicating that the renaming to KromaZKTrie has been successfully completed across the codebase. This aligns with the PR's objective and suggests thorough implementation of the renaming.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to ExperimentalZkTrie in the codebase.
rg --type go 'ExperimentalZkTrie'

Length of output: 33

trie/iterator.go (3)
  • 862-862: The usage of BytesToZkIteratorKey for converting keys in merkleTreeIteratorLeafNode is a critical change. Ensure that the BytesToZkIteratorKey function correctly handles the key conversion logic as expected for the ZkTrie feature. This conversion is essential for maintaining the integrity and functionality of the trie iterator, especially in the context of Zero-Knowledge proofs where key representation can significantly impact the trie's behavior and security.
  • 902-902: Similar to the previous comment, the use of BytesToZkIteratorKey in the zktrieNodeBlobFunctions function for converting node keys is crucial. It's important to verify that this conversion aligns with the expected behavior of the ZkTrie, ensuring that keys are correctly handled throughout the trie operations. This change is part of the broader effort to integrate Zero-Knowledge Trie technology into the system, and as such, it's vital to ensure its correctness and efficiency.
  • 936-936: The introduction of zk.NewTreePathFromHashBig for converting the path parameter in the merkleTreeIterator.seek method is noteworthy. This conversion is likely related to the handling of trie paths in the context of Zero-Knowledge proofs. It's important to ensure that this conversion is accurate and does not introduce any potential issues with trie navigation or proof generation. The correct handling of paths is essential for the integrity and functionality of the trie, especially in scenarios involving Zero-Knowledge proofs.
cmd/utils/flags.go (1)
  • 1039-1043: The renaming of the ExperimentalZkTrie flag to KromaZKTrie is correctly implemented. The updated flag name and usage description align with the PR's objectives to rebrand the ZkTrie feature. Setting the default value to true suggests that the KromaZKTrie feature is enabled by default, which should be verified for alignment with project goals and documentation.
core/blockchain.go (5)
  • 154-154: Renaming ExperimentalZkTrie to KromaZKTrie in the CacheConfig struct is consistent with the PR's objective to rebrand the Zero-Knowledge Trie feature. This change aligns with the renaming strategy and does not introduce any immediate issues.
  • 159-159: The update in triedbConfig method to use KromaZKTrie instead of ExperimentalZkTrie correctly reflects the renaming and ensures that the trie database configuration is aligned with the new naming convention.
  • 154-159: The renaming of ExperimentalZkTrie to KromaZKTrie in both the CacheConfig struct and the triedbConfig method is consistent and correctly implemented. This change aligns with the PR's objective to rebrand the Zero-Knowledge Trie feature and is correctly applied in the context of trie database configuration.
  • 159-159: The use of KromaZKTrie in the trie.Config initialization correctly reflects the updated naming convention. It's important to ensure that all references to the old ExperimentalZkTrie name are updated across the codebase to maintain consistency.
Verification successful

The search for any remaining references to ExperimentalZkTrie did not produce any results, indicating that all references to the old name have likely been updated across the Go files in the codebase. This aligns with the goal of maintaining consistency with the updated naming convention.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to `ExperimentalZkTrie` that should be updated.
rg --type go 'ExperimentalZkTrie'

Length of output: 33

* 159-159: The assignment of `KromaZKTrie: c.KromaZKTrie` in the `trie.Config` struct correctly applies the updated configuration value. This change is part of the broader effort to rename and update functionalities related to the Zero-Knowledge Trie feature, aligning with the PR's objectives.

@@ -787,7 +787,7 @@ func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, st
}

func (s *BlockChainAPI) newStateTrie(id *trie.ID, db *trie.Database) (state.Trie, error) {
if db.IsZkStateTrie() {
if db.IsKromaZK() {
Copy link

Choose a reason for hiding this comment

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

The condition if db.IsKromaZK() checks for a specific trie type but does not account for potential future trie types or configurations. Consider future-proofing this logic by either implementing a more flexible trie type handling mechanism or documenting the need for updates when new trie types are introduced.


The method newStateTrie uses a conditional check to determine the trie type but does not handle potential errors or unexpected trie types. It's recommended to add error handling for unsupported trie types to prevent runtime panics or undefined behavior.

+ if err != nil {
+   return nil, fmt.Errorf("unsupported trie type: %v", err)
+ }

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.

Suggested change
if db.IsKromaZK() {
if db.IsKromaZK() {
+ if err != nil {
+ return nil, fmt.Errorf("unsupported trie type: %v", err)
+ }

The use of IsKromaZK and IsZk methods to determine the trie type introduces tight coupling between the newStateTrie function and the specific trie implementations. Consider abstracting trie creation behind a factory pattern to improve modularity and facilitate easier addition of new trie types in the future.


In the newStateTrie method, there's a direct return in the conditional branches without any logging or metrics collection. For debugging and monitoring purposes, it might be beneficial to log the trie type being used or collect metrics on trie usage.

+ log.Debug("Creating new state trie", "type", "KromaZK")

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.

Suggested change
if db.IsKromaZK() {
if db.IsKromaZK() {
+ log.Debug("Creating new state trie", "type", "KromaZK")

The method newStateTrie does not validate the integrity or authenticity of the trie ID or root being passed to it. In a blockchain context, ensuring data integrity is crucial. Consider implementing additional checks or leveraging existing cryptographic validations to ensure the trie data's integrity before usage.

Comment on lines 151 to 162
SnapshotNoBuild bool // Whether the background generation is allowed
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it

ExperimentalZkTrie bool // use ZkMerkleStateTrie instead of ZkTrie
KromaZKTrie bool // use ZkMerkleStateTrie instead of ZkTrie
}

// triedbConfig derives the configures for trie database.
func (c *CacheConfig) triedbConfig() *trie.Config {
config := &trie.Config{Preimages: c.Preimages, ExperimentalZkTrie: c.ExperimentalZkTrie}
config := &trie.Config{Preimages: c.Preimages, KromaZKTrie: c.KromaZKTrie}
if c.StateScheme == rawdb.HashScheme {
config.HashDB = &hashdb.Config{
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [14-14]

The TODO comment regarding adding tests should be addressed to ensure the reliability and correctness of the code.

Would you like me to help generate tests for this functionality?

@seolaoh seolaoh changed the title release v0.4.4 feat: enable KromaZKTrie by default Mar 1, 2024
@Pangssu Pangssu merged commit af3965b into main Mar 1, 2024
2 checks passed
@Pangssu Pangssu deleted the release/v0.4.4 branch March 1, 2024 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants