From 0bbde0c9de5007c7289f9f93b585c1b98c8d8bd6 Mon Sep 17 00:00:00 2001 From: eordano Date: Wed, 18 Feb 2015 09:51:49 -0300 Subject: [PATCH] Script: Update max length for standard opreturn to 80 --- lib/script/script.js | 6 ++++-- test/script/script.js | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/script/script.js b/lib/script/script.js index 321ffc0..bc6c1d1 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -324,7 +324,7 @@ Script.prototype.isMultisigIn = function() { }; /** - * @returns {boolean} if this is an OP_RETURN data script + * @returns {boolean} true if this is a valid standard OP_RETURN output */ Script.prototype.isDataOut = function() { return this.chunks.length >= 1 && @@ -332,7 +332,7 @@ Script.prototype.isDataOut = function() { (this.chunks.length === 1 || (this.chunks.length === 2 && this.chunks[1].buf && - this.chunks[1].buf.length <= 40 && + this.chunks[1].buf.length <= Script.OP_RETURN_STANDARD_SIZE && this.chunks[1].length === this.chunks.len)); }; @@ -375,6 +375,8 @@ Script.types.MULTISIG_OUT = 'Pay to multisig'; Script.types.MULTISIG_IN = 'Spend from multisig'; Script.types.DATA_OUT = 'Data push'; +Script.OP_RETURN_STANDARD_SIZE = 80; + Script.identifiers = {}; Script.identifiers.PUBKEY_OUT = Script.prototype.isPublicKeyOut; Script.identifiers.PUBKEY_IN = Script.prototype.isPublicKeyIn; diff --git a/test/script/script.js b/test/script/script.js index a3c6d1d..c167bb0 100644 --- a/test/script/script.js +++ b/test/script/script.js @@ -207,18 +207,28 @@ describe('Script', function() { Script('OP_RETURN').isDataOut().should.equal(true); }); - it('should know this is an OP_RETURN script', function() { + it('validates that this 40-byte OP_RETURN is standard', function() { var buf = new Buffer(40); buf.fill(0); Script('OP_RETURN 40 0x' + buf.toString('hex')).isDataOut().should.equal(true); }); + it('validates that this 80-byte OP_RETURN is standard', function() { + var buf = new Buffer(80); + buf.fill(0); + Script('OP_RETURN OP_PUSHDATA1 80 0x' + buf.toString('hex')).isDataOut().should.equal(true); + }); - it('should know this is not an OP_RETURN script', function() { + it('validates that this 40-byte long OP_CHECKMULTISIG is not standard op_return', function() { var buf = new Buffer(40); buf.fill(0); Script('OP_CHECKMULTISIG 40 0x' + buf.toString('hex')).isDataOut().should.equal(false); }); + it('validates that this 81-byte OP_RETURN is not a valid standard OP_RETURN', function() { + var buf = new Buffer(81); + buf.fill(0); + Script('OP_RETURN OP_PUSHDATA1 81 0x' + buf.toString('hex')).isDataOut().should.equal(false); + }); }); describe('#isPublicKeyHashIn', function() {