Skip to content

Commit ddafe78

Browse files
authored
Merge pull request #149 from davidben/unify-consistency
Unify the two branches in the consistency proof check
2 parents edbcb0a + 27988ca commit ddafe78

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

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

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -516,32 +516,26 @@ 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. Check that `[start, end)` is a valid subtree ({{definition-of-a-subtree}}), and that `end <= n`. If either do not hold, fail proof verification. These checks imply `0 <= start < end <= end`.
520+
1. Set `fn` to `start`, `sn` to `end - 1`, and `tn` to `n - 1`.
521+
1. If `sn` is `tn`, then:
522+
1. Until `fn` is `sn`, right-shift `fn`, `sn`, and `tn` equally.
523+
1. Otherwise:
524+
1. Until `LSB(sn)` is not set or `fn` is `sn`, right-shift `fn`, `sn`, and `tn` equally.
525+
1. If `fn` is `sn`, set `fr` and `sr` to `node_hash`.
526+
1. Otherwise:
530527
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.
528+
1. Remove the first value of the `proof` array and set `fr` and `sr` to the removed value.
529+
1. For each value `c` in the `proof` array:
530+
1. If `tn` is `0`, then stop the iteration and fail the proof verification.
531+
1. If `LSB(sn)` is set, or if `sn` is equal to `tn`, then:
532+
1. If `fn < sn`, set `fr` to `HASH(0x01 || c || fr)`.
533+
1. Set `sr` to `HASH(0x01 || c || sr)`.
534+
1. Until `LSB(sn)` is set, right-shift `fn`, `sn`, and `tn` equally.
535+
1. Otherwise:
536+
1. Set `sr` to `HASH(0x01 || sr || c)`.
537+
1. Right-shift `fn`, `sn`, and `tn` once more.
538+
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.
545539

546540
## Arbitrary Intervals
547541

0 commit comments

Comments
 (0)