Skip to content

verifysubtreeinclusion - #3

Open
phbnf wants to merge 11 commits into
mainfrom
verifysubtreeinclusion
Open

verifysubtreeinclusion#3
phbnf wants to merge 11 commits into
mainfrom
verifysubtreeinclusion

Conversation

@phbnf

@phbnf phbnf commented Jun 3, 2026

Copy link
Copy Markdown
Owner
  • verifysubtreeinclusion implementation
  • verifysubtreeinclusion test copy + implementation
  • size --> start, end in tests
  • duplicate tests to -shifted.json
  • shift everything by bit_ceil
  • mv -shifted.json -subtree.json
  • s/shifted/subtree
  • add error tests

@phbnf

phbnf commented Jun 3, 2026

Copy link
Copy Markdown
Owner 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 a new VerifySubtreeInclusion function in proof/verify.go to verify subtree inclusion proofs, along with comprehensive test coverage and test data. Feedback on the changes highlights a misleading error message in the subtree validation check, which also poses a potential risk of panic or undefined behavior on extremely large inputs. A simplified error message was suggested to resolve this safely.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread proof/verify.go Outdated
Comment on lines +68 to +71
if !isSubtreeValid(start, end) {
return fmt.Errorf("start %d not a multiple of bit_ceil(end - start) = %d", start, end-start)

}

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 error message is misleading because it prints end-start as the value of bit_ceil(end - start), which is not ceiled. Additionally, directly calling bitCeil(end - start) on extremely large inputs (where end - start > 1<<63, as tested in invalid-large-subtree.json) would violate bitCeil's precondition and could cause undefined behavior or panic.

To fix this safely and cleanly, and to remove the extra blank line on line 70, we can simplify the error message to omit the ceiled value.

	if !isSubtreeValid(start, end) {
		return fmt.Errorf("start %d not a multiple of bit_ceil(end - start)", start)
	}

@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 the VerifySubtreeInclusion function to verify subtree inclusion proofs, along with a comprehensive test suite and extensive JSON-based test cases. Feedback on the implementation highlights an error message formatting issue where end-start is printed instead of the actual bitCeil(end-start) value, as well as an unnecessary blank line in the validation block.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread proof/verify.go Outdated
Comment on lines +68 to +71
if !isSubtreeValid(start, end) {
return fmt.Errorf("start %d not a multiple of bit_ceil(end - start) = %d", start, end-start)

}

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 error message incorrectly prints end-start as the value of bit_ceil(end - start). Since bitCeil is available in the package, we should use bitCeil(end-start) to show the correct value in the error message. Additionally, there is an unnecessary blank line inside the if block.

	if !isSubtreeValid(start, end) {
		return fmt.Errorf("start %d not a multiple of bit_ceil(end - start) = %d", start, bitCeil(end-start))
	}

@phbnf
phbnf force-pushed the verifysubtreeinclusion branch from bca3439 to 7cd81e3 Compare June 3, 2026 10:24
@phbnf

phbnf commented Jun 3, 2026

Copy link
Copy Markdown
Owner 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 subtree inclusion proof verification, adding the VerifySubtreeInclusion function in proof/verify.go along with corresponding tests and a comprehensive set of JSON test cases. Feedback on the changes includes removing an unnecessary blank line in proof/verify.go, correcting a struct comment in proof/verify_test.go to refer to subtreeInclusionProbe instead of inclusionProbe, and updating a test error message to specify 'subtree inclusion probes' for better clarity.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread proof/verify.go Outdated
Comment on lines +68 to +71
if !isSubtreeValid(start, end) {
return fmt.Errorf("start %d not a multiple of bit_ceil(end - start)", start)

}

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

There is an unnecessary blank line at the end of the if block. Running gofmt on the file will automatically remove this blank line and ensure compliance with standard Go formatting guidelines.

	if !isSubtreeValid(start, end) {
		return fmt.Errorf("start %d not a multiple of bit_ceil(end - start)", start)
	}

Comment thread proof/verify_test.go Outdated
WantError bool `json:"wantErr"`
}

// inclusionProbe is a parameter set for inclusion proof verification.

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 comment refers to inclusionProbe, but the struct being defined is subtreeInclusionProbe. Updating the comment to match the struct name improves code readability and maintainability.

Suggested change
// inclusionProbe is a parameter set for inclusion proof verification.
// subtreeInclusionProbe is a parameter set for subtree inclusion proof verification.

Comment thread proof/verify_test.go Outdated

return nil
}); err != nil {
t.Errorf("failed to read inclusion probes: %s", err)

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 error message mentions inclusion probes, but this test is specifically for subtree inclusion probes. Updating the error message to be more specific helps with debugging test failures.

Suggested change
t.Errorf("failed to read inclusion probes: %s", err)
t.Errorf("failed to read subtree inclusion probes: %s", err)

@phbnf
phbnf force-pushed the verifysubtreeinclusion branch 2 times, most recently from ca746d9 to f8931b7 Compare June 3, 2026 10:30
@phbnf

phbnf commented Jun 3, 2026

Copy link
Copy Markdown
Owner 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 adds the VerifySubtreeInclusion function to verify subtree inclusion proofs, along with corresponding unit tests and a comprehensive set of JSON test vectors. It also refactors an error message in proof/proof.go. The review feedback recommends adding a defensive check to ensure the hasher parameter is not nil to prevent potential nil pointer dereferences.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread proof/verify.go
Comment on lines +61 to +62
func VerifySubtreeInclusion(hasher merkle.LogHasher, index, start, end uint64, leafHash []byte, proof [][]byte, root []byte) error {
if start >= end {

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 hasher parameter is not checked for nil. If a caller passes nil for hasher, the function will panic with a nil pointer dereference when hasher.Size() is called inside RootFromInclusionProof.

Consider adding a defensive check at the beginning of the function to return an error if hasher is nil.

Suggested change
func VerifySubtreeInclusion(hasher merkle.LogHasher, index, start, end uint64, leafHash []byte, proof [][]byte, root []byte) error {
if start >= end {
func VerifySubtreeInclusion(hasher merkle.LogHasher, index, start, end uint64, leafHash []byte, proof [][]byte, root []byte) error {
if hasher == nil {
return errors.New("hasher cannot be nil")
}
if start >= end {

@phbnf
phbnf force-pushed the verifysubtreeinclusion branch from f8931b7 to e6a72d5 Compare June 3, 2026 10:35
@phbnf
phbnf force-pushed the verifysubtreeinclusion branch from 85206ca to f6aeee6 Compare June 8, 2026 10:00
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.

1 participant