mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 14:50:57 +01:00
Fix a bug in the BIP 62 handling code that can cause a crash for any broadcast multisig transaction.
This commit is contained in:
parent
199a741850
commit
b7bac50fa1
2 changed files with 25 additions and 2 deletions
|
@ -81,6 +81,8 @@ public class ScriptChunk {
|
||||||
*/
|
*/
|
||||||
public boolean isShortestPossiblePushData() {
|
public boolean isShortestPossiblePushData() {
|
||||||
checkState(isPushData());
|
checkState(isPushData());
|
||||||
|
if (data == null)
|
||||||
|
return true; // OP_N
|
||||||
if (data.length == 0)
|
if (data.length == 0)
|
||||||
return opcode == OP_0;
|
return opcode == OP_0;
|
||||||
if (data.length == 1) {
|
if (data.length == 1) {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.bitcoinj.wallet;
|
package org.bitcoinj.wallet;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.bitcoinj.core.*;
|
import org.bitcoinj.core.*;
|
||||||
import org.bitcoinj.params.MainNetParams;
|
import org.bitcoinj.params.MainNetParams;
|
||||||
import org.bitcoinj.script.ScriptBuilder;
|
import org.bitcoinj.script.ScriptBuilder;
|
||||||
|
@ -38,7 +39,7 @@ public class DefaultRiskAnalysisTest {
|
||||||
private static final NetworkParameters params = MainNetParams.get();
|
private static final NetworkParameters params = MainNetParams.get();
|
||||||
private Wallet wallet;
|
private Wallet wallet;
|
||||||
private final int TIMESTAMP = 1384190189;
|
private final int TIMESTAMP = 1384190189;
|
||||||
private ECKey key1;
|
private static final ECKey key1 = new ECKey();
|
||||||
private final ImmutableList<Transaction> NO_DEPS = ImmutableList.of();
|
private final ImmutableList<Transaction> NO_DEPS = ImmutableList.of();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -54,7 +55,6 @@ public class DefaultRiskAnalysisTest {
|
||||||
return TIMESTAMP;
|
return TIMESTAMP;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
key1 = new ECKey();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -161,4 +161,25 @@ public class DefaultRiskAnalysisTest {
|
||||||
tx.addOutput(new TransactionOutput(params, null, COIN, nonStandardScript));
|
tx.addOutput(new TransactionOutput(params, null, COIN, nonStandardScript));
|
||||||
assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
|
assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void standardOutputs() throws Exception {
|
||||||
|
Transaction tx = new Transaction(params);
|
||||||
|
tx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0));
|
||||||
|
// A pay to address output
|
||||||
|
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1.toAddress(params)));
|
||||||
|
// A pay to pubkey output
|
||||||
|
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1));
|
||||||
|
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1));
|
||||||
|
// 1-of-2 multisig output.
|
||||||
|
ImmutableList<ECKey> keys = ImmutableList.of(key1, new ECKey());
|
||||||
|
tx.addOutput(Coin.CENT, ScriptBuilder.createMultiSigOutputScript(1, keys));
|
||||||
|
// 2-of-2 multisig output.
|
||||||
|
tx.addOutput(Coin.CENT, ScriptBuilder.createMultiSigOutputScript(2, keys));
|
||||||
|
// P2SH
|
||||||
|
tx.addOutput(Coin.CENT, ScriptBuilder.createP2SHOutputScript(1, keys));
|
||||||
|
// OP_RETURN
|
||||||
|
tx.addOutput(Coin.CENT, ScriptBuilder.createOpReturnScript("hi there".getBytes()));
|
||||||
|
assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS).analyze());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue