Merge pull request #482 from bitcoinjs/opint
fix isMultisigOutput allowing m data
This commit is contained in:
commit
0eadf3d5ae
2 changed files with 33 additions and 20 deletions
|
@ -4,11 +4,16 @@ var typeforce = require('typeforce')
|
||||||
var types = require('./types')
|
var types = require('./types')
|
||||||
|
|
||||||
var OPS = require('./opcodes')
|
var OPS = require('./opcodes')
|
||||||
var REVERSE_OPS = []
|
var REVERSE_OPS = (function () {
|
||||||
for (var op in OPS) {
|
var result = {}
|
||||||
var code = OPS[op]
|
for (var op in OPS) {
|
||||||
REVERSE_OPS[code] = op
|
var code = OPS[op]
|
||||||
}
|
result[code] = op
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
})()
|
||||||
|
|
||||||
|
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
|
||||||
|
|
||||||
function toASM (chunks) {
|
function toASM (chunks) {
|
||||||
if (types.Buffer(chunks)) {
|
if (types.Buffer(chunks)) {
|
||||||
|
@ -225,21 +230,21 @@ function isMultisigOutput (script) {
|
||||||
if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) return false
|
if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) return false
|
||||||
|
|
||||||
var mOp = chunks[0]
|
var mOp = chunks[0]
|
||||||
if (mOp < OPS.OP_1) return false
|
|
||||||
if (mOp > OPS.OP_16) return false
|
|
||||||
|
|
||||||
var nOp = chunks[chunks.length - 2]
|
var nOp = chunks[chunks.length - 2]
|
||||||
if (nOp < OPS.OP_1) return false
|
|
||||||
if (nOp > OPS.OP_16) return false
|
|
||||||
|
|
||||||
var m = mOp - (OPS.OP_1 - 1)
|
if (!types.Number(mOp)) return false
|
||||||
var n = nOp - (OPS.OP_1 - 1)
|
if (!types.Number(nOp)) return false
|
||||||
if (n < m) return false
|
|
||||||
|
|
||||||
var pubKeys = chunks.slice(1, -2)
|
var m = mOp - OP_INT_BASE
|
||||||
if (n !== pubKeys.length) return false
|
var n = nOp - OP_INT_BASE
|
||||||
|
|
||||||
return pubKeys.every(isCanonicalPubKey)
|
// 0 < m <= n <= 16
|
||||||
|
if (m <= 0) return false
|
||||||
|
if (m > n) return false
|
||||||
|
if (n > 16) return false
|
||||||
|
if (n !== chunks.length - 3) return false
|
||||||
|
|
||||||
|
return chunks.slice(1, -2).every(isCanonicalPubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNullDataOutput (script) {
|
function isNullDataOutput (script) {
|
||||||
|
@ -309,9 +314,9 @@ function multisigOutput (m, pubKeys) {
|
||||||
if (n < m) throw new Error('Not enough pubKeys provided')
|
if (n < m) throw new Error('Not enough pubKeys provided')
|
||||||
|
|
||||||
return compile([].concat(
|
return compile([].concat(
|
||||||
(OPS.OP_1 - 1) + m,
|
OP_INT_BASE + m,
|
||||||
pubKeys,
|
pubKeys,
|
||||||
(OPS.OP_1 - 1) + n,
|
OP_INT_BASE + n,
|
||||||
OPS.OP_CHECKMULTISIG
|
OPS.OP_CHECKMULTISIG
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -349,8 +354,8 @@ function multisigInput (signatures, scriptPubKey) {
|
||||||
|
|
||||||
var mOp = chunks[0]
|
var mOp = chunks[0]
|
||||||
var nOp = chunks[chunks.length - 2]
|
var nOp = chunks[chunks.length - 2]
|
||||||
var m = mOp - (OPS.OP_1 - 1)
|
var m = mOp - OP_INT_BASE
|
||||||
var n = nOp - (OPS.OP_1 - 1)
|
var n = nOp - OP_INT_BASE
|
||||||
|
|
||||||
if (signatures.length < m) throw new Error('Not enough signatures provided')
|
if (signatures.length < m) throw new Error('Not enough signatures provided')
|
||||||
if (signatures.length > n) throw new Error('Too many signatures provided')
|
if (signatures.length > n) throw new Error('Too many signatures provided')
|
||||||
|
|
8
test/fixtures/script.json
vendored
8
test/fixtures/script.json
vendored
|
@ -245,6 +245,14 @@
|
||||||
"description": "n > len(pubKeys)",
|
"description": "n > len(pubKeys)",
|
||||||
"scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
|
"scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"description": "m is data",
|
||||||
|
"scriptPubKey": "ffff 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_1 OP_CHECKMULTISIG"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "n is data",
|
||||||
|
"scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 ffff OP_CHECKMULTISIG"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"description": "non-canonical pubKey (bad length)",
|
"description": "non-canonical pubKey (bad length)",
|
||||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffff OP_1 OP_CHECKMULTISIG"
|
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffff OP_1 OP_CHECKMULTISIG"
|
||||||
|
|
Loading…
Reference in a new issue