Skip to content

Commit

Permalink
Merge bitcoin#7236: Use createrawtx locktime parm in txn_clone
Browse files Browse the repository at this point in the history
e279038 Use createrawtx locktime parm in txn_clone (Tom Harding)
  • Loading branch information
laanwj authored and codablock committed Dec 9, 2017
1 parent 643181f commit 8591933
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions qa/rpc-tests/txn_clone.py
Expand Up @@ -53,16 +53,10 @@ def run_test(self):
clone_inputs = [{"txid":rawtx1["vin"][0]["txid"],"vout":rawtx1["vin"][0]["vout"]}]
clone_outputs = {rawtx1["vout"][0]["scriptPubKey"]["addresses"][0]:rawtx1["vout"][0]["value"],
rawtx1["vout"][1]["scriptPubKey"]["addresses"][0]:rawtx1["vout"][1]["value"]}
clone_raw = self.nodes[0].createrawtransaction(clone_inputs, clone_outputs)
clone_locktime = rawtx1["locktime"]
clone_raw = self.nodes[0].createrawtransaction(clone_inputs, clone_outputs, clone_locktime)

# 3 hex manipulations on the clone are required

# manipulation 1. sequence is at version+#inputs+input+sigstub
posseq = 2*(4+1+36+1)
seqbe = '%08x' % rawtx1["vin"][0]["sequence"]
clone_raw = clone_raw[:posseq] + seqbe[6:8] + seqbe[4:6] + seqbe[2:4] + seqbe[0:2] + clone_raw[posseq + 8:]

# manipulation 2. createrawtransaction randomizes the order of its outputs, so swap them if necessary.
# createrawtransaction randomizes the order of its outputs, so swap them if necessary.
# output 0 is at version+#inputs+input+sigstub+sequence+#outputs
# 400 DASH serialized is 00902f5009000000
pos0 = 2*(4+1+36+1+4+1)
Expand All @@ -74,11 +68,6 @@ def run_test(self):
output1 = clone_raw[pos0 + output_len : pos0 + 2 * output_len]
clone_raw = clone_raw[:pos0] + output1 + output0 + clone_raw[pos0 + 2 * output_len:]

# manipulation 3. locktime is after outputs
poslt = pos0 + 2 * output_len
ltbe = '%08x' % rawtx1["locktime"]
clone_raw = clone_raw[:poslt] + ltbe[6:8] + ltbe[4:6] + ltbe[2:4] + ltbe[0:2] + clone_raw[poslt + 8:]

# Use a different signature hash type to sign. This creates an equivalent but malleated clone.
# Don't send the clone anywhere yet
tx1_clone = self.nodes[0].signrawtransaction(clone_raw, None, None, "ALL|ANYONECANPAY")
Expand Down

0 comments on commit 8591933

Please sign in to comment.