Exemple #1
0
def perform(shard, leaves, seed, size=0, offset=0):
    response = store.shard.get_hash_hex(shard, hex_salt=seed,
                                        size=size, offset=offset)
    leaf = util.hash_hex(response)
    assert(leaf in leaves)
    challengenum = leaves.index(leaf)
    width = util.next_power_of_two(len(leaves))
    proof = leaves + [util.hash_hex("") for x in range(width - len(leaves))]
    proof[challengenum] = [response]
    return trim(proof, challengenum)
Exemple #2
0
def validate(proof, root, challengenum, leaves):
    """ Validate an audit proof is for a given root and challange.

    Args:
        proof: The proof to be validated.
        root: The merkle root the proof must be for.
        challengenum: The leaf the proof must be for.
        leaves: All audit leaves (to ensure proof is not for other leaves).

    Retruns:
        True if the proof is correct.
    """
    width = util.next_power_of_two(len(leaves))
    depth = util.perfect_binary_tree_depth(width)
    leaf = leaves[challengenum]
    try:
        return root == collapse(proof, leaf, depth)
    except AssertionError:
        return False  # incorrect proof or proof format