From 285a34b7538f0aff7f39447527d6d2f521b32cd0 Mon Sep 17 00:00:00 2001 From: John Russell Date: Wed, 28 May 2014 00:53:48 -0700 Subject: [PATCH 1/3] ensure that pubKey length is greater than m --- src/script.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/script.js b/src/script.js index 8a28f1032..f5facf294 100644 --- a/src/script.js +++ b/src/script.js @@ -304,6 +304,9 @@ Script.createP2SHScriptPubKey = function(hash) { // m [pubKeys ...] n OP_CHECKMULTISIG Script.createMultisigScriptPubKey = function(m, pubKeys) { + assert(pubKeys instanceof Array) + assert(pubKeys.length >= m) + var script = new Script() var n = pubKeys.length From 8cb87d435d2f8c2dc3f3c7b374182eb646da985a Mon Sep 17 00:00:00 2001 From: John Russell Date: Wed, 28 May 2014 00:57:12 -0700 Subject: [PATCH 2/3] added error message --- src/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/script.js b/src/script.js index f5facf294..3952b2c1a 100644 --- a/src/script.js +++ b/src/script.js @@ -304,8 +304,8 @@ Script.createP2SHScriptPubKey = function(hash) { // m [pubKeys ...] n OP_CHECKMULTISIG Script.createMultisigScriptPubKey = function(m, pubKeys) { - assert(pubKeys instanceof Array) - assert(pubKeys.length >= m) + assert(pubKeys instanceof Array, 'pubKeys not instance of an array') + assert(pubKeys.length >= m, 'Not enough pubKeys provided') var script = new Script() var n = pubKeys.length From 6c951e4e6d1b1af44a456a393cb2dadcf24a6979 Mon Sep 17 00:00:00 2001 From: John Russell Date: Wed, 28 May 2014 01:03:58 -0700 Subject: [PATCH 3/3] add test --- test/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/script.js b/test/script.js index 41efcbd7c..1e60eb1c3 100644 --- a/test/script.js +++ b/test/script.js @@ -120,6 +120,10 @@ describe('Script', function() { assert.equal(multisigAddress.toString(), '32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v') }) + + it('should throw on not enough pubKeys provided', function() { + assert.throws(function() {Script.createMultisigScriptPubKey(4, pubKeys)}, 'Not enough pubKeys provided') + }) }) describe('2-of-2 Multisig scriptSig', function() {