Skip to content
This repository has been archived by the owner on Dec 3, 2018. It is now read-only.

Create proofs for slices of leaves #15

Open
starius opened this issue Aug 2, 2017 · 0 comments · May be fixed by #17
Open

Create proofs for slices of leaves #15

starius opened this issue Aug 2, 2017 · 0 comments · May be fixed by #17

Comments

@starius
Copy link
Contributor

starius commented Aug 2, 2017

It can be used in Metadata Request (to provide a proof for a slice of sector ids) and in Data Request (to provide a proof that a slice of bytes inside a sector belongs to the sector).

The algorithm to make proofs can be adjusted to work with slices instead of single index: just replace "subtree containing the proofIndex" with "subtree overlapping with the proofSlice" in the original algorithm. The new algorithm produces exactly the same proofs for a slice of size 1 as the old one provides for the corresponding proofIndex. That means that the new algorithm is backward compatible.

Here is a demonstration script in Python, which prints proof as a list of slices of leaves.

proofSlice = (3, 5)
numLeaves = 7

def size(st):
    return st[1] - st[0]

def inside(point, st):
    return st[0] <= point < st[1]

def overlaps(st):
    return inside(st[0], proofSlice) or inside(proofSlice[0], st)

stack = []

def combine():
    right = stack.pop()
    left = stack.pop()
    if overlaps(right) and not overlaps(left):
        print(left)
    if overlaps(left) and not overlaps(right):
        print(right)
    st2 = (left[0], right[1])
    stack.append(st2)

for i in range(numLeaves):
    st = (i, i+1)
    stack.append(st)
    while len(stack) > 1 and size(stack[-2]) == size(stack[-1]):
        combine()
while len(stack) > 1:
    combine()
starius added a commit to starius/merkletree that referenced this issue Sep 1, 2017
This text was written with slices of leaves in mind
NebulousLabs#15
@starius starius linked a pull request Sep 1, 2017 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant