script: do not pass flags to Script.num.
This commit is contained in:
parent
8893131e08
commit
30b8a458ed
@ -705,27 +705,24 @@ exports.formatStackASM = function formatStackASM(items, decode) {
|
||||
/**
|
||||
* Create a CScriptNum.
|
||||
* @param {Buffer} value
|
||||
* @param {Number?} flags - Script standard flags.
|
||||
* @param {Boolean?} minimal
|
||||
* @param {Number?} size - Max size in bytes.
|
||||
* @returns {BN}
|
||||
* @throws {ScriptError}
|
||||
*/
|
||||
|
||||
exports.num = function num(value, flags, size) {
|
||||
exports.num = function num(value, minimal, size) {
|
||||
var result;
|
||||
|
||||
assert(Buffer.isBuffer(value));
|
||||
|
||||
if (flags == null)
|
||||
flags = exports.flags.STANDARD_VERIFY_FLAGS;
|
||||
|
||||
if (size == null)
|
||||
size = 4;
|
||||
|
||||
if (value.length > size)
|
||||
throw new exports.ScriptError('UNKNOWN_ERROR', 'Script number overflow.');
|
||||
|
||||
if ((flags & exports.flags.VERIFY_MINIMALDATA) && value.length > 0) {
|
||||
if (minimal && value.length > 0) {
|
||||
// If the low bits on the last byte are unset,
|
||||
// fail if the value's second to last byte does
|
||||
// not have the high bit set. A number can't
|
||||
|
||||
@ -694,7 +694,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length === 0)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
locktime = Script.num(stack.top(-1), flags, 5);
|
||||
locktime = Script.num(stack.top(-1), minimal, 5);
|
||||
|
||||
if (locktime.cmpn(0) < 0)
|
||||
throw new ScriptError('NEGATIVE_LOCKTIME', op, ip);
|
||||
@ -720,7 +720,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length === 0)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
locktime = Script.num(stack.top(-1), flags, 5);
|
||||
locktime = Script.num(stack.top(-1), minimal, 5);
|
||||
|
||||
if (locktime.cmpn(0) < 0)
|
||||
throw new ScriptError('NEGATIVE_LOCKTIME', op, ip);
|
||||
@ -882,7 +882,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length < 2)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
num = Script.num(stack.top(-1), flags).toNumber();
|
||||
num = Script.num(stack.top(-1), minimal).toNumber();
|
||||
stack.pop();
|
||||
|
||||
if (num < 0 || num >= stack.length)
|
||||
@ -963,7 +963,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length < 1)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
num = Script.num(stack.top(-1), flags);
|
||||
num = Script.num(stack.top(-1), minimal);
|
||||
|
||||
switch (op) {
|
||||
case opcodes.OP_1ADD:
|
||||
@ -1024,8 +1024,8 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length < 2)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
n1 = Script.num(stack.top(-2), flags);
|
||||
n2 = Script.num(stack.top(-1), flags);
|
||||
n1 = Script.num(stack.top(-2), minimal);
|
||||
n2 = Script.num(stack.top(-1), minimal);
|
||||
|
||||
switch (op) {
|
||||
case opcodes.OP_ADD:
|
||||
@ -1118,9 +1118,9 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length < 3)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
n1 = Script.num(stack.top(-3), flags);
|
||||
n2 = Script.num(stack.top(-2), flags);
|
||||
n3 = Script.num(stack.top(-1), flags);
|
||||
n1 = Script.num(stack.top(-3), minimal);
|
||||
n2 = Script.num(stack.top(-2), minimal);
|
||||
n3 = Script.num(stack.top(-1), minimal);
|
||||
|
||||
val = n2.cmp(n1) <= 0 && n1.cmp(n3) < 0;
|
||||
|
||||
@ -1223,7 +1223,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length < i)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
n = Script.num(stack.top(-i), flags).toNumber();
|
||||
n = Script.num(stack.top(-i), minimal).toNumber();
|
||||
ikey2 = n + 2;
|
||||
|
||||
if (!(n >= 0 && n <= consensus.MAX_MULTISIG_PUBKEYS))
|
||||
@ -1241,7 +1241,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length < i)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
m = Script.num(stack.top(-i), flags).toNumber();
|
||||
m = Script.num(stack.top(-i), minimal).toNumber();
|
||||
|
||||
if (!(m >= 0 && m <= n))
|
||||
throw new ScriptError('SIG_COUNT', op, ip);
|
||||
@ -1334,8 +1334,8 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
v1 = stack.top(-3);
|
||||
v2 = Script.num(stack.top(-2), flags).toNumber();
|
||||
v3 = Script.num(stack.top(-1), flags).toNumber();
|
||||
v2 = Script.num(stack.top(-2), minimal).toNumber();
|
||||
v3 = Script.num(stack.top(-1), minimal).toNumber();
|
||||
|
||||
if (v2 < 0 || v3 < v2)
|
||||
throw new ScriptError('UNKNOWN_ERROR', 'String out of range.');
|
||||
@ -1358,7 +1358,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
v1 = stack.top(-2);
|
||||
v2 = Script.num(stack.top(-1), flags).toNumber();
|
||||
v2 = Script.num(stack.top(-1), minimal).toNumber();
|
||||
|
||||
if (v2 < 0)
|
||||
throw new ScriptError('UNKNOWN_ERROR', 'String size out of range.');
|
||||
@ -1470,14 +1470,14 @@ Script.bool = function bool(value) {
|
||||
/**
|
||||
* Create a CScriptNum.
|
||||
* @param {Buffer} value
|
||||
* @param {Number?} flags - Script standard flags.
|
||||
* @param {Boolean?} minimal
|
||||
* @param {Number?} size - Max size in bytes.
|
||||
* @returns {BN}
|
||||
* @throws {ScriptError}
|
||||
*/
|
||||
|
||||
Script.num = function num(value, flags, size) {
|
||||
return common.num(value, flags, size);
|
||||
Script.num = function num(value, minimal, size) {
|
||||
return common.num(value, minimal, size);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2498,7 +2498,6 @@ Script.prototype.getCoinbaseHeight = function getCoinbaseHeight() {
|
||||
*/
|
||||
|
||||
Script.getCoinbaseHeight = function getCoinbaseHeight(raw) {
|
||||
var flags = Script.flags.STANDARD_VERIFY_FLAGS;
|
||||
var data, height, op;
|
||||
|
||||
if (raw.length === 0)
|
||||
@ -2524,7 +2523,7 @@ Script.getCoinbaseHeight = function getCoinbaseHeight(raw) {
|
||||
|
||||
// Deserialize the height.
|
||||
try {
|
||||
height = Script.num(data, flags, 6);
|
||||
height = Script.num(data, true, 6);
|
||||
} catch (e) {
|
||||
return -1;
|
||||
}
|
||||
@ -2689,7 +2688,7 @@ Script.prototype.getNumber = function getNumber(i) {
|
||||
if (!op || !op.data || op.data.length > 5)
|
||||
return null;
|
||||
|
||||
return Script.num(op.data, Script.flags.VERIFY_NONE, 5);
|
||||
return Script.num(op.data, false, 5);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -511,7 +511,7 @@ Witness.prototype.getNumber = function getNumber(i) {
|
||||
var item = this.items[i];
|
||||
if (!item || item.length > 5)
|
||||
return;
|
||||
return common.num(item, common.flags.VERIFY_NONE, 5);
|
||||
return common.num(item, false, 5);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user