From 6154b1f7a1c3215fc1ff5948ef2bad630c5e4e35 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 14 Jan 2016 01:16:39 -0800 Subject: [PATCH] improve tx verification. --- lib/bcoin/tx.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 5a8b5aaf..2c996d94 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -689,13 +689,20 @@ TX.prototype.verify = function verify(index, force, flags) { if (!input.out.tx) return false; - output = input.out.tx.outputs[input.out.index]; - - assert(input.out.tx.outputs.length > input.out.index); + // Somethis is very wrong if this is + // not the case. assert.equal(input.out.tx.hash('hex'), input.out.hash); - // Transaction cannot reference itself - if (input.out.tx.hash('hex') === this.hash('hex')) + // Grab the previous output. + output = input.out.tx.outputs[input.out.index]; + + // Transaction is referencing an output + // that does not exist. + if (!output) + return false; + + // Transaction cannot reference itself. + if (input.out.hash === this.hash('hex')) return false; return bcoin.script.verify(input.script, output.script, this, i, flags);