Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

feat: init single merkle proof - #85

Merged
wemeetagain merged 2 commits into
mainfrom
single_merkle_proof
Nov 11, 2025
Merged

feat: init single merkle proof#85
wemeetagain merged 2 commits into
mainfrom
single_merkle_proof

Conversation

@GrapeBaBa

Copy link
Copy Markdown
Contributor

Motivation

Provide single-proof support for the persistent Merkle tree so callers can export and reconstruct proofs for individual nodes.

Description

  • Added proof.zig with createSingleProof and createNodeFromSingleProof, a shared error set, and the SingleProof struct that takes ownership of witness buffers.
  • Created proof_test.zig to cover round-trip reconstruction, consistency across leaves, invalid navigation, and invalid gindex scenarios.

Signed-off-by: grapebaba <grapebaba@grapebabadeMacBook-Pro.local>
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @GrapeBaBa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates single Merkle proof capabilities into the persistent Merkle tree system. This enhancement allows users to generate and verify proofs for specific nodes, enabling more granular data verification and reconstruction. The changes provide a foundational mechanism for exporting and validating individual node states without needing the entire tree.

Highlights

  • Single Merkle Proof Implementation: Introduces core functionality for creating and reconstructing single Merkle proofs for individual nodes within a persistent Merkle tree.
  • New proof.zig Module: Adds proof.zig containing createSingleProof and createNodeFromSingleProof functions, a dedicated error set, and the SingleProof struct for managing proof data.
  • Comprehensive Testing: Includes proof_test.zig with tests covering proof round-trip reconstruction, consistency across leaves, and error handling for invalid navigation and gindex values.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for single Merkle proofs, including functions to create proofs and reconstruct nodes from them. The implementation is accompanied by a comprehensive test suite covering round-trip conversions, consistency, and error cases. The code is well-structured. I've made a few suggestions to improve code clarity and remove unused code: one regarding an unused import, another to simplify an index calculation, and a third to remove an unused error from the public API.

Comment thread src/persistent_merkle_tree/proof.zig Outdated
Comment thread src/persistent_merkle_tree/proof.zig Outdated
Comment thread src/persistent_merkle_tree/proof.zig Outdated
Comment thread src/persistent_merkle_tree/proof.zig
Signed-off-by: grapebaba <grapebaba@grapebabadeMacBook-Pro.local>
@GrapeBaBa

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces functionality for creating and reconstructing single Merkle proofs. The implementation is robust and accompanied by a comprehensive test suite that covers round-trip verification, consistency across different leaves, and various error scenarios. The code is well-structured and clear. I have one suggestion to slightly refactor the proof creation logic to improve readability and reduce a small amount of code duplication. Overall, this is a solid contribution.

Comment on lines +57 to +65
if (path.left()) {
const right_id = try node_id.getRight(pool);
witnesses[witness_index] = right_id.getRoot(pool).*;
node_id = try node_id.getLeft(pool);
} else {
const left_id = try node_id.getLeft(pool);
witnesses[witness_index] = left_id.getRoot(pool).*;
node_id = try node_id.getRight(pool);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic within this if/else block can be simplified to improve readability and reduce code duplication. Since both branches need to access the left and right children of the current node (one for the witness, one for the next step in the traversal), you can fetch both child IDs before the conditional statement.

            const left_id = try node_id.getLeft(pool);
            const right_id = try node_id.getRight(pool);

            if (path.left()) {
                witnesses[witness_index] = right_id.getRoot(pool).*;
                node_id = left_id;
            } else {
                witnesses[witness_index] = left_id.getRoot(pool).*;
                node_id = right_id;
            }

@wemeetagain
wemeetagain merged commit e821dc4 into main Nov 11, 2025
3 checks passed
@wemeetagain
wemeetagain deleted the single_merkle_proof branch November 11, 2025 19:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants