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