-
Notifications
You must be signed in to change notification settings - Fork 48
feat: refactor VerifyLeafHashes, VerifyNamespace, and VerifyInclusion to expose computing root and validations outside of Proof #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe pull request refactors the namespace proof verification logic by introducing several new methods to modularize and clarify the code. It adds Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant VerifyLeafHashes
participant Validate
participant ComputeLeafHashes
participant ComputeRoot
Client->>VerifyLeafHashes: VerifyLeafHashes(nth, verifyCompleteness, nID, leafHashes, root)
VerifyLeafHashes->>Validate: ValidateProofStructure(...)
Validate-->>VerifyLeafHashes: Validation result
VerifyLeafHashes->>Validate: ValidateSingleNamespace(...)
Validate-->>VerifyLeafHashes: Validation result
VerifyLeafHashes->>Validate: ValidateCompleteness(...) (if requested)
Validate-->>VerifyLeafHashes: Validation result
VerifyLeafHashes->>ComputeRoot: ComputeRoot(nth, leafHashes)
ComputeRoot-->>VerifyLeafHashes: computedRoot or error
VerifyLeafHashes-->>Client: (bool valid, error)
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (13)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
… VerifyInclusion for utilizing outside of proof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall seems fine to me. Left a few optional nits and refactors that are safe to ignore if that code was just copied from the previous implementation.
It would be nice to include unit tests for the extracted helper methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice changes and refactor!
Agree with above that nmt pkg will benefit from unit tests for new exported funcs.
any remaining blocking reviews @vgonkivs ? or can we merge and flup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the core verification methods in the proof package to isolate root computation logic and expose validations externally, while also extending test coverage for various proof scenarios.
- Refactored verification functions to separate basic validation and root computation.
- Added helper functions for computing and validating leaf hashes and prefixed leaf hashes.
- Expanded tests to cover namespace mismatch, proof structure violations, and completeness conditions.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
proof_test.go | New tests covering ComputeRootWithBasicValidation, namespace and completeness validations |
proof.go | Refactored proof verification APIs; added validation helper functions and improved error handling |
Comments suppressed due to low confidence (1)
proof.go:249
- [nitpick] Although the proof range check is effective, consider splitting the condition into separately named variables for proof start and end to improve readability and future maintainability.
if proof.Start() < 0 || proof.Start() >= proof.End() {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[no change needed] I don't understand the refactor anymore because so many lines were modified. One idea for a future refactor is to split the proof struct into multiple structs. For example: one struct for absence proof and one for inclusion proof. Then we can split this large file into two smaller files.
I don't see any issues besides the AI slop in the tests so seems safe to merge after addressing that comment.
Fixes #290
Summary by CodeRabbit