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);