Beispiel #1
0
def transaction_fuzz(args):
    """ Requests pending transactions from bitcoind and parses them with the
    transaction object disassemble. Uses the input hashes of these to look up
    more transactions and records and prints any failures. """
    conn = AuthServiceProxy("http://{0}:{1}@{2}:{3}/".format(args.username,
                                                             args.password,
                                                             args.address,
                                                             args.port))
    failure = 0
    success = 0
    coinbase = 0
    proc = set()
    fail = []
    unidentified = {}
    try:
        while True:
            # get new transactions from bitcoind
            trans = conn.getblocktemplate()['transactions']
            unidentified.update(
                {val['hash']: val['data'] for val in trans if val['hash'] not in proc})
            new = {}
            for hash, data in six.iteritems(unidentified):
                print("Testing transaction " + hash)
                t_obj = Transaction(unhexlify(data))
                t_obj.disassemble()
                for inp in t_obj.inputs:
                    new_hash = hexlify(inp.prevout_hash[::-1]).decode('ascii')
                    if new_hash not in proc:
                        try:
                            new[new_hash] = conn.getrawtransaction(new_hash)
                        except Exception:
                            pass
                t_obj.assemble()
                if t_obj.is_coinbase:
                    coinbase += 1
                t_obj.disassemble(t_obj._raw)
                try:
                    assert t_obj.lehexhash.decode('ascii') == hash
                except Exception:
                    failure += 1
                    fail.append(data)
                else:
                    success += 1

                proc.add(hash)

            unidentified.update(new)
            sys.stdout.write(".")
            sleep(args.sleep)
    finally:
        print()
        for f in fail:
            print("\n\n")
            print(f)
        print("Failed: %s" % failure)
        print("Coinbase: %s" % coinbase)
        print("Success: %s" % success)
Beispiel #2
0
    def test_coinbase(self):
        coinbase = Transaction()
        coinbase.version = 2
        coinbase.inputs.append(Input.coinbase(12000, b'\0' * 6))
        coinbase.outputs.append(
            Output.to_address(50000, 'D7QJyeBNuwEqxsyVCLJi3pHs64uPdMDuBa'))
        one, two = coinbase.assemble(split=True)
        one = one[:-6]

        test = Transaction(one + unhexlify('0abcdef01012') + two)
        test.disassemble()
Beispiel #3
0
    def test_coinbase(self):
        coinbase = Transaction()
        coinbase.version = 2
        coinbase.inputs.append(Input.coinbase(12000, b'\0' * 6))
        coinbase.outputs.append(
            Output.to_address(50000, 'D7QJyeBNuwEqxsyVCLJi3pHs64uPdMDuBa'))
        one, two = coinbase.assemble(split=True)
        one = one[:-6]

        test = Transaction(one + unhexlify('0abcdef01012') + two)
        test.disassemble()