Code Monkey home page Code Monkey logo

merkletree's People

Contributors

chrisschinnerl avatar davidvorick avatar edwardbetts avatar golint-fixer avatar lukechampine avatar starius avatar voidingwarranties avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

merkletree's Issues

Expanded Testing

There are a few sanity checks that could be inserted to verify consistency. There are also a few other manual tests I would like to write to make sure that the complexity of the testing exceeds the complexity of the code.

errcheck

We should be runinng errcheck. This might cause some grief.
I'm not sure what the best approach to errcheck is, but we definitely have missed a few bugs that would have been caught had we been using errcheck.

But there are also lots of examples of harmless failures in errcheck, it's not clear whether we should be rigorous or find some way to explicitly ignore certain errcheck warnings.

Create a test for incomplete proofs

An incomplete proof is any time that the index is greater than the numLeaves. Not testing this case resulted in a bug, caught by fuzzing. The bug has now been fixed but there's not an explicit test exploring incomplete proofs.

Create proofs for slices of leaves

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.