Skip to content

Commit

Permalink
Fix 'shortest possible pushdata' logic for transaction inputs. Also a…
Browse files Browse the repository at this point in the history
…dd a testcase.
  • Loading branch information
schildbach committed May 28, 2014
1 parent 8ca8075 commit 344be21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static RuleViolation isStandard(Transaction tx) {
for (int i = 0; i < inputs.size(); i++) {
TransactionInput input = inputs.get(i);
for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
if (chunk.data != null && chunk.isShortestPossiblePushData()) {
if (chunk.data != null && !chunk.isShortestPossiblePushData()) {
log.warn("TX considered non-standard due to input {} having a longer than necessary data push: {}",
i, chunk);
return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

import com.google.bitcoin.core.*;
import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.script.ScriptBuilder;
import com.google.bitcoin.script.ScriptChunk;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;

import static com.google.bitcoin.script.ScriptOpCodes.OP_PUSHDATA1;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -141,4 +144,20 @@ public void nonStandardDust() {
edgeCaseTx.addOutput(DefaultRiskAnalysis.MIN_ANALYSIS_NONDUST_OUTPUT, key1); // Dust threshold
assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, edgeCaseTx, NO_DEPS).analyze());
}

@Test
public void nonShortestPossiblePushData() {
ScriptChunk nonStandardChunk = new ScriptChunk(OP_PUSHDATA1, new byte[75]);
byte[] nonStandardScript = new ScriptBuilder().addChunk(nonStandardChunk).build().getProgram();
// Test non-standard script as an input.
Transaction tx = new Transaction(params);
assertEquals(DefaultRiskAnalysis.RuleViolation.NONE, DefaultRiskAnalysis.isStandard(tx));
tx.addInput(new TransactionInput(params, null, nonStandardScript));
assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
// Test non-standard script as an output.
tx.clearInputs();
assertEquals(DefaultRiskAnalysis.RuleViolation.NONE, DefaultRiskAnalysis.isStandard(tx));
tx.addOutput(new TransactionOutput(params, null, Utils.COIN, nonStandardScript));
assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
}
}

0 comments on commit 344be21

Please sign in to comment.