Remove the subtree edge case entirely by allowing zero-length subtrees - #275
Merged
Conversation
The accumulated test for the subtree covering was written as if the single-subtree special case was for [start, end) being a subtree, when it's actually for [start, end) having size 1. Either would have worked. The spec mostly arbitrarily picked the latter.
Instead of having an rare edge case where landmark intervals of size one return one subtree instead of two, just always return two. In order to do that, we have to say zero-length subtrees are legal. That introduces silly special cases for consistency proofs, but means all our functions have uniform types, which I think is worth it.
davidben
commented
Jul 18, 2026
| ## Subtree Inclusion Proofs {#subtree-inclusion-proof-vectors} | ||
|
|
||
| For each value of `end` from 1 to 130, and each value of `start` from 0 to `end - 1`, if `[start, end)` is a valid subtree, for each value of `index` from `start` to `end - 1`, add to the rolling hash the ASCII string `INDEX [START, END)`, then, for each hash in the inclusion proof ({{subtree-inclusion-proofs}}) for `d[index]` in the subtree `[start, end)`, a space (U+0020) followed by the hexadecimal encoding of that hash, and finally a newline (U+000A), where `INDEX` is the decimal representation of `index`, and `START` and `END` are the decimal representations of `start` and `end`, respectively. | ||
| For each value of `end` from 0 to 130, and each value of `start` from 0 to `end`, if `[start, end)` is a valid subtree, for each value of `index` from `start` to `end - 1`, add to the rolling hash the ASCII string `INDEX [START, END)`, then, for each hash in the inclusion proof ({{subtree-inclusion-proofs}}) for `d[index]` in the subtree `[start, end)`, a space (U+0020) followed by the hexadecimal encoding of that hash, and finally a newline (U+000A), where `INDEX` is the decimal representation of `index`, and `START` and `END` are the decimal representations of `start` and `end`, respectively. |
Collaborator
Author
There was a problem hiding this comment.
The hash is unchanged because all the extra loop iterations are are vacuous. I added them just to keep it all uniform.
lukevalenta
approved these changes
Jul 20, 2026
lukevalenta
left a comment
Collaborator
There was a problem hiding this comment.
Oh this is a really nice simplification. LGTM.
Co-authored-by: Luke Valenta <lvalenta@cloudflare.com>
This was referenced Jul 22, 2026
FiloSottile
added a commit
to FiloSottile/torchwood
that referenced
this pull request
Jul 28, 2026
FiloSottile
added a commit
to FiloSottile/torchwood
that referenced
this pull request
Jul 28, 2026
FiloSottile
added a commit
to FiloSottile/torchwood
that referenced
this pull request
Jul 28, 2026
FiloSottile
added a commit
to FiloSottile/torchwood
that referenced
this pull request
Jul 28, 2026
FiloSottile
added a commit
to FiloSottile/torchwood
that referenced
this pull request
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This includes #274
Instead of having an rare edge case where landmark intervals of size one return one subtree instead of two, just always return two. In order to do that, we have to say zero-length subtrees are legal.
That introduces silly special cases for consistency proofs, but means all our functions have uniform types, which I think is worth it.