Giter VIP home page Giter VIP logo

merkle-proofs-verification-jsong's Introduction

Verifying a Merkle Root

Try it

Verify a Merkle Proof

Transaction Hash:

e8270fb475763bc8d855cfe45ed98060988c1bdcad2ffc8364f783c98999a208

Index:

6

Merkle Root:

4297fb95a0168b959d1469410c7527da5d6243d99699e7d041b7f3916ba93301

Merkle Proof:

9ed0a5430b5b530822b1ce1b2b9a03d513c888aaa3f028f041bf143efd8c1b92
1dc4b438b3a842bcdd46b6ea5a4aac8d66be858b0ba412578027a1f1fe838c51
156f3662b07aaa4a0d9762faaa8c18afe4c211ff92eb1eae1952aa66627bbf2e
524c93c6dd0874c5fd9e4e57cfe83176e3c2841c973afb4043d225c22cc52983
from block import Proof
from helper import double_sha256, merkle_root, merkle_path, merkle_parent

tx_hash = bytes.fromhex('e8270fb475763bc8d855cfe45ed98060988c1bdcad2ffc8364f783c98999a208')
merkle_root = bytes.fromhex('4297fb95a0168b959d1469410c7527da5d6243d99699e7d041b7f3916ba93301')
proof_hex_hashes = [
    '9ed0a5430b5b530822b1ce1b2b9a03d513c888aaa3f028f041bf143efd8c1b92',
    '1dc4b438b3a842bcdd46b6ea5a4aac8d66be858b0ba412578027a1f1fe838c51',
    '156f3662b07aaa4a0d9762faaa8c18afe4c211ff92eb1eae1952aa66627bbf2e',
    '524c93c6dd0874c5fd9e4e57cfe83176e3c2841c973afb4043d225c22cc52983',
]
proof_hashes = [bytes.fromhex(x) for x in proof_hex_hashes]
index = 6

# get the current hash (reverse tx_hash as it needs to be little endian)
# initialize the current_index to the index
# loop through proof hashes
    # if current_index is odd, proof_hash is on the left
    # if current_index is even, proof_hash is on the right
    # update current_index to be integer divide by 2
# see if the current one reversed is the same as merkle root

Test Driven Exercise

from io import BytesIO
from helper import double_sha256, merkle_root, merkle_path, merkle_parent
from block import Block, Proof

class Proof(Proof):

    def verify(self):
        '''Returns whether this proof is valid'''
        # current hash starts with self.tx_hash, reversed
        # initialize the current_index to be the index at at base level
        # Loop through proof hashes
            # if current_index is odd, proof_hash goes on left
                # current hash becomes merkle parent of proof_hash and current
            # if current_index is even, proof_hash goes on right
                # current hash becomes merkle parent of current and proof_hash
            # update the current_index to be integer divide by 2
        # if final result reversed is equal to merkle_root, return True
        pass

merkle-proofs-verification-jsong's People

Watchers

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

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.