Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces a significant feature for the Contract API and Virtual Storage called "Witness Merging." The primary goal of this feature is to eliminate the need for light clients to fetch the entire MerkleMap state, in order to generate necessary witnesses on-demand for executing zkApp transactions/computations. This implementation is finalized for a local testing mode. Future work will integrate with the ZKFS node.
Background and Context
Previously, clients had to fetch the entire Merkle Map state to create necessary witnesses for zkApp transactions/computations. This process was resource-intensive and inefficient, particularly for clients with limited bandwidth.
It is important to understand how Merkle witnesses work in this context. Suppose we have two values and their corresponding witnesses:
These witnesses allow us to compute the same Merkle root, R.
Now, let's suppose value1 is updated to value1'.
However, witness2 becomes outdated because some values (aka siblings) required to compute the root R' depend on the updated value1'. To address this issue, it is necessary to retrieve the updated witness from an updated MerkleMap that reflects the change in value1'. The issue is that a light client would need to fetch the whole MerkleMap, which is especially resource intensive if multiple maps are fetched (nested maps).
Solution: Witness Merging
Witness Merging is a novel technique that allows clients to update witnesses on-demand without the need to fetch the entire MerkleMap state. For this, it is necessary to keep track of last updated values and their witnesses. The Witness Merging algorithm takes witness1, witness2, and value1' as inputs and generates an updated_witness2', which computes the new root R' with value2. This eliminates the need for clients to access the whole Merkle Map to generate updated witnesses.
Changes
This PR includes the following major changes:
Performance Impact
A Merkle witness is significantly smaller and most certainly negligible in size compared to a Merkle tree of height 255. This translates to less network activity and reduced resource consumption for ZKFS light clients and ZKFS writer nodes.
Future Work
While this PR implements the core functionality of Witness Merging, there needs to be an integration with the ZKFS node/light client in order to manage off-chain state fetching and any configuration between testing locally or with a live Mina network.
Reviewers
Please review the changes in this PR, focusing on the following aspects: