Skip to content

add accumulated test vectors from specs - #15

Open
phbnf wants to merge 2 commits into
mainfrom
conf-inc-testvectors
Open

add accumulated test vectors from specs#15
phbnf wants to merge 2 commits into
mainfrom
conf-inc-testvectors

Conversation

@phbnf

@phbnf phbnf commented Jun 23, 2026

Copy link
Copy Markdown
Owner

No description provided.

@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 test file testonly/vectors_test.go to reproduce subtree test vectors from the draft-ietf-plants-merkle-tree-certs specification, testing subtree hashes, inclusion proofs, and consistency proofs. The reviewer's feedback points out that the helper function isValidSubtree duplicates the logic of the existing package-private function isSubtreeValid in tree.go. It is recommended to remove this duplicate helper and use the existing function instead.

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 testonly/vectors_test.go Outdated
Comment on lines +43 to +49
func isValidSubtree(start, end int) bool {
if 0 > start || start >= end {
return false
}
ceil := uint(1) << (bits.UintSize - bits.LeadingZeros(uint(end-start-1)))
return uint(start)&(ceil-1) == 0
}

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 isValidSubtree function duplicates the logic of isSubtreeValid already defined in tree.go within the same testonly package. You can remove this duplicate helper and directly use isSubtreeValid(uint64(start), uint64(end)) == nil instead.

Comment thread testonly/vectors_test.go Outdated
Comment on lines +67 to +69
if !isValidSubtree(start, end) {
continue
}

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

Use the package-private isSubtreeValid function from tree.go instead of the duplicate isValidSubtree helper.

Suggested change
if !isValidSubtree(start, end) {
continue
}
if isSubtreeValid(uint64(start), uint64(end)) != nil {
continue
}

Comment thread testonly/vectors_test.go Outdated
Comment on lines +86 to +88
if !isValidSubtree(start, end) {
continue
}

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

Use the package-private isSubtreeValid function from tree.go instead of the duplicate isValidSubtree helper.

Suggested change
if !isValidSubtree(start, end) {
continue
}
if isSubtreeValid(uint64(start), uint64(end)) != nil {
continue
}

Comment thread testonly/vectors_test.go Outdated
Comment on lines +110 to +112
if !isValidSubtree(start, end) {
continue
}

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

Use the package-private isSubtreeValid function from tree.go instead of the duplicate isValidSubtree helper.

Suggested change
if !isValidSubtree(start, end) {
continue
}
if isSubtreeValid(uint64(start), uint64(end)) != nil {
continue
}

@phbnf
phbnf force-pushed the conf-inc-testvectors branch from cc3ad56 to ccde87d Compare June 23, 2026 19:48
@phbnf

phbnf commented Jun 23, 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 a new test file testonly/vectors_test.go to verify subtree test vectors up to size 130 against the draft-ietf-plants-merkle-tree-certs specification. The review feedback suggests optimizing the writeProofLine helper function by using hex.NewEncoder instead of fmt.Fprintf with %x to reduce reflection and memory allocation overhead during test execution.

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 testonly/vectors_test.go
Comment on lines +50 to +54
for _, h := range proof {
if _, err := fmt.Fprintf(w, " %x", h); err != nil {
t.Fatalf("fmt.Fprintf: %v", 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

In writeProofLine, using fmt.Fprintf with %x inside a loop that executes hundreds of thousands of times across the test suite introduces significant overhead due to reflection and string allocations.

Using hex.NewEncoder from the encoding/hex package allows writing the hex-encoded bytes directly to the writer without intermediate allocations, which will greatly speed up the test execution.

Note: You will need to import "encoding/hex" in this file.

	enc := hex.NewEncoder(w)
	for _, h := range proof {
		if _, err := io.WriteString(w, " "); err != nil {
			t.Fatalf("io.WriteString: %v", err)
		}
		if _, err := enc.Write(h); err != nil {
			t.Fatalf("hex.Encoder.Write: %v", err)
		}
	}

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