示例#1
0
 def create_transaction(self, node, coinbase, to_address, amount):
     from_txid = node.getblock(coinbase)['tx'][0]
     inputs = [{"txid": from_txid, "vout": 0}]
     outputs = {to_address: amount}
     rawtx = node.createrawtransaction(inputs, outputs)
     signresult = node.signrawtransaction(rawtx)
     tx = CTransaction()
     f = cStringIO.StringIO(unhexlify(signresult['hex']))
     tx.deserialize(f)
     return tx
示例#2
0
 def create_transaction(self, node, coinbase, to_address, amount):
     from_txid = node.getblock(coinbase)['tx'][0]
     inputs = [{ "txid" : from_txid, "vout" : 0}]
     outputs = { to_address : amount }
     rawtx = node.createrawtransaction(inputs, outputs)
     signresult = node.signrawtransaction(rawtx)
     tx = CTransaction()
     f = cStringIO.StringIO(unhexlify(signresult['hex']))
     tx.deserialize(f)
     return tx
示例#3
0
 def get(self, txhash):
     serialized_tx = None
     try:
         serialized_tx = self.txDB[repr(txhash)]
     except KeyError:
         return None
     f = cStringIO.StringIO(serialized_tx)
     ret = CTransaction()
     ret.deserialize(f)
     ret.calc_sha256()
     return ret
示例#4
0
 def get(self, txhash):
     serialized_tx = None
     try:
         serialized_tx = self.txDB[repr(txhash)]
     except KeyError:
         return None
     f = cStringIO.StringIO(serialized_tx)
     ret = CTransaction()
     ret.deserialize(f)
     ret.calc_sha256()
     return ret
示例#5
0
def create_tampered_rawtx_cbh(node_from, node_to, tx_amount, fee, mode):

    genesis_block_hash = node_from.getblock(str(0))['hash']

    # select necessary UTXOs
    usp = node_from.listunspent()
    assert (len(usp) != 0)

    amount = Decimal('0')
    inputs = []

    for x in usp:
        amount += Decimal(x['amount'])
        inputs.append({"txid": x['txid'], "vout": x['vout']})
        if amount >= tx_amount + fee:
            break

    outputs = {
        node_from.getnewaddress(): (Decimal(amount) - tx_amount - fee),
        node_to.getnewaddress(): tx_amount
    }
    rawTx = node_from.createrawtransaction(inputs, outputs)

    # build an object from the raw Tx in order to be able to modify it
    tx_01 = CTransaction()
    f = StringIO(unhexlify(rawTx))
    tx_01.deserialize(f)

    # corrupt vouts in this Tx
    for vout_idx in range(len(tx_01.vout)):
        decodedScriptOrig = node_from.decodescript(
            hexlify(tx_01.vout[vout_idx].scriptPubKey))

        scriptOrigAsm = decodedScriptOrig['asm']
        params = scriptOrigAsm.split()
        hash160 = hex_str_to_bytes(params[2])
        original_height = int(params[6])
        original_hash = hex_str_to_bytes(params[5])

        if mode == MODE_HEIGHT:
            # new referenced block height
            evil_height = -1
            # new referenced block hash
            modTargetHash = hex_str_to_bytes(swap_bytes(genesis_block_hash))
            # build modified script: CScript is putting a 4f (OP_NEGATE) for our -1
            # edit script.py to send different stuff for the -1 value (like ff itself!)
            modScriptPubKey = CScript([
                OP_DUP, OP_HASH160, hash160, OP_EQUALVERIFY, OP_CHECKSIG,
                modTargetHash, evil_height, OP_CHECKBLOCKATHEIGHT
            ])
        elif mode == MODE_SWAP_ARGS:
            modScriptPubKey = CScript([
                OP_DUP, OP_HASH160, hash160, OP_EQUALVERIFY, OP_CHECKSIG,
                original_height, original_hash, OP_CHECKBLOCKATHEIGHT
            ])
        elif mode == MODE_NON_MIN_ENC:
            non_min_h = hex_str_to_bytes("07000000")
            modScriptPubKey = CScript([
                OP_DUP, OP_HASH160, hash160, OP_EQUALVERIFY, OP_CHECKSIG,
                original_hash, non_min_h, OP_CHECKBLOCKATHEIGHT
            ])
        else:
            assert (False)

        tx_01.vout[vout_idx].scriptPubKey = modScriptPubKey

    tx_01.rehash()
    signedRawTx = node_from.signrawtransaction(ToHex(tx_01))
    return signedRawTx