add accumulated test vectors from specs - #15
Conversation
There was a problem hiding this comment.
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.
| 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 | ||
| } |
| if !isValidSubtree(start, end) { | ||
| continue | ||
| } |
| if !isValidSubtree(start, end) { | ||
| continue | ||
| } |
| if !isValidSubtree(start, end) { | ||
| continue | ||
| } |
cc3ad56 to
ccde87d
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
| for _, h := range proof { | ||
| if _, err := fmt.Fprintf(w, " %x", h); err != nil { | ||
| t.Fatalf("fmt.Fprintf: %v", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
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)
}
}
No description provided.