diff --git a/script.go b/script.go index 0854931b..11f0dab3 100644 --- a/script.go +++ b/script.go @@ -1128,11 +1128,13 @@ func expectedInputs(pops []parsedOpcode, class ScriptClass) int { return 1 case MultiSigTy: // Standard multisig has a push a small number for the number - // of sigs and number of keys. - // Check the first push instruction to see how many arguments - // are expected. typeOfScript already checked this so we know - // it'll be a small int. - return asSmallInt(pops[0].opcode) + // of sigs and number of keys. Check the first push instruction + // to see how many arguments are expected. typeOfScript already + // checked this so we know it'll be a small int. Also, due to + // the original bitcoind bug where OP_CHECKMULTISIG pops an + // additional item from the stack, add an extra expected input + // for the extra push that is required to compensate. + return asSmallInt(pops[0].opcode) + 1 case NullDataTy: fallthrough default: diff --git a/script_test.go b/script_test.go index d1eb604e..1fb6e7a3 100644 --- a/script_test.go +++ b/script_test.go @@ -1200,7 +1200,7 @@ var txTests = []txTest{ scriptInfo: btcscript.ScriptInfo{ PkScriptClass: btcscript.ScriptHashTy, NumInputs: 2, - ExpectedInputs: 1, + ExpectedInputs: 2, SigOps: 1, }, }, @@ -1780,6 +1780,7 @@ func TestScriptInfo(t *testing.T) { name: "multisig script", sigScript: []byte{btcscript.OP_TRUE, btcscript.OP_TRUE, btcscript.OP_TRUE, + btcscript.OP_0, // Extra arg for OP_CHECKMULTISIG bug }, pkScript: []byte{ btcscript.OP_3, btcscript.OP_DATA_33, @@ -1802,8 +1803,8 @@ func TestScriptInfo(t *testing.T) { bip16: true, scriptInfo: btcscript.ScriptInfo{ PkScriptClass: btcscript.MultiSigTy, - NumInputs: 3, - ExpectedInputs: 3, + NumInputs: 4, + ExpectedInputs: 4, SigOps: 3, }, },