Skip to content

Remove the subtree edge case entirely by allowing zero-length subtrees - #275

Merged
davidben merged 3 commits into
mainfrom
remove-edge-case
Jul 20, 2026
Merged

Remove the subtree edge case entirely by allowing zero-length subtrees#275
davidben merged 3 commits into
mainfrom
remove-edge-case

Conversation

@davidben

Copy link
Copy Markdown
Collaborator

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.

davidben added 2 commits July 17, 2026 18:02
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.
## 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hash is unchanged because all the extra loop iterations are are vacuous. I added them just to keep it all uniform.

@lukevalenta lukevalenta left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is a really nice simplification. LGTM.

Comment thread draft-ietf-plants-merkle-tree-certs.md Outdated
Co-authored-by: Luke Valenta <lvalenta@cloudflare.com>
@davidben
davidben merged commit 0a39f6e into main Jul 20, 2026
4 checks passed
@davidben
davidben deleted the remove-edge-case branch July 20, 2026 20:26
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.

2 participants