From 56fd91b9f962d01092e4b9c1bf1357b990d68f50 Mon Sep 17 00:00:00 2001 From: Cayman Date: Tue, 1 Oct 2019 11:23:03 -0500 Subject: [PATCH 1/2] merkle proofs: Fix get_helper_indices --- specs/light_client/merkle_proofs.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/specs/light_client/merkle_proofs.md b/specs/light_client/merkle_proofs.md index b920f50b1..b021f1ac0 100644 --- a/specs/light_client/merkle_proofs.md +++ b/specs/light_client/merkle_proofs.md @@ -258,6 +258,18 @@ def get_branch_indices(tree_index: GeneralizedIndex) -> Sequence[GeneralizedInde return o[:-1] ``` +```python +def get_path_indices(tree_index: GeneralizedIndex) -> Sequence[GeneralizedIndex]: + """ + Get the generalized indices of the chunks along the path from the chunk with the + given tree index to the root. + """ + o = [tree_index] + while o[-1] > 1: + o.append(generalized_index_parent(o[-1])) + return o[:-1] +``` + ```python def get_helper_indices(indices: Sequence[GeneralizedIndex]) -> Sequence[GeneralizedIndex]: """ @@ -265,17 +277,14 @@ def get_helper_indices(indices: Sequence[GeneralizedIndex]) -> Sequence[Generali generalized indices. Note that the decreasing order is chosen deliberately to ensure equivalence to the order of hashes in a regular single-item Merkle proof in the single-item case. """ - all_indices: Set[GeneralizedIndex] = set() + all_helper_indices: Set[GeneralizedIndex] = set() + all_path_indices: Set[GeneralizedIndex] = set() for index in indices: - all_indices = all_indices.union(set(list(get_branch_indices(index)) + [index])) + all_helper_indices = all_helper_indices.union(set(get_branch_indices(index))) + all_path_indices = all_path_indices.union(set(get_path_indices(index))) return sorted([ - x for x in all_indices if ( - not ( - generalized_index_child(x, False) in all_indices and - generalized_index_child(x, True) in all_indices - ) and not (x in indices) - ) + x for x in all_helper_indices if x not in all_path_indices ], reverse=True) ``` From a9961d4ce46d0653dd5d2e18a597282a54b905ca Mon Sep 17 00:00:00 2001 From: Cayman Date: Fri, 18 Oct 2019 03:38:06 -0500 Subject: [PATCH 2/2] Simplify get_helper_indices --- specs/light_client/merkle_proofs.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/specs/light_client/merkle_proofs.md b/specs/light_client/merkle_proofs.md index b021f1ac0..f6c77fffb 100644 --- a/specs/light_client/merkle_proofs.md +++ b/specs/light_client/merkle_proofs.md @@ -283,9 +283,7 @@ def get_helper_indices(indices: Sequence[GeneralizedIndex]) -> Sequence[Generali all_helper_indices = all_helper_indices.union(set(get_branch_indices(index))) all_path_indices = all_path_indices.union(set(get_path_indices(index))) - return sorted([ - x for x in all_helper_indices if x not in all_path_indices - ], reverse=True) + return sorted(all_helper_indices.difference(all_path_indices), reverse=True) ``` Now we provide the Merkle proof verification functions. First, for single item proofs: