diff --git a/core/src/main/java/com/google/bitcoin/script/Script.java b/core/src/main/java/com/google/bitcoin/script/Script.java index a5f2c17e..26cc3efe 100644 --- a/core/src/main/java/com/google/bitcoin/script/Script.java +++ b/core/src/main/java/com/google/bitcoin/script/Script.java @@ -1168,6 +1168,13 @@ public class Script { */ public void correctlySpends(Transaction txContainingThis, long scriptSigIndex, Script scriptPubKey, boolean enforceP2SH) throws ScriptException { + // Clone the transaction because executing the script involves editing it, and if we die, we'll leave + // the tx half broken (also it's not so thread safe to work on it directly. + try { + txContainingThis = new Transaction(txContainingThis.getParams(), txContainingThis.bitcoinSerialize()); + } catch (ProtocolException e) { + throw new RuntimeException(e); // Should not happen unless we were given a totally broken transaction. + } if (getProgram().length > 10000 || scriptPubKey.getProgram().length > 10000) throw new ScriptException("Script larger than 10,000 bytes");