mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 03:35:52 +00:00
Fix 'shortest possible pushdata' logic for transaction inputs. Also add a testcase.
This commit is contained in:
parent
8ca8075a7b
commit
344be21821
@ -144,7 +144,7 @@ public class DefaultRiskAnalysis implements RiskAnalysis {
|
|||||||
for (int i = 0; i < inputs.size(); i++) {
|
for (int i = 0; i < inputs.size(); i++) {
|
||||||
TransactionInput input = inputs.get(i);
|
TransactionInput input = inputs.get(i);
|
||||||
for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
|
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: {}",
|
log.warn("TX considered non-standard due to input {} having a longer than necessary data push: {}",
|
||||||
i, chunk);
|
i, chunk);
|
||||||
return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
|
return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
|
||||||
|
@ -21,10 +21,13 @@ import java.math.BigInteger;
|
|||||||
|
|
||||||
import com.google.bitcoin.core.*;
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.bitcoin.params.MainNetParams;
|
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 com.google.common.collect.ImmutableList;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static com.google.bitcoin.script.ScriptOpCodes.OP_PUSHDATA1;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@ -141,4 +144,20 @@ public class DefaultRiskAnalysisTest {
|
|||||||
edgeCaseTx.addOutput(DefaultRiskAnalysis.MIN_ANALYSIS_NONDUST_OUTPUT, key1); // Dust threshold
|
edgeCaseTx.addOutput(DefaultRiskAnalysis.MIN_ANALYSIS_NONDUST_OUTPUT, key1); // Dust threshold
|
||||||
assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, edgeCaseTx, NO_DEPS).analyze());
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user