accurate hasStandardInputs.
This commit is contained in:
parent
ae2a5fb702
commit
0720c6c64a
@ -73,6 +73,10 @@ Witness.prototype.isScripthashInput = function isScripthashInput(redeem) {
|
||||
return Script.isScripthashInput(this.items, redeem, true);
|
||||
};
|
||||
|
||||
Witness.prototype.isNonstandardInput = function isNonstandardInput(prev) {
|
||||
return Script.isNonstandardInput(this.items, prev, true);
|
||||
};
|
||||
|
||||
Witness.prototype.getRedeem = function getRedeem() {
|
||||
if (!this.redeem)
|
||||
this.redeem = Script.getRedeem(this.items);
|
||||
@ -1402,7 +1406,7 @@ Script.prototype.getType = function getType() {
|
||||
|| 'unknown';
|
||||
};
|
||||
|
||||
Script.prototype.isUnknown = function isUnknown() {
|
||||
Script.prototype.isNonstandard = function isNonstandard() {
|
||||
return this.getType() === 'unknown';
|
||||
};
|
||||
|
||||
@ -1787,8 +1791,12 @@ Script.getInputType = function getInputType(code, prev, isWitness) {
|
||||
return type;
|
||||
};
|
||||
|
||||
Script.prototype.isInputUnknown = function isInputUnknown() {
|
||||
return this.getInputType() === 'unknown';
|
||||
Script.prototype.isNonstandardInput = function isNonstandardInput(prev) {
|
||||
return Script.isNonstandardInput(this.code, prev, false);
|
||||
};
|
||||
|
||||
Script.isNonstandardInput = function isNonstandardInput(code, prev, isWitness) {
|
||||
return Script.getInputType(code, prev, isWitness) === 'unknown';
|
||||
};
|
||||
|
||||
Script.createOutputScript = function(options) {
|
||||
|
||||
@ -890,100 +890,6 @@ TX.prototype.isStandard = function isStandard(flags, ts, height, ret) {
|
||||
|
||||
// AreInputsStandard
|
||||
TX.prototype.hasStandardInputs = function hasStandardInputs(flags) {
|
||||
var maxSigops = constants.script.maxScripthashSigops;
|
||||
var i, input, args, stack, res, redeem, targs;
|
||||
|
||||
if (flags == null)
|
||||
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
||||
|
||||
if (this.isCoinbase())
|
||||
return true;
|
||||
|
||||
for (i = 0; i < this.inputs.length; i++) {
|
||||
input = this.inputs[i];
|
||||
|
||||
if (!input.coin)
|
||||
return false;
|
||||
|
||||
if ((flags & constants.flags.VERIFY_WITNESS)
|
||||
&& input.coin.script.isWitnessProgram()) {
|
||||
// Input script must be empty.
|
||||
if (input.script.code.length !== 0)
|
||||
return false;
|
||||
|
||||
// Verify the program in the output script
|
||||
if (!input.coin.script.isStandardProgram(input.witness, flags))
|
||||
return false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
args = input.coin.script.getArgs();
|
||||
|
||||
if (args < 0)
|
||||
return false;
|
||||
|
||||
// Not accurate:
|
||||
// Failsafe to avoid getting dos'd in case we ever
|
||||
// call hasStandardInputs before isStandard.
|
||||
if (!input.script.isPushOnly())
|
||||
return false;
|
||||
|
||||
stack = new Stack([]);
|
||||
|
||||
res = input.script.execute(stack, flags, this, i, 0);
|
||||
|
||||
if (!res)
|
||||
return false;
|
||||
|
||||
if ((flags & constants.flags.VERIFY_P2SH)
|
||||
&& input.coin.script.isScripthash()) {
|
||||
if (stack.length === 0)
|
||||
return false;
|
||||
|
||||
redeem = stack.getRedeem(false);
|
||||
|
||||
if (!redeem)
|
||||
return false;
|
||||
|
||||
if ((flags & constants.flags.VERIFY_WITNESS)
|
||||
&& redeem.isWitnessProgram()) {
|
||||
// Input script must be exactly one push of the redeem script.
|
||||
if (!(input.script.code.length === 1
|
||||
&& utils.isEqual(input.script.code[0], redeem.raw))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify the program in the redeem script
|
||||
if (!redeem.isStandardProgram(input.witness, flags))
|
||||
return false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (redeem.isUnknown()) {
|
||||
if (redeem.getSigops(true) > maxSigops)
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
targs = redeem.getArgs();
|
||||
|
||||
if (targs < 0)
|
||||
return false;
|
||||
|
||||
args += targs;
|
||||
}
|
||||
|
||||
if (stack.length !== args)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// AreInputsStandard (segwit branch)
|
||||
TX.prototype.hasStandardInputsWitness = function hasStandardInputsWitness(flags) {
|
||||
var maxSigops = constants.script.maxScripthashSigops;
|
||||
var i, input, stack, res, redeem;
|
||||
|
||||
@ -999,6 +905,9 @@ TX.prototype.hasStandardInputsWitness = function hasStandardInputsWitness(flags)
|
||||
if (!input.coin)
|
||||
return false;
|
||||
|
||||
if (input.coin.script.isNonstandard())
|
||||
return false;
|
||||
|
||||
if ((flags & constants.flags.VERIFY_P2SH)
|
||||
&& input.coin.script.isScripthash()) {
|
||||
// Not accurate:
|
||||
@ -1009,7 +918,7 @@ TX.prototype.hasStandardInputsWitness = function hasStandardInputsWitness(flags)
|
||||
|
||||
stack = new Stack([]);
|
||||
|
||||
res = input.script.execute(stack, flags, this, i, 0);
|
||||
res = input.script.execute(stack, constants.flags.VERIFY_NONE, this, i, 0);
|
||||
|
||||
if (!res)
|
||||
return false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user