bitcore-lib icon indicating copy to clipboard operation
bitcore-lib copied to clipboard

Potential Error in Script.isDataOut

Open micahriggan opened this issue 7 years ago • 2 comments

this.chunks[1].length === this.chunks.len

this line should probably be

this.chunks[1].len === this.chunks.length

https://github.com/bitpay/bitcore-lib/blob/86583608814dfc513e675d7b853806caf9bd95e7/lib/script/script.js#L514

micahriggan avatar Nov 12 '18 21:11 micahriggan

I am testing this for a valid script, and I get:

console.log('[script.js.465]', this.chunks[1].length , this.chunks.len);

=> undefined, undefined.

So it is wrong it both sides. See tests at:

https://github.com/bitpay/bitcore-lib/blob/86583608814dfc513e675d7b853806caf9bd95e7/test/script/script.js#L268

matiu avatar Nov 12 '18 22:11 matiu

I dont understand the point of that test, I think we should remove it, leaving the line as:

return this.chunks.length >= 1 && this.chunks[0].opcodenum === Opcode.OP_RETURN && (this.chunks.length === 1 || (this.chunks.length === 2 && this.chunks[1].buf && this.chunks[1].buf.length <= Script.OP_RETURN_STANDARD_SIZE));

matiu avatar Nov 12 '18 22:11 matiu