Skip to content

Commit d2d5021

Browse files
committed
Unify the two branches in the consistency proof check
Also replace prepending to the proof list with removing in the other branch. It makes it a little obvious how to implement this without making a copy of the proof. This should also hopefully make the relationship between inclusion and consistency proof evaluation clearer. While I'm here, use '1.' for the steps so we don't have to renumber it as it changes.
1 parent edbcb0a commit d2d5021

1 file changed

Lines changed: 18 additions & 25 deletions

File tree

draft-davidben-tls-merkle-tree-certs.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -516,32 +516,25 @@ The following procedure can be used to verify a subtree consistency proof.
516516

517517
Given a Merkle Tree over `n` elements, a subtree defined by `[start, end)`, a consistency proof `proof`, a subtree hash `node_hash`, and a root hash `root_hash`:
518518

519-
1. If `end` is `n`, run the following:
520-
1. Set `fn` to `start` and `sn` to `end - 1`.
521-
2. Set `r` to `node_hash`.
522-
3. Until `LSB(fn)` is set or `sn` is `0`, right-shift `fn` and `sn` equally.
523-
4. For each value `p` in the `proof` array:
524-
1. If `sn` is `0`, then stop iteration and fail the proof verification.
525-
2. Set `r` to `HASH(0x01 || p || r)`.
526-
3. Until `LSB(sn)` is set, right-shift `sn`.
527-
4. Right-shift `sn` once more.
528-
5. Compare `sn` to `0` and `r` to `root_hash`. If either is not equal, fail the proof verification. If all are equal, accept the proof.
529-
2. Otherwise, run the following:
519+
1. Set `fn` to `start`, `sn` to `end - 1`, and `tn` to `n - 1`.
520+
1. If `sn` is `tn`, then:
521+
1. Right-shift `fn`, `sn`, and `tn` equally until `fn` is `sn`.
522+
1. Otherwise:
523+
1. Right-shift `fn`, `sn`, and `tn` equally until `LSB(sn)` is not set or `fn` is `sn`
524+
1. If `fn` is `sn`, set `fr` and `sr` to `node_hash`.
525+
1. Otherwise:
530526
1. If `proof` is an empty array, stop and fail verification.
531-
2. If `end - start` is an exact power of two, prepend `node_hash` to the `proof` array.
532-
3. Set `fn` to `start`, `sn` to `end - 1`, and `tn` to `n - 1`.
533-
4. Until `LSB(sn)` is not set or `fn` is equal to `sn`, right-shift `fn`, `sn`, and `tn` equally.
534-
5. Set both `fr` and `sr` to the first value in the `proof` array.
535-
6. For each subsequent value `c` in the `proof` array:
536-
1. If `tn` is `0`, then stop the iteration and fail the proof verification.
537-
2. If `LSB(sn)` is set, or if `sn` is equal to `tn`, then:
538-
1. If `fn < sn`, set `fr` to `HASH(0x01 || c || fr)`.
539-
2. Set `sr` to `HASH(0x01 || c || sr)`.
540-
3. Until `LSB(sn)` is set, right-shift `fn`, `sn`, and `tn` equally.
541-
3. Otherwise:
542-
1. Set `sr` to `HASH(0x01 || sr || c)`.
543-
4. Right-shift `fn`, `sn`, and `tn` once more.
544-
7. Compare `tn` to `0`, `fr` to `node_hash`, and `sr` to `root_hash`. If any are not equal, fail the proof verification. If all are equal, accept the proof.
527+
1. Remove the first value of the `proof` array and set `fr` and `sr` to the removed value.
528+
1. For each value `c` in the `proof` array:
529+
1. If `tn` is `0`, then stop the iteration and fail the proof verification.
530+
1. If `LSB(sn)` is set, or if `sn` is equal to `tn`, then:
531+
1. If `fn < sn`, set `fr` to `HASH(0x01 || c || fr)`.
532+
1. Set `sr` to `HASH(0x01 || c || sr)`.
533+
1. Until `LSB(sn)` is set, right-shift `fn`, `sn`, and `tn` equally.
534+
1. Otherwise:
535+
1. Set `sr` to `HASH(0x01 || sr || c)`.
536+
1. Right-shift `fn`, `sn`, and `tn` once more.
537+
1. Compare `tn` to `0`, `fr` to `node_hash`, and `sr` to `root_hash`. If any are not equal, fail the proof verification. If all are equal, accept the proof.
545538

546539
## Arbitrary Intervals
547540

0 commit comments

Comments
 (0)