From 500f0796320ad6248bd6fe22a9c6bab8d02cbce9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 21 Dec 2015 11:26:13 -0800 Subject: [PATCH] fix script arithmetic, op_verify, and wallet.fillUnspent. --- lib/bcoin/script.js | 8 +++++++- lib/bcoin/wallet.js | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 2b0123f7..d390e48e 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -326,7 +326,7 @@ script.execute = function execute(s, stack, tx, index, recurse) { case 'verify': { if (stack.length === 0) return false; - if (new bn(stack[stack.length - 1]).cmpn(0) === 0) + if (new bn(stack.pop()).cmpn(0) === 0) return false; break; } @@ -518,6 +518,8 @@ script.execute = function execute(s, stack, tx, index, recurse) { default: return false; } + if (typeof n === 'boolean') + n = new bn(+n); stack.push(n.toArray()); break; } @@ -596,6 +598,8 @@ script.execute = function execute(s, stack, tx, index, recurse) { default: return false; } + if (typeof n === 'boolean') + n = new bn(+n); res = n.cmpn(0) !== 0; if (o === 'numeqverify') { if (!res) @@ -672,6 +676,7 @@ script.execute = function execute(s, stack, tx, index, recurse) { pub = stack.pop(); sig = stack.pop(); type = sig[sig.length - 1]; + if (!constants.hashTypeByVal[type & 0x1f]) return false; @@ -728,6 +733,7 @@ script.execute = function execute(s, stack, tx, index, recurse) { for (i = 0, j = 0; i < m && j < n; i++) { sig = stack.pop(); type = sig[sig.length - 1]; + if (!constants.hashTypeByVal[type & 0x1f]) return false; diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 489072f4..1bf4bbc6 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -459,8 +459,8 @@ Wallet.prototype.scriptOutputs = function scriptOutputs(tx, options, outputs) { return outputs.length; }; -Wallet.prototype.fillUnspent = function fillUnspent(tx, unspent, change) { - return tx.fillUnspent(tx, unspent, change); +Wallet.prototype.fillUnspent = function fillUnspent(tx, change) { + return tx.fillUnspent(this.unspent(), change || this.getFullAddress()); }; Wallet.prototype.scriptInputs = function scriptInputs(tx, inputs) {