disabled opcodes fixes.

This commit is contained in:
Christopher Jeffrey 2016-04-17 08:45:37 -07:00
parent 0a621238ba
commit 4960e48b48
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1529,33 +1529,33 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
case opcodes.OP_SUBSTR: { case opcodes.OP_SUBSTR: {
if (stack.length < 3) if (stack.length < 3)
throw new ScriptError('Stack too small.', op, ip); throw new ScriptError('Stack too small.', op, ip);
v1 = Script.num(stack.pop(), flags).toNumber(); // end v3 = Script.num(stack.pop(), flags).toNumber(); // end
v2 = Script.num(stack.pop(), flags).toNumber(); // begin v2 = Script.num(stack.pop(), flags).toNumber(); // begin
v3 = stack.pop(); // string v1 = stack.pop(); // string
if (v2 < 0 || v1 < v2) if (v2 < 0 || v3 < v2)
throw new ScriptError('String begin and end out of range.', op, ip); throw new ScriptError('String begin and end out of range.', op, ip);
if (v2 > v3.length) if (v2 > v1.length)
v2 = v3.length; v2 = v1.length;
if (v1 > v3.length) if (v3 > v1.length)
v1 = v3.length; v3 = v1.length;
stack.push(v3.slice(v2, v1)); stack.push(v1.slice(v2, v3));
break; break;
} }
case opcodes.OP_LEFT: case opcodes.OP_LEFT:
case opcodes.OP_RIGHT: { case opcodes.OP_RIGHT: {
if (stack.length < 2) if (stack.length < 2)
throw new ScriptError('Stack too small.', op, ip); throw new ScriptError('Stack too small.', op, ip);
v1 = Script.num(stack.pop(), flags).toNumber(); // size v2 = Script.num(stack.pop(), flags).toNumber(); // size
v2 = stack.pop(); // string v1 = stack.pop(); // string
if (v1 < 0) if (v2 < 0)
throw new ScriptError('String size is negative.', op, ip); throw new ScriptError('String size is negative.', op, ip);
if (v1 > v2.length) if (v2 > v1.length)
v1 = v2.length; v2 = v1.length;
if (op === opcodes.OP_LEFT) if (op === opcodes.OP_LEFT)
v2 = v2.slice(0, v1); v1 = v1.slice(0, v2);
else else
v2 = v2.slice(v2.length - v1); v1 = v1.slice(v1.length - v2);
stack.push(v2); stack.push(v1);
break; break;
} }
case opcodes.OP_INVERT: { case opcodes.OP_INVERT: {
@ -1563,7 +1563,7 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
throw new ScriptError('Stack too small.', op, ip); throw new ScriptError('Stack too small.', op, ip);
val = utils.slice(stack.pop()); val = utils.slice(stack.pop());
for (i = 0; i < val.length; i++) for (i = 0; i < val.length; i++)
val[i] = ~val[i]; val[i] = ~val[i] & 0xff;
stack.push(val); stack.push(val);
break; break;
} }