Esempio n. 1
0
    def verify_chain(self, chain):

        first_header = chain[0]
        prev_header = self.read_header(first_header.get('block_height') - 1)

        for header in chain:

            height = header.get('block_height')

            prev_hash = self.hash_header(prev_header)
            bits, target = self.get_target(height, chain)
            _hash = self.hash_header(header)
            pow_hash = _hash

            try:
                if height >= 45000 and header['version'] == 196865:
                    assert auxpow.verify(_hash, auxpow.get_our_chain_id(),
                                         header['auxpow'])
                    pow_hash = self.hash_header(
                        header['auxpow']['parent_block'])
                assert prev_hash == header.get('prev_block_hash')
                assert bits == header.get('bits')
                assert int('0x' + pow_hash, 16) < target
            except Exception:
                print traceback.format_exc()
                print 'error validating chain at height ', height
                print 'block ', height, '(', _hash, ') failed validation'
                pprint.pprint(header)
                return False

            prev_header = header

        return True
    def verify_chain(self, chain):

        first_header = chain[0]
        prev_header = self.read_header(first_header.get('block_height') -1)

        for header in chain:

            height = header.get('block_height')

            prev_hash = self.hash_header(prev_header)
            bits, target = self.get_target(height, chain)
            _hash = self.hash_header(header)
            pow_hash = _hash

            try:
                if height >= 45000 and header['version'] == 196865:
                    assert auxpow.verify(_hash, auxpow.get_our_chain_id(), header['auxpow'])
                    pow_hash = self.hash_header(header['auxpow']['parent_block'])
                assert prev_hash == header.get('prev_block_hash')
                assert bits == header.get('bits')
                assert int('0x'+pow_hash,16) < target
            except Exception:
                print traceback.format_exc()
                print 'error validating chain at height ', height
                print 'block ', height, '(',_hash,') failed validation'
                pprint.pprint(header)
                return False

            prev_header = header

        return True
Esempio n. 3
0
    def verify_chain(self, chain):

        first_header = chain[0]
        prev_header = self.read_header(first_header.get('block_height') - 1)

        for header in chain:

            height = header.get('block_height')

            prev_hash = self.hash_header(prev_header)
            bits, target = self.get_target(height, chain)
            _hash = self.hash_header(header)
            pow_hash = self.pow_hash_header(header)

            try:
                # todo: dogecoin auxpow block version
                if height >= auxpow_start and header['version'] == 6422786:
                    assert auxpow.verify(_hash, auxpow.get_our_chain_id(), header['auxpow'])
                    pow_hash = self.pow_hash_header(header['auxpow']['parent_block'])
                assert prev_hash == header.get('prev_block_hash')
                assert bits == header.get('bits')
                assert int('0x'+pow_hash,16) < target
            except Exception:
                print traceback.format_exc()
                print 'error validating chain at height ', height
                print 'block ', height, '(',_hash,') failed validation'
                pprint.pprint(header)
                print hex(bits), '==', hex(header.get('bits'))
                print int('0x'+pow_hash,16), '<', target
                return False

            prev_header = header

        return True
    def verify_chain(self, chain):

        first_header = chain[0]
        prev_header = self.read_header(first_header.get('block_height') - 1)

        for header in chain:

            height = header.get('block_height')

            prev_hash = self.hash_header(prev_header)
            bits, target = self.get_target(height, chain)
            _hash = self.hash_header(header)
            pow_hash = self.pow_hash_header(header)

            try:
                # todo: dogecoin auxpow block version
                if height >= auxpow_start and header['version'] == 6422786:
                    assert auxpow.verify(_hash, auxpow.get_our_chain_id(),
                                         header['auxpow'])
                    pow_hash = self.pow_hash_header(
                        header['auxpow']['parent_block'])
                assert prev_hash == header.get('prev_block_hash')
                assert bits == header.get('bits')
                assert int('0x' + pow_hash, 16) < target
            except Exception:
                print traceback.format_exc()
                print 'error validating chain at height ', height
                print 'block ', height, '(', _hash, ') failed validation'
                pprint.pprint(header)
                print hex(bits), '==', hex(header.get('bits'))
                print int('0x' + pow_hash, 16), '<', target
                return False

            prev_header = header

        return True
Esempio n. 5
0
    def verify_chunk(self, index, hexdata):
        hex_to_int = lambda s: int('0x' + s[::-1].encode('hex'), 16)

        data = hexdata.decode('hex')
        disk_data = ''
        height = index * 2016
        num = hex_to_int(data[0:4])
        data = data[4:]

        auxpowdata = data[num * 88:]
        auxpowbaseoffset = 0

        if index == 0:
            previous_hash = ("0" * 64)
        else:
            prev_header = self.read_header(index * 2016 - 1)
            if prev_header is None: raise
            previous_hash = self.hash_header(prev_header)

        bits, target = self.get_target(height)

        chain = []
        for i in range(num):
            height = index * 2016 + i

            raw_header = data[i * 88:(i + 1) * 88]
            disk_data += raw_header[0:80]  # strip auxpow data

            header = self.header_from_string(raw_header)
            _hash = self.hash_header(header)
            _prev_hash = _hash
            header['block_height'] = height

            if (i == 0):
                auxpowbaseoffset = header['auxpow_offset']

            start = header['auxpow_offset'] - auxpowbaseoffset
            end = start + header['auxpow_length']

            if (end > start):
                header['auxpow'] = self.auxpow_from_string(
                    auxpowdata[start:end].decode('hex'))
                #print header['auxpow']

            if height >= 20160 and (height % 144) == 0:
                #print height , '%', 144 , '=', height % 144
                bits, target = self.get_target(height, chain)

            if height >= 45000 and header[
                    'version'] == 196865:  #TODO getAuxPowVersion()
                #todo: check that auxpow.get_chain_id(header) == auxpow.get_our_chain_id?
                #print header['auxpow']
                try:
                    assert auxpow.verify(_hash, auxpow.get_our_chain_id(),
                                         header['auxpow'])
                except Exception as e:
                    print traceback.format_exc()
                    print 'block ', height, '(', _hash, ') failed validation'
                    print 'auxpow failed verification'
                    pp.pprint(header['auxpow'])
                    raise e
                #pp.pprint(header)
                #pp.pprint(parent_header)
                _hash = self.hash_header(header['auxpow']['parent_block'])
                #print _hash
                # todo: verify auxpow data
                #_hash = '' # auxpow.getHash()

            try:
                assert previous_hash == header.get('prev_block_hash')
                assert bits == header.get('bits')
                assert int('0x' + _hash, 16) < target
            except Exception as e:
                print 'block ', height, ' failed validation'
                raise e

            if height % 144 == 0:
                print 'block ', height, ' validated'

            chain.append(header)
            previous_header = header
            previous_hash = _prev_hash

        self.save_chunk(index, disk_data)
        print_error("validated chunk %d" % height)
    def verify_chunk(self, index, hexdata):
        hex_to_int = lambda s: int('0x' + s[::-1].encode('hex'), 16)

        data = hexdata.decode('hex')
        disk_data = ''
        height = index * 2016
        num = hex_to_int(data[0:4])
        data = data[4:]

        auxpowdata = data[num*88:]
        auxpowbaseoffset = 0

        if index == 0:
            previous_hash = ("0"*64)
        else:
            prev_header = self.read_header(index*2016-1)
            if prev_header is None: raise
            previous_hash = self.hash_header(prev_header)


        bits, target = self.get_target(height)

        chain = []
        for i in range(num):
            height = index * 2016 + i

            raw_header = data[i*88:(i+1)*88]
            disk_data += raw_header[0:80] # strip auxpow data

            header = self.header_from_string(raw_header)
            _hash = self.hash_header(header)
            _prev_hash = _hash
            header['block_height'] = height

            if (i == 0):
               auxpowbaseoffset = header['auxpow_offset']

            start = header['auxpow_offset'] - auxpowbaseoffset
            end = start + header['auxpow_length']

            if (end > start):
                header['auxpow'] = self.auxpow_from_string(auxpowdata[start:end].decode('hex'))
                #print header['auxpow']

            if height >= 20160 and (height % 144) == 0:
                #print height , '%', 144 , '=', height % 144
                bits, target = self.get_target(height, chain)


            if height >= 45000 and header['version'] == 196865: #TODO getAuxPowVersion()
                #todo: check that auxpow.get_chain_id(header) == auxpow.get_our_chain_id?
                #print header['auxpow']
                try:
                    assert auxpow.verify(_hash, auxpow.get_our_chain_id(), header['auxpow'])
                except Exception as e:
                    print traceback.format_exc()
                    print 'block ', height, '(',_hash,') failed validation'
                    print 'auxpow failed verification'
                    pp.pprint(header['auxpow'])
                    raise e
                #pp.pprint(header)
                #pp.pprint(parent_header)
                _hash = self.hash_header(header['auxpow']['parent_block'])
                #print _hash
                # todo: verify auxpow data
                #_hash = '' # auxpow.getHash()

            try:
                assert previous_hash == header.get('prev_block_hash')
                assert bits == header.get('bits')
                assert int('0x'+_hash,16) < target
            except Exception as e:
                print 'block ', height, ' failed validation'
                raise e

            if height % 144 == 0:
                print 'block ', height, ' validated'

            chain.append(header)
            previous_header = header
            previous_hash = _prev_hash

        self.save_chunk(index, disk_data)
        print_error("validated chunk %d"%height)