add allowEval option.

This commit is contained in:
Christopher Jeffrey 2015-12-18 17:50:51 -08:00
parent 0bd4d798a9
commit 283157dd71

View File

@ -198,7 +198,7 @@ script._next = function(to, s, pc) {
return -1;
};
script.execute = function execute(s, stack, tx, index) {
script.execute = function execute(s, stack, tx, index, recurse) {
s = s.slice();
if (s.length > constants.script.maxOps)
@ -713,9 +713,6 @@ script.execute = function execute(s, stack, tx, index) {
}
case 'checklocktimeverify': {
// OP_CHECKLOCKTIMEVERIFY = OP_NOP2
// input: [[], sig1, sig2, 1]
// prev_out: [[lock], 'checklocktimeverify', 'drop',
// 'dup', 'hash160', pubkey, 'equalverify', 'checksig']
if (!tx || stack.length === 0)
return false;
@ -742,12 +739,30 @@ script.execute = function execute(s, stack, tx, index) {
}
case 'eval_': {
// OP_EVAL = OP_NOP1
// var evalScript = script.decode(stack.pop());
// if (!Array.isArray(evalScript))
// return false;
// var res = script.execute(evalScript, stack, tx, index);
// if (!res)
// return false;
if (!script.allowEval)
break;
recurse = recurse || 0;
if (recurse++ > 2)
return false;
var evalScript = stack.pop();
if (!Array.isArray(evalScript))
return false;
evalScript = script.decode(evalScript);
var res = evalScript.some(function(op) {
return op === 'codesep';
});
if (res)
return false;
res = script.execute(evalScript, stack, tx, index, recurse);
if (!res)
return false;
break;
}
default: {
@ -763,10 +778,10 @@ script.execute = function execute(s, stack, tx, index) {
return true;
};
script.exec = function(input, output, tx, i) {
script.exec = function(input, output, tx, i, recurse) {
var stack = [];
script.execute(input, stack, tx, i);
var res = script.execute(output, stack, tx, i);
script.execute(input, stack, tx, i, recurse);
var res = script.execute(output, stack, tx, i, recurse);
// if (!res || stack.length === 0 || new bn(stack.pop()).cmp(0) !== 0)
if (!res || stack.length === 0 || utils.isEqual(stack.pop(), [ 0 ]))
return false;