2015-01-30 07:03:01 +01:00
|
|
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
2013-06-12 23:35:27 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
package txscript_test
|
2013-06-12 23:35:27 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-04-18 00:15:30 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2014-07-03 02:37:49 +02:00
|
|
|
"testing"
|
|
|
|
|
2015-02-06 17:38:24 +01:00
|
|
|
"github.com/btcsuite/btcd/btcec"
|
2015-02-06 06:18:27 +01:00
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
2015-01-30 07:03:01 +01:00
|
|
|
"github.com/btcsuite/btcd/txscript"
|
2015-02-05 22:16:39 +01:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2015-01-15 17:42:26 +01:00
|
|
|
"github.com/btcsuite/btcutil"
|
2013-06-12 23:35:27 +02:00
|
|
|
)
|
|
|
|
|
2014-12-20 08:34:39 +01:00
|
|
|
// builderScript is a convenience function which is used in the tests. It
|
|
|
|
// allows access to the script from a known good script built with the builder.
|
|
|
|
// Any errors are converted to a panic since it is only, and must only, be used
|
|
|
|
// with hard coded, and therefore, known good, scripts.
|
2015-01-30 07:03:01 +01:00
|
|
|
func builderScript(builder *txscript.ScriptBuilder) []byte {
|
2014-12-20 08:34:39 +01:00
|
|
|
script, err := builder.Script()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return script
|
|
|
|
}
|
|
|
|
|
2014-05-08 19:14:01 +02:00
|
|
|
func TestPushedData(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-05-08 19:14:01 +02:00
|
|
|
var tests = []struct {
|
|
|
|
in []byte
|
|
|
|
out [][]byte
|
|
|
|
valid bool
|
|
|
|
}{
|
|
|
|
{
|
2015-01-30 07:03:01 +01:00
|
|
|
[]byte{txscript.OP_0, txscript.OP_IF, txscript.OP_0, txscript.OP_ELSE, txscript.OP_2, txscript.OP_ENDIF},
|
2014-05-08 19:14:01 +02:00
|
|
|
[][]byte{{}, {}},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2015-01-30 07:03:01 +01:00
|
|
|
builderScript(txscript.NewScriptBuilder().AddInt64(16777216).AddInt64(10000000)),
|
2014-05-08 19:14:01 +02:00
|
|
|
[][]byte{
|
|
|
|
{0x00, 0x00, 0x00, 0x01}, // 16777216
|
|
|
|
{0x80, 0x96, 0x98, 0x00}, // 10000000
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2015-01-30 07:03:01 +01:00
|
|
|
builderScript(txscript.NewScriptBuilder().AddOp(txscript.OP_DUP).AddOp(txscript.OP_HASH160).
|
|
|
|
AddData([]byte("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem")).AddOp(txscript.OP_EQUALVERIFY).
|
|
|
|
AddOp(txscript.OP_CHECKSIG)),
|
2014-05-08 19:14:01 +02:00
|
|
|
[][]byte{
|
|
|
|
// 17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem
|
|
|
|
{
|
|
|
|
0x31, 0x37, 0x56, 0x5a, 0x4e, 0x58, 0x31, 0x53, 0x4e, 0x35,
|
|
|
|
0x4e, 0x74, 0x4b, 0x61, 0x38, 0x55, 0x51, 0x46, 0x78, 0x77,
|
|
|
|
0x51, 0x62, 0x46, 0x65, 0x46, 0x63, 0x33, 0x69, 0x71, 0x52,
|
|
|
|
0x59, 0x68, 0x65, 0x6d,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2015-01-30 07:03:01 +01:00
|
|
|
builderScript(txscript.NewScriptBuilder().AddOp(txscript.OP_PUSHDATA4).AddInt64(1000).
|
|
|
|
AddOp(txscript.OP_EQUAL)),
|
2014-05-08 19:14:01 +02:00
|
|
|
[][]byte{},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for x, test := range tests {
|
2015-01-30 07:03:01 +01:00
|
|
|
pushedData, err := txscript.PushedData(test.in)
|
2014-05-08 19:14:01 +02:00
|
|
|
if test.valid && err != nil {
|
|
|
|
t.Errorf("TestPushedData failed test #%d: %v\n", x, err)
|
|
|
|
continue
|
|
|
|
} else if !test.valid && err == nil {
|
|
|
|
t.Errorf("TestPushedData failed test #%d: test should be invalid\n", x)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for x, data := range pushedData {
|
|
|
|
if !bytes.Equal(data, test.out[x]) {
|
|
|
|
t.Errorf("TestPushedData failed test #%d: want: %x got: %x\n",
|
|
|
|
x, test.out[x], data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 06:05:35 +01:00
|
|
|
func TestStandardPushes(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-12-20 08:34:39 +01:00
|
|
|
for i := 0; i < 65535; i++ {
|
2015-01-30 07:03:01 +01:00
|
|
|
builder := txscript.NewScriptBuilder()
|
2014-02-20 18:42:06 +01:00
|
|
|
builder.AddInt64(int64(i))
|
2014-12-20 08:34:39 +01:00
|
|
|
script, err := builder.Script()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("StandardPushesTests test #%d unexpected error: %v\n", i, err)
|
|
|
|
continue
|
2014-02-20 06:05:35 +01:00
|
|
|
}
|
2015-01-30 07:03:01 +01:00
|
|
|
if result := txscript.IsPushOnlyScript(script); !result {
|
2014-12-20 08:34:39 +01:00
|
|
|
t.Errorf("StandardPushesTests IsPushOnlyScript test #%d failed: %x\n", i, script)
|
|
|
|
continue
|
|
|
|
}
|
2015-02-25 02:11:57 +01:00
|
|
|
pops, err := txscript.TstParseScript(script)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("StandardPushesTests #%d failed to TstParseScript: %v", i, err)
|
2014-02-20 06:05:35 +01:00
|
|
|
continue
|
|
|
|
}
|
2015-02-25 02:11:57 +01:00
|
|
|
for _, pop := range pops {
|
|
|
|
if result := txscript.TstHasCanonicalPushes(pop); !result {
|
|
|
|
t.Errorf("StandardPushesTests TstHasCanonicalPushes test #%d failed: %x\n", i, script)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2014-02-20 06:05:35 +01:00
|
|
|
}
|
2015-01-30 07:03:01 +01:00
|
|
|
for i := 0; i <= txscript.MaxScriptElementSize; i++ {
|
|
|
|
builder := txscript.NewScriptBuilder()
|
2014-02-20 18:42:06 +01:00
|
|
|
builder.AddData(bytes.Repeat([]byte{0x49}, i))
|
2014-12-20 08:34:39 +01:00
|
|
|
script, err := builder.Script()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("StandardPushesTests test #%d unexpected error: %v\n", i, err)
|
|
|
|
continue
|
|
|
|
}
|
2015-01-30 07:03:01 +01:00
|
|
|
if result := txscript.IsPushOnlyScript(script); !result {
|
2014-12-20 08:34:39 +01:00
|
|
|
t.Errorf("StandardPushesTests IsPushOnlyScript test #%d failed: %x\n", i, script)
|
|
|
|
continue
|
2014-02-20 06:05:35 +01:00
|
|
|
}
|
2015-02-25 02:11:57 +01:00
|
|
|
pops, err := txscript.TstParseScript(script)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("StandardPushesTests #%d failed to TstParseScript: %v", i, err)
|
2014-02-20 06:05:35 +01:00
|
|
|
continue
|
|
|
|
}
|
2015-02-25 02:11:57 +01:00
|
|
|
for _, pop := range pops {
|
|
|
|
if result := txscript.TstHasCanonicalPushes(pop); !result {
|
|
|
|
t.Errorf("StandardPushesTests TstHasCanonicalPushes test #%d failed: %x\n", i, script)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2014-02-20 06:05:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 23:35:27 +02:00
|
|
|
type txTest struct {
|
2013-10-09 01:13:52 +02:00
|
|
|
name string
|
2015-02-05 22:16:39 +01:00
|
|
|
tx *wire.MsgTx
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript []byte // output script of previous tx
|
|
|
|
idx int // tx idx to be run.
|
|
|
|
bip16 bool // is bip16 active?
|
2015-02-14 15:37:47 +01:00
|
|
|
strictSigs bool // should signatures be validated as strict?
|
2015-01-30 07:03:01 +01:00
|
|
|
parseErr error // failure of NewScript
|
|
|
|
err error // Failure of Executre
|
|
|
|
shouldFail bool // Execute should fail with nonspecified error.
|
|
|
|
nSigOps int // result of GetPreciseSigOpsCount
|
|
|
|
scriptInfo txscript.ScriptInfo // result of ScriptInfo
|
|
|
|
scriptInfoErr error // error return of ScriptInfo
|
2013-06-12 23:35:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var txTests = []txTest{
|
|
|
|
// tx 0437cd7f8525ceed2324359c2d0ba26006d92d85. the first tx in the
|
|
|
|
// blockchain that verifies signatures.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "CheckSig",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-12 23:35:27 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0xc9, 0x97, 0xa5, 0xe5,
|
|
|
|
0x6e, 0x10, 0x41, 0x02,
|
|
|
|
0xfa, 0x20, 0x9c, 0x6a,
|
|
|
|
0x85, 0x2d, 0xd9, 0x06,
|
|
|
|
0x60, 0xa2, 0x0b, 0x2d,
|
|
|
|
0x9c, 0x35, 0x24, 0x23,
|
|
|
|
0xed, 0xce, 0x25, 0x85,
|
|
|
|
0x7f, 0xcd, 0x37, 0x04,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []uint8{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0x4e,
|
|
|
|
0x45, 0xe1, 0x69, 0x32, 0xb8,
|
|
|
|
0xaf, 0x51, 0x49, 0x61, 0xa1,
|
|
|
|
0xd3, 0xa1, 0xa2, 0x5f, 0xdf,
|
|
|
|
0x3f, 0x4f, 0x77, 0x32, 0xe9,
|
|
|
|
0xd6, 0x24, 0xc6, 0xc6, 0x15,
|
|
|
|
0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15,
|
|
|
|
0x22, 0xec, 0x8e, 0xca, 0x07,
|
|
|
|
0xde, 0x48, 0x60, 0xa4, 0xac,
|
|
|
|
0xdd, 0x12, 0x90, 0x9d, 0x83,
|
|
|
|
0x1c, 0xc5, 0x6c, 0xbb, 0xac,
|
|
|
|
0x46, 0x22, 0x08, 0x22, 0x21,
|
|
|
|
0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
0x01,
|
|
|
|
},
|
|
|
|
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0xae, 0x1a, 0x62, 0xfe,
|
|
|
|
0x09, 0xc5, 0xf5, 0x1b, 0x13,
|
|
|
|
0x90, 0x5f, 0x07, 0xf0, 0x6b,
|
|
|
|
0x99, 0xa2, 0xf7, 0x15, 0x9b,
|
|
|
|
0x22, 0x25, 0xf3, 0x74, 0xcd,
|
|
|
|
0x37, 0x8d, 0x71, 0x30, 0x2f,
|
|
|
|
0xa2, 0x84, 0x14, 0xe7, 0xaa,
|
|
|
|
0xb3, 0x73, 0x97, 0xf5, 0x54,
|
|
|
|
0xa7, 0xdf, 0x5f, 0x14, 0x2c,
|
|
|
|
0x21, 0xc1, 0xb7, 0x30, 0x3b,
|
|
|
|
0x8a, 0x06, 0x26, 0xf1, 0xba,
|
|
|
|
0xde, 0xd5, 0xc7, 0x2a, 0x70,
|
|
|
|
0x4f, 0x7e, 0x6c, 0xd8, 0x4c,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 4000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1,
|
|
|
|
0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53,
|
|
|
|
0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e,
|
|
|
|
0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0,
|
|
|
|
0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0,
|
|
|
|
0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01,
|
|
|
|
0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6,
|
|
|
|
0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7,
|
|
|
|
0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea,
|
|
|
|
0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4,
|
|
|
|
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
2015-01-30 07:03:01 +01:00
|
|
|
0x12, 0xa3, txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-06-21 02:33:56 +02:00
|
|
|
idx: 0,
|
2013-06-20 19:07:44 +02:00
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.PubKeyTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 1,
|
|
|
|
ExpectedInputs: 1,
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// Previous test with the value of one output changed.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "CheckSig Failure",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-12 23:35:27 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0xc9, 0x97, 0xa5, 0xe5,
|
|
|
|
0x6e, 0x10, 0x41, 0x02,
|
|
|
|
0xfa, 0x20, 0x9c, 0x6a,
|
|
|
|
0x85, 0x2d, 0xd9, 0x06,
|
|
|
|
0x60, 0xa2, 0x0b, 0x2d,
|
|
|
|
0x9c, 0x35, 0x24, 0x23,
|
|
|
|
0xed, 0xce, 0x25, 0x85,
|
|
|
|
0x7f, 0xcd, 0x37, 0x04,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []uint8{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0x4e,
|
|
|
|
0x45, 0xe1, 0x69, 0x32, 0xb8,
|
|
|
|
0xaf, 0x51, 0x49, 0x61, 0xa1,
|
|
|
|
0xd3, 0xa1, 0xa2, 0x5f, 0xdf,
|
|
|
|
0x3f, 0x4f, 0x77, 0x32, 0xe9,
|
|
|
|
0xd6, 0x24, 0xc6, 0xc6, 0x15,
|
|
|
|
0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15,
|
|
|
|
0x22, 0xec, 0x8e, 0xca, 0x07,
|
|
|
|
0xde, 0x48, 0x60, 0xa4, 0xac,
|
|
|
|
0xdd, 0x12, 0x90, 0x9d, 0x83,
|
|
|
|
0x1c, 0xc5, 0x6c, 0xbb, 0xac,
|
|
|
|
0x46, 0x22, 0x08, 0x22, 0x21,
|
|
|
|
0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
0x01,
|
|
|
|
},
|
|
|
|
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0xae, 0x1a, 0x62, 0xfe,
|
|
|
|
0x09, 0xc5, 0xf5, 0x1b, 0x13,
|
|
|
|
0x90, 0x5f, 0x07, 0xf0, 0x6b,
|
|
|
|
0x99, 0xa2, 0xf7, 0x15, 0x9b,
|
|
|
|
0x22, 0x25, 0xf3, 0x74, 0xcd,
|
|
|
|
0x37, 0x8d, 0x71, 0x30, 0x2f,
|
|
|
|
0xa2, 0x84, 0x14, 0xe7, 0xaa,
|
|
|
|
0xb3, 0x73, 0x97, 0xf5, 0x54,
|
|
|
|
0xa7, 0xdf, 0x5f, 0x14, 0x2c,
|
|
|
|
0x21, 0xc1, 0xb7, 0x30, 0x3b,
|
|
|
|
0x8a, 0x06, 0x26, 0xf1, 0xba,
|
|
|
|
0xde, 0xd5, 0xc7, 0x2a, 0x70,
|
|
|
|
0x4f, 0x7e, 0x6c, 0xd8, 0x4c,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 5000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1,
|
|
|
|
0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53,
|
|
|
|
0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e,
|
|
|
|
0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0,
|
|
|
|
0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0,
|
|
|
|
0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01,
|
|
|
|
0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6,
|
|
|
|
0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7,
|
|
|
|
0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea,
|
|
|
|
0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4,
|
|
|
|
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
2015-01-30 07:03:01 +01:00
|
|
|
0x12, 0xa3, txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-06-21 02:33:56 +02:00
|
|
|
idx: 0,
|
2015-01-30 07:03:01 +01:00
|
|
|
err: txscript.ErrStackScriptFailed,
|
2013-06-20 19:07:44 +02:00
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.PubKeyTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 1,
|
|
|
|
ExpectedInputs: 1,
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-19 00:36:44 +02:00
|
|
|
name: "CheckSig invalid signature",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-19 00:36:44 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-19 00:36:44 +02:00
|
|
|
0xc9, 0x97, 0xa5, 0xe5,
|
|
|
|
0x6e, 0x10, 0x41, 0x02,
|
|
|
|
0xfa, 0x20, 0x9c, 0x6a,
|
|
|
|
0x85, 0x2d, 0xd9, 0x06,
|
|
|
|
0x60, 0xa2, 0x0b, 0x2d,
|
|
|
|
0x9c, 0x35, 0x24, 0x23,
|
|
|
|
0xed, 0xce, 0x25, 0x85,
|
|
|
|
0x7f, 0xcd, 0x37, 0x04,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
// Signature has length fiddled to
|
|
|
|
// fail parsing.
|
|
|
|
SignatureScript: []uint8{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x30, 0x45, 0x02, 0x20, 0x4e,
|
|
|
|
0x45, 0xe1, 0x69, 0x32, 0xb8,
|
|
|
|
0xaf, 0x51, 0x49, 0x61, 0xa1,
|
|
|
|
0xd3, 0xa1, 0xa2, 0x5f, 0xdf,
|
|
|
|
0x3f, 0x4f, 0x77, 0x32, 0xe9,
|
|
|
|
0xd6, 0x24, 0xc6, 0xc6, 0x15,
|
|
|
|
0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15,
|
|
|
|
0x22, 0xec, 0x8e, 0xca, 0x07,
|
|
|
|
0xde, 0x48, 0x60, 0xa4, 0xac,
|
|
|
|
0xdd, 0x12, 0x90, 0x9d, 0x83,
|
|
|
|
0x1c, 0xc5, 0x6c, 0xbb, 0xac,
|
|
|
|
0x46, 0x22, 0x08, 0x22, 0x21,
|
|
|
|
0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
0x01,
|
|
|
|
},
|
|
|
|
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-19 00:36:44 +02:00
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x04, 0xae, 0x1a, 0x62, 0xfe,
|
|
|
|
0x09, 0xc5, 0xf5, 0x1b, 0x13,
|
|
|
|
0x90, 0x5f, 0x07, 0xf0, 0x6b,
|
|
|
|
0x99, 0xa2, 0xf7, 0x15, 0x9b,
|
|
|
|
0x22, 0x25, 0xf3, 0x74, 0xcd,
|
|
|
|
0x37, 0x8d, 0x71, 0x30, 0x2f,
|
|
|
|
0xa2, 0x84, 0x14, 0xe7, 0xaa,
|
|
|
|
0xb3, 0x73, 0x97, 0xf5, 0x54,
|
|
|
|
0xa7, 0xdf, 0x5f, 0x14, 0x2c,
|
|
|
|
0x21, 0xc1, 0xb7, 0x30, 0x3b,
|
|
|
|
0x8a, 0x06, 0x26, 0xf1, 0xba,
|
|
|
|
0xde, 0xd5, 0xc7, 0x2a, 0x70,
|
|
|
|
0x4f, 0x7e, 0x6c, 0xd8, 0x4c,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-19 00:36:44 +02:00
|
|
|
Value: 4000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1,
|
|
|
|
0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53,
|
|
|
|
0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e,
|
|
|
|
0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0,
|
|
|
|
0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0,
|
|
|
|
0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01,
|
|
|
|
0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6,
|
|
|
|
0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7,
|
|
|
|
0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea,
|
|
|
|
0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4,
|
|
|
|
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
2015-01-30 07:03:01 +01:00
|
|
|
0x12, 0xa3, txscript.OP_CHECKSIG,
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
|
|
|
idx: 0,
|
|
|
|
shouldFail: true,
|
2013-06-21 02:33:56 +02:00
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.PubKeyTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 1,
|
|
|
|
ExpectedInputs: 1,
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-19 00:36:44 +02:00
|
|
|
name: "CheckSig invalid pubkey",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-19 00:36:44 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-19 00:36:44 +02:00
|
|
|
0xc9, 0x97, 0xa5, 0xe5,
|
|
|
|
0x6e, 0x10, 0x41, 0x02,
|
|
|
|
0xfa, 0x20, 0x9c, 0x6a,
|
|
|
|
0x85, 0x2d, 0xd9, 0x06,
|
|
|
|
0x60, 0xa2, 0x0b, 0x2d,
|
|
|
|
0x9c, 0x35, 0x24, 0x23,
|
|
|
|
0xed, 0xce, 0x25, 0x85,
|
|
|
|
0x7f, 0xcd, 0x37, 0x04,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []uint8{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0x4e,
|
|
|
|
0x45, 0xe1, 0x69, 0x32, 0xb8,
|
|
|
|
0xaf, 0x51, 0x49, 0x61, 0xa1,
|
|
|
|
0xd3, 0xa1, 0xa2, 0x5f, 0xdf,
|
|
|
|
0x3f, 0x4f, 0x77, 0x32, 0xe9,
|
|
|
|
0xd6, 0x24, 0xc6, 0xc6, 0x15,
|
|
|
|
0x48, 0xab, 0x5f, 0xb8, 0xcd,
|
|
|
|
0x41, 0x02, 0x20, 0x18, 0x15,
|
|
|
|
0x22, 0xec, 0x8e, 0xca, 0x07,
|
|
|
|
0xde, 0x48, 0x60, 0xa4, 0xac,
|
|
|
|
0xdd, 0x12, 0x90, 0x9d, 0x83,
|
|
|
|
0x1c, 0xc5, 0x6c, 0xbb, 0xac,
|
|
|
|
0x46, 0x22, 0x08, 0x22, 0x21,
|
|
|
|
0xa8, 0x76, 0x8d, 0x1d, 0x09,
|
|
|
|
0x01,
|
|
|
|
},
|
|
|
|
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-19 00:36:44 +02:00
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x04, 0xae, 0x1a, 0x62, 0xfe,
|
|
|
|
0x09, 0xc5, 0xf5, 0x1b, 0x13,
|
|
|
|
0x90, 0x5f, 0x07, 0xf0, 0x6b,
|
|
|
|
0x99, 0xa2, 0xf7, 0x15, 0x9b,
|
|
|
|
0x22, 0x25, 0xf3, 0x74, 0xcd,
|
|
|
|
0x37, 0x8d, 0x71, 0x30, 0x2f,
|
|
|
|
0xa2, 0x84, 0x14, 0xe7, 0xaa,
|
|
|
|
0xb3, 0x73, 0x97, 0xf5, 0x54,
|
|
|
|
0xa7, 0xdf, 0x5f, 0x14, 0x2c,
|
|
|
|
0x21, 0xc1, 0xb7, 0x30, 0x3b,
|
|
|
|
0x8a, 0x06, 0x26, 0xf1, 0xba,
|
|
|
|
0xde, 0xd5, 0xc7, 0x2a, 0x70,
|
|
|
|
0x4f, 0x7e, 0x6c, 0xd8, 0x4c,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-19 00:36:44 +02:00
|
|
|
Value: 4000000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1,
|
|
|
|
0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53,
|
|
|
|
0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e,
|
|
|
|
0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0,
|
|
|
|
0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0,
|
|
|
|
0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
// pubkey header magic byte has been changed to parse wrong.
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-19 00:36:44 +02:00
|
|
|
0x02, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01,
|
|
|
|
0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6,
|
|
|
|
0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7,
|
|
|
|
0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea,
|
|
|
|
0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4,
|
|
|
|
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
2015-01-30 07:03:01 +01:00
|
|
|
0x12, 0xa3, txscript.OP_CHECKSIG,
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
|
|
|
idx: 0,
|
|
|
|
shouldFail: true,
|
2013-06-21 02:33:56 +02:00
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.PubKeyTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 1,
|
|
|
|
ExpectedInputs: 1,
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
2013-06-19 00:36:44 +02:00
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
// tx 599e47a8114fe098103663029548811d2651991b62397e057f0c863c2bc9f9ea
|
|
|
|
// uses checksig with SigHashNone.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "CheckSigHashNone",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-12 23:35:27 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0x5f, 0x38, 0x6c, 0x8a,
|
|
|
|
0x38, 0x42, 0xc9, 0xa9,
|
|
|
|
0xdc, 0xfa, 0x9b, 0x78,
|
|
|
|
0xbe, 0x78, 0x5a, 0x40,
|
|
|
|
0xa7, 0xbd, 0xa0, 0x8b,
|
|
|
|
0x64, 0x64, 0x6b, 0xe3,
|
|
|
|
0x65, 0x43, 0x01, 0xea,
|
|
|
|
0xcc, 0xfc, 0x8d, 0x5e,
|
|
|
|
}),
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0xbb,
|
|
|
|
0x4f, 0xbc, 0x49, 0x5a, 0xa2,
|
|
|
|
0x3b, 0xab, 0xb2, 0xc2, 0xbe,
|
|
|
|
0x4e, 0x3f, 0xb4, 0xa5, 0xdf,
|
|
|
|
0xfe, 0xfe, 0x20, 0xc8, 0xef,
|
|
|
|
0xf5, 0x94, 0x0f, 0x13, 0x56,
|
|
|
|
0x49, 0xc3, 0xea, 0x96, 0x44,
|
|
|
|
0x4a, 0x02, 0x20, 0x04, 0xaf,
|
|
|
|
0xcd, 0xa9, 0x66, 0xc8, 0x07,
|
|
|
|
0xbb, 0x97, 0x62, 0x2d, 0x3e,
|
|
|
|
0xef, 0xea, 0x82, 0x8f, 0x62,
|
|
|
|
0x3a, 0xf3, 0x06, 0xef, 0x2b,
|
|
|
|
0x75, 0x67, 0x82, 0xee, 0x6f,
|
|
|
|
0x8a, 0x22, 0xa9, 0x59, 0xa2,
|
|
|
|
0x02,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0xf1, 0x93, 0x9a, 0xe6,
|
|
|
|
0xb0, 0x1e, 0x84, 0x9b, 0xf0,
|
|
|
|
0x5d, 0x0e, 0xd5, 0x1f, 0xd5,
|
|
|
|
0xb9, 0x2b, 0x79, 0xa0, 0xe3,
|
|
|
|
0x13, 0xe3, 0xf3, 0x89, 0xc7,
|
|
|
|
0x26, 0xf1, 0x1f, 0xa3, 0xe1,
|
|
|
|
0x44, 0xd9, 0x22, 0x7b, 0x07,
|
|
|
|
0xe8, 0xa8, 0x7c, 0x0e, 0xe3,
|
|
|
|
0x63, 0x72, 0xe9, 0x67, 0xe0,
|
|
|
|
0x90, 0xd1, 0x1b, 0x77, 0x77,
|
|
|
|
0x07, 0xaa, 0x73, 0xef, 0xac,
|
|
|
|
0xab, 0xff, 0xff, 0xa2, 0x85,
|
|
|
|
0xc0, 0x0b, 0x36, 0x22, 0xd6,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 1000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x66, 0x0d, 0x4e, 0xf3, 0xa7,
|
|
|
|
0x43, 0xe3, 0xe6, 0x96, 0xad,
|
|
|
|
0x99, 0x03, 0x64, 0xe5, 0x55,
|
|
|
|
0xc2, 0x71, 0xad, 0x50, 0x4b,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 29913632,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x21, 0xc4, 0x3c, 0xe4, 0x00,
|
|
|
|
0x90, 0x13, 0x12, 0xa6, 0x03,
|
|
|
|
0xe4, 0x20, 0x7a, 0xad, 0xfd,
|
|
|
|
0x74, 0x2b, 0xe8, 0xe7, 0xda,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x21, 0xc4, 0x3c, 0xe4, 0x00, 0x90, 0x13, 0x12, 0xa6,
|
|
|
|
0x03, 0xe4, 0x20, 0x7a, 0xad, 0xfd, 0x74, 0x2b, 0xe8,
|
|
|
|
0xe7, 0xda,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-06-21 02:33:56 +02:00
|
|
|
idx: 0,
|
|
|
|
bip16: true, // after threshold
|
2013-06-20 19:07:44 +02:00
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.PubKeyHashTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 2,
|
|
|
|
ExpectedInputs: 2,
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-10-24 16:13:58 +02:00
|
|
|
name: "Non-canonical signature: R value negative",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-10-24 16:13:58 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-10-24 16:13:58 +02:00
|
|
|
0xfe, 0x15, 0x62, 0xc4,
|
|
|
|
0x8b, 0x3a, 0xa6, 0x37,
|
|
|
|
0x3f, 0x42, 0xe9, 0x61,
|
|
|
|
0x51, 0x89, 0xcf, 0x73,
|
|
|
|
0x32, 0xd7, 0x33, 0x5c,
|
|
|
|
0xbe, 0xa7, 0x80, 0xbe,
|
|
|
|
0x69, 0x6a, 0xc6, 0xc6,
|
|
|
|
0x50, 0xfd, 0xda, 0x4a,
|
|
|
|
}),
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-10-24 16:13:58 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0xa0,
|
|
|
|
0x42, 0xde, 0xe5, 0x52, 0x6b,
|
|
|
|
0xf2, 0x29, 0x4d, 0x3f, 0x3e,
|
|
|
|
0xb9, 0x5a, 0xa7, 0x73, 0x19,
|
|
|
|
0xd3, 0xff, 0x56, 0x7b, 0xcf,
|
|
|
|
0x36, 0x46, 0x07, 0x0c, 0x81,
|
|
|
|
0x12, 0x33, 0x01, 0xca, 0xce,
|
|
|
|
0xa9, 0x02, 0x20, 0xea, 0x48,
|
|
|
|
0xae, 0x58, 0xf5, 0x54, 0x10,
|
|
|
|
0x96, 0x3f, 0xa7, 0x03, 0xdb,
|
|
|
|
0x56, 0xf0, 0xba, 0xb2, 0x70,
|
|
|
|
0xb1, 0x08, 0x22, 0xc5, 0x1c,
|
|
|
|
0x68, 0x02, 0x6a, 0x97, 0x5c,
|
|
|
|
0x7d, 0xae, 0x11, 0x2e, 0x4f,
|
|
|
|
0x01,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-10-24 16:13:58 +02:00
|
|
|
0x04, 0x49, 0x45, 0x33, 0x18,
|
|
|
|
0xbd, 0x5e, 0xcf, 0xea, 0x5f,
|
|
|
|
0x86, 0x32, 0x8c, 0x6d, 0x8e,
|
|
|
|
0xd4, 0x12, 0xb4, 0xde, 0x2c,
|
|
|
|
0xab, 0xd7, 0xb8, 0x56, 0x51,
|
|
|
|
0x2f, 0x8c, 0xb7, 0xfd, 0x25,
|
|
|
|
0xf6, 0x03, 0xb0, 0x55, 0xc5,
|
|
|
|
0xdf, 0xe6, 0x22, 0x4b, 0xc4,
|
|
|
|
0xfd, 0xbb, 0x6a, 0x7a, 0xa0,
|
|
|
|
0x58, 0xd7, 0x5d, 0xad, 0x92,
|
|
|
|
0x99, 0x45, 0x4f, 0x62, 0x1a,
|
|
|
|
0x95, 0xb4, 0xb0, 0x21, 0x0e,
|
|
|
|
0xc4, 0x09, 0x2b, 0xe5, 0x27,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-10-24 16:13:58 +02:00
|
|
|
0x2a, 0xc7, 0xee, 0xf8,
|
|
|
|
0xa9, 0x62, 0x2d, 0xda,
|
|
|
|
0xec, 0x18, 0x3b, 0xba,
|
|
|
|
0xa9, 0x92, 0xb0, 0x7a,
|
|
|
|
0x70, 0x3b, 0x48, 0x86,
|
|
|
|
0x27, 0x9c, 0x46, 0xac,
|
|
|
|
0x25, 0xeb, 0x91, 0xec,
|
|
|
|
0x4c, 0x86, 0xd2, 0x9c,
|
|
|
|
}),
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-10-24 16:13:58 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0xc3,
|
|
|
|
0x02, 0x3b, 0xed, 0x85, 0x0d,
|
|
|
|
0x94, 0x27, 0x8e, 0x06, 0xd2,
|
|
|
|
0x37, 0x92, 0x21, 0x55, 0x28,
|
|
|
|
0xdd, 0xdb, 0x63, 0xa4, 0xb6,
|
|
|
|
0x88, 0x33, 0x92, 0x06, 0xdd,
|
|
|
|
0xf9, 0xee, 0x72, 0x97, 0xa3,
|
|
|
|
0x08, 0x02, 0x20, 0x25, 0x00,
|
|
|
|
0x42, 0x8b, 0x26, 0x36, 0x45,
|
|
|
|
0x54, 0xcb, 0x11, 0xd3, 0x3e,
|
|
|
|
0x85, 0x35, 0x23, 0x49, 0x65,
|
|
|
|
0x82, 0x8e, 0x33, 0x6e, 0x1a,
|
|
|
|
0x4a, 0x72, 0x73, 0xeb, 0x5b,
|
|
|
|
0x8d, 0x1d, 0xd7, 0x02, 0xcc,
|
|
|
|
0x01,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-10-24 16:13:58 +02:00
|
|
|
0x04, 0x49, 0x5c, 0x8f, 0x66,
|
|
|
|
0x90, 0x0d, 0xb7, 0x62, 0x69,
|
|
|
|
0x0b, 0x54, 0x49, 0xa1, 0xf4,
|
|
|
|
0xe7, 0xc2, 0xed, 0x1f, 0x4b,
|
|
|
|
0x34, 0x70, 0xfd, 0x42, 0x79,
|
|
|
|
0x68, 0xa1, 0x31, 0x76, 0x0c,
|
|
|
|
0x25, 0xf9, 0x12, 0x63, 0xad,
|
|
|
|
0x51, 0x73, 0x8e, 0x19, 0xb6,
|
|
|
|
0x07, 0xf5, 0xcf, 0x5f, 0x94,
|
|
|
|
0x27, 0x4a, 0x8b, 0xbc, 0x74,
|
|
|
|
0xba, 0x4b, 0x56, 0x0c, 0xe0,
|
|
|
|
0xb3, 0x08, 0x8f, 0x7f, 0x5c,
|
|
|
|
0x5f, 0xcf, 0xd6, 0xa0, 0x4b,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-10-24 16:13:58 +02:00
|
|
|
Value: 630320000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-24 16:13:58 +02:00
|
|
|
0x43, 0xdc, 0x32, 0x1b, 0x66,
|
|
|
|
0x00, 0x51, 0x1f, 0xe0, 0xa9,
|
|
|
|
0x6a, 0x97, 0xc2, 0x59, 0x3a,
|
|
|
|
0x90, 0x54, 0x29, 0x74, 0xd6,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-10-24 16:13:58 +02:00
|
|
|
},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-10-24 16:13:58 +02:00
|
|
|
Value: 100000181,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-24 16:13:58 +02:00
|
|
|
0xa4, 0x05, 0xea, 0x18, 0x09,
|
|
|
|
0x14, 0xa9, 0x11, 0xd0, 0xb8,
|
|
|
|
0x07, 0x99, 0x19, 0x2b, 0x0b,
|
|
|
|
0x84, 0xae, 0x80, 0x1e, 0xbd,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-10-24 16:13:58 +02:00
|
|
|
},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-10-24 16:13:58 +02:00
|
|
|
Value: 596516343,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-24 16:13:58 +02:00
|
|
|
0x24, 0x56, 0x76, 0x45, 0x4f,
|
|
|
|
0x6f, 0xff, 0x28, 0x88, 0x39,
|
|
|
|
0x47, 0xea, 0x70, 0x23, 0x86,
|
|
|
|
0x9b, 0x8a, 0x71, 0xa3, 0x05,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-10-24 16:13:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
// Test input 0
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-24 16:13:58 +02:00
|
|
|
0xfd, 0xf6, 0xea, 0xe7, 0x10,
|
|
|
|
0xa0, 0xc4, 0x49, 0x7a, 0x8d,
|
|
|
|
0x0f, 0xd2, 0x9a, 0xf6, 0x6b,
|
|
|
|
0xac, 0x94, 0xaf, 0x6c, 0x98,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-10-24 16:13:58 +02:00
|
|
|
},
|
2015-02-14 15:37:47 +01:00
|
|
|
idx: 0,
|
|
|
|
strictSigs: true,
|
|
|
|
shouldFail: true,
|
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.PubKeyHashTy,
|
2013-10-24 16:13:58 +02:00
|
|
|
NumInputs: 2,
|
|
|
|
ExpectedInputs: 2,
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-06-12 23:35:27 +02:00
|
|
|
// tx 51bf528ecf3c161e7c021224197dbe84f9a8564212f6207baa014c01a1668e1e
|
|
|
|
// first instance of an AnyoneCanPay signature in the blockchain
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "CheckSigHashAnyoneCanPay",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-12 23:35:27 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0xf6, 0x04, 0x4c, 0x0a,
|
|
|
|
0xd4, 0x85, 0xf6, 0x33,
|
|
|
|
0xb4, 0x1f, 0x97, 0xd0,
|
|
|
|
0xd7, 0x93, 0xeb, 0x28,
|
|
|
|
0x37, 0xae, 0x40, 0xf7,
|
|
|
|
0x38, 0xff, 0x6d, 0x5f,
|
|
|
|
0x50, 0xfd, 0xfd, 0x10,
|
|
|
|
0x52, 0x8c, 0x1d, 0x76,
|
|
|
|
}),
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_72,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x45, 0x02, 0x20, 0x58,
|
|
|
|
0x53, 0xc7, 0xf1, 0x39, 0x57,
|
|
|
|
0x85, 0xbf, 0xab, 0xb0, 0x3c,
|
|
|
|
0x57, 0xe9, 0x62, 0xeb, 0x07,
|
|
|
|
0x6f, 0xf2, 0x4d, 0x8e, 0x4e,
|
|
|
|
0x57, 0x3b, 0x04, 0xdb, 0x13,
|
|
|
|
0xb4, 0x5e, 0xd3, 0xed, 0x6e,
|
|
|
|
0xe2, 0x02, 0x21, 0x00, 0x9d,
|
|
|
|
0xc8, 0x2a, 0xe4, 0x3b, 0xe9,
|
|
|
|
0xd4, 0xb1, 0xfe, 0x28, 0x47,
|
|
|
|
0x75, 0x4e, 0x1d, 0x36, 0xda,
|
|
|
|
0xd4, 0x8b, 0xa8, 0x01, 0x81,
|
|
|
|
0x7d, 0x48, 0x5d, 0xc5, 0x29,
|
|
|
|
0xaf, 0xc5, 0x16, 0xc2, 0xdd,
|
|
|
|
0xb4, 0x81,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x03, 0x05, 0x58, 0x49, 0x80,
|
|
|
|
0x36, 0x7b, 0x32, 0x1f, 0xad,
|
|
|
|
0x7f, 0x1c, 0x1f, 0x4d, 0x5d,
|
|
|
|
0x72, 0x3d, 0x0a, 0xc8, 0x0c,
|
|
|
|
0x1d, 0x80, 0xc8, 0xba, 0x12,
|
|
|
|
0x34, 0x39, 0x65, 0xb4, 0x83,
|
|
|
|
0x64, 0x53, 0x7a,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0x9c, 0x6a, 0xf0, 0xdf,
|
|
|
|
0x66, 0x69, 0xbc, 0xde,
|
|
|
|
0xd1, 0x9e, 0x31, 0x7e,
|
|
|
|
0x25, 0xbe, 0xbc, 0x8c,
|
|
|
|
0x78, 0xe4, 0x8d, 0xf8,
|
|
|
|
0xae, 0x1f, 0xe0, 0x2a,
|
|
|
|
0x7f, 0x03, 0x08, 0x18,
|
|
|
|
0xe7, 0x1e, 0xcd, 0x40,
|
|
|
|
}),
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_73,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x46, 0x02, 0x21, 0x00,
|
|
|
|
0x82, 0x69, 0xc9, 0xd7, 0xba,
|
|
|
|
0x0a, 0x7e, 0x73, 0x0d, 0xd1,
|
|
|
|
0x6f, 0x40, 0x82, 0xd2, 0x9e,
|
|
|
|
0x36, 0x84, 0xfb, 0x74, 0x63,
|
|
|
|
0xba, 0x06, 0x4f, 0xd0, 0x93,
|
|
|
|
0xaf, 0xc1, 0x70, 0xad, 0x6e,
|
|
|
|
0x03, 0x88, 0x02, 0x21, 0x00,
|
|
|
|
0xbc, 0x6d, 0x76, 0x37, 0x39,
|
|
|
|
0x16, 0xa3, 0xff, 0x6e, 0xe4,
|
|
|
|
0x1b, 0x2c, 0x75, 0x20, 0x01,
|
|
|
|
0xfd, 0xa3, 0xc9, 0xe0, 0x48,
|
|
|
|
0xbc, 0xff, 0x0d, 0x81, 0xd0,
|
|
|
|
0x5b, 0x39, 0xff, 0x0f, 0x42,
|
|
|
|
0x17, 0xb2, 0x81,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x03, 0xaa, 0xe3, 0x03, 0xd8,
|
|
|
|
0x25, 0x42, 0x15, 0x45, 0xc5,
|
|
|
|
0xbc, 0x7c, 0xcd, 0x5a, 0xc8,
|
|
|
|
0x7d, 0xd5, 0xad, 0xd3, 0xbc,
|
|
|
|
0xc3, 0xa4, 0x32, 0xba, 0x7a,
|
|
|
|
0xa2, 0xf2, 0x66, 0x16, 0x99,
|
|
|
|
0xf9, 0xf6, 0x59,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 300000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x5c, 0x11, 0xf9, 0x17, 0x88,
|
|
|
|
0x3b, 0x92, 0x7e, 0xef, 0x77,
|
|
|
|
0xdc, 0x57, 0x70, 0x7a, 0xeb,
|
|
|
|
0x85, 0x3f, 0x6d, 0x38, 0x94,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x85, 0x51, 0xe4, 0x8a, 0x53, 0xde, 0xcd, 0x1c, 0xfc,
|
|
|
|
0x63, 0x07, 0x9a, 0x45, 0x81, 0xbc, 0xcc, 0xfa, 0xd1,
|
|
|
|
0xa9, 0x3c,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-06-21 02:33:56 +02:00
|
|
|
idx: 0,
|
|
|
|
bip16: true, // after threshold
|
2013-06-20 19:07:44 +02:00
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.PubKeyHashTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 2,
|
|
|
|
ExpectedInputs: 2,
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// tx 6d36bc17e947ce00bb6f12f8e7a56a1585c5a36188ffa2b05e10b4743273a74b
|
|
|
|
// Uses OP_CODESEPARATOR and OP_CHECKMULTISIG
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "CheckMultiSig",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-12 23:35:27 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0x37, 0xb1, 0x7d, 0x76,
|
|
|
|
0x38, 0x51, 0xcd, 0x1a,
|
|
|
|
0xb0, 0x4a, 0x42, 0x44,
|
|
|
|
0x63, 0xd4, 0x13, 0xc4,
|
|
|
|
0xee, 0x5c, 0xf6, 0x13,
|
|
|
|
0x04, 0xc7, 0xfd, 0x76,
|
|
|
|
0x97, 0x7b, 0xea, 0x7f,
|
|
|
|
0xce, 0x07, 0x57, 0x05,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0x02,
|
|
|
|
0xdb, 0xe4, 0xb5, 0xa2, 0xfb,
|
|
|
|
0xb5, 0x21, 0xe4, 0xdc, 0x5f,
|
|
|
|
0xbe, 0xc7, 0x5f, 0xd9, 0x60,
|
|
|
|
0x65, 0x1a, 0x27, 0x54, 0xb0,
|
|
|
|
0x3d, 0x08, 0x71, 0xb8, 0xc9,
|
|
|
|
0x65, 0x46, 0x9b, 0xe5, 0x0f,
|
|
|
|
0xa7, 0x02, 0x20, 0x6d, 0x97,
|
|
|
|
0x42, 0x1f, 0xb7, 0xea, 0x93,
|
|
|
|
0x59, 0xb6, 0x3e, 0x48, 0xc2,
|
|
|
|
0x10, 0x82, 0x23, 0x28, 0x4b,
|
|
|
|
0x9a, 0x71, 0x56, 0x0b, 0xd8,
|
|
|
|
0x18, 0x24, 0x69, 0xb9, 0x03,
|
|
|
|
0x92, 0x28, 0xd7, 0xb3, 0xd7,
|
|
|
|
0x01, 0x21, 0x02, 0x95, 0xbf,
|
|
|
|
0x72, 0x71, 0x11, 0xac, 0xde,
|
|
|
|
0xab, 0x87, 0x78, 0x28, 0x4f,
|
|
|
|
0x02, 0xb7, 0x68, 0xd1, 0xe2,
|
|
|
|
0x1a, 0xcb, 0xcb, 0xae, 0x42,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0x37, 0xb1, 0x7d, 0x76,
|
|
|
|
0x38, 0x51, 0xcd, 0x1a,
|
|
|
|
0xb0, 0x4a, 0x42, 0x44,
|
|
|
|
0x63, 0xd4, 0x13, 0xc4,
|
|
|
|
0xee, 0x5c, 0xf6, 0x13,
|
|
|
|
0x04, 0xc7, 0xfd, 0x76,
|
|
|
|
0x97, 0x7b, 0xea, 0x7f,
|
|
|
|
0xce, 0x07, 0x57, 0x05,
|
|
|
|
}),
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
SignatureScript: []uint8{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_FALSE,
|
|
|
|
txscript.OP_DATA_72,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x45, 0x02, 0x20, 0x10,
|
|
|
|
0x6a, 0x3e, 0x4e, 0xf0, 0xb5,
|
|
|
|
0x1b, 0x76, 0x4a, 0x28, 0x87,
|
|
|
|
0x22, 0x62, 0xff, 0xef, 0x55,
|
|
|
|
0x84, 0x65, 0x14, 0xda, 0xcb,
|
|
|
|
0xdc, 0xbb, 0xdd, 0x65, 0x2c,
|
|
|
|
0x84, 0x9d, 0x39, 0x5b, 0x43,
|
|
|
|
0x84, 0x02, 0x21, 0x00, 0xe0,
|
|
|
|
0x3a, 0xe5, 0x54, 0xc3, 0xcb,
|
|
|
|
0xb4, 0x06, 0x00, 0xd3, 0x1d,
|
|
|
|
0xd4, 0x6f, 0xc3, 0x3f, 0x25,
|
|
|
|
0xe4, 0x7b, 0xf8, 0x52, 0x5b,
|
|
|
|
0x1f, 0xe0, 0x72, 0x82, 0xe3,
|
|
|
|
0xb6, 0xec, 0xb5, 0xf3, 0xbb,
|
|
|
|
0x28, 0x01,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CODESEPARATOR,
|
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_33,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89,
|
|
|
|
0x3e, 0x7f, 0x06, 0x31, 0x36,
|
|
|
|
0x4d, 0x7f, 0xd0, 0x1c, 0xb3,
|
|
|
|
0x3d, 0x24, 0xda, 0x45, 0x32,
|
|
|
|
0x9a, 0x00, 0x35, 0x7b, 0x3a,
|
|
|
|
0x78, 0x86, 0x21, 0x1a, 0xb4,
|
|
|
|
0x14, 0xd5, 0x5a,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 4800000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x0d, 0x77, 0x13, 0x64, 0x9f,
|
|
|
|
0x9a, 0x06, 0x78, 0xf4, 0xe8,
|
|
|
|
0x80, 0xb4, 0x0f, 0x86, 0xb9,
|
|
|
|
0x32, 0x89, 0xd1, 0xbb, 0x27,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
// This is a very weird script...
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x2a, 0x9b, 0xc5, 0x44, 0x7d, 0x66, 0x4c, 0x1d, 0x01,
|
|
|
|
0x41, 0x39, 0x2a, 0x84, 0x2d, 0x23, 0xdb, 0xa4, 0x5c,
|
|
|
|
0x4f, 0x13,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_NOP2, txscript.OP_DROP,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-10-09 01:13:52 +02:00
|
|
|
idx: 1,
|
|
|
|
bip16: false,
|
|
|
|
nSigOps: 0, // multisig is in the pkScript!
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfoErr: txscript.ErrStackNonPushOnly,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// same as previous but with one byte changed to make signature fail
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "CheckMultiSig fail",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-12 23:35:27 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0x37, 0xb1, 0x7d, 0x76,
|
|
|
|
0x38, 0x51, 0xcd, 0x1a,
|
|
|
|
0xb0, 0x4a, 0x42, 0x44,
|
|
|
|
0x63, 0xd4, 0x13, 0xc4,
|
|
|
|
0xee, 0x5c, 0xf6, 0x13,
|
|
|
|
0x04, 0xc7, 0xfd, 0x76,
|
|
|
|
0x97, 0x7b, 0xea, 0x7f,
|
|
|
|
0xce, 0x07, 0x57, 0x05,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_71,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x44, 0x02, 0x20, 0x02,
|
|
|
|
0xdb, 0xe4, 0xb5, 0xa2, 0xfb,
|
|
|
|
0xb5, 0x21, 0xe4, 0xdc, 0x5f,
|
|
|
|
0xbe, 0xc7, 0x5f, 0xd9, 0x60,
|
|
|
|
0x65, 0x1a, 0x27, 0x54, 0xb0,
|
|
|
|
0x3d, 0x08, 0x71, 0xb8, 0xc9,
|
|
|
|
0x65, 0x46, 0x9b, 0xe5, 0x0f,
|
|
|
|
0xa7, 0x02, 0x20, 0x6d, 0x97,
|
|
|
|
0x42, 0x1f, 0xb7, 0xea, 0x93,
|
|
|
|
0x59, 0xb6, 0x3e, 0x48, 0xc2,
|
|
|
|
0x10, 0x82, 0x23, 0x28, 0x4b,
|
|
|
|
0x9a, 0x71, 0x56, 0x0b, 0xd8,
|
|
|
|
0x18, 0x24, 0x69, 0xb9, 0x03,
|
|
|
|
0x92, 0x28, 0xd7, 0xb3, 0xd7,
|
|
|
|
0x01, 0x21, 0x02, 0x95, 0xbf,
|
|
|
|
0x72, 0x71, 0x11, 0xac, 0xde,
|
|
|
|
0xab, 0x87, 0x78, 0x28, 0x4f,
|
|
|
|
0x02, 0xb7, 0x68, 0xd1, 0xe2,
|
|
|
|
0x1a, 0xcb, 0xcb, 0xae, 0x42,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0x37, 0xb1, 0x7d, 0x76,
|
|
|
|
0x38, 0x51, 0xcd, 0x1a,
|
|
|
|
0xb0, 0x4a, 0x42, 0x44,
|
|
|
|
0x63, 0xd4, 0x13, 0xc4,
|
|
|
|
0xee, 0x5c, 0xf6, 0x13,
|
|
|
|
0x04, 0xc7, 0xfd, 0x76,
|
|
|
|
0x97, 0x7b, 0xea, 0x7f,
|
|
|
|
0xce, 0x07, 0x57, 0x05,
|
|
|
|
}),
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
SignatureScript: []uint8{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_FALSE,
|
|
|
|
txscript.OP_DATA_72,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x30, 0x45, 0x02, 0x20, 0x10,
|
|
|
|
0x6a, 0x3e, 0x4e, 0xf0, 0xb5,
|
|
|
|
0x1b, 0x76, 0x4a, 0x28, 0x87,
|
|
|
|
0x22, 0x62, 0xff, 0xef, 0x55,
|
|
|
|
0x84, 0x65, 0x14, 0xda, 0xcb,
|
|
|
|
0xdc, 0xbb, 0xdd, 0x65, 0x2c,
|
|
|
|
0x84, 0x9d, 0x39, 0x5b, 0x43,
|
|
|
|
0x84, 0x02, 0x21, 0x00, 0xe0,
|
|
|
|
0x3a, 0xe5, 0x54, 0xc3, 0xcb,
|
|
|
|
0xb4, 0x06, 0x00, 0xd3, 0x1d,
|
|
|
|
0xd4, 0x6f, 0xc3, 0x3f, 0x25,
|
|
|
|
0xe4, 0x7b, 0xf8, 0x52, 0x5b,
|
|
|
|
0x1f, 0xe0, 0x72, 0x82, 0xe3,
|
|
|
|
0xb6, 0xec, 0xb5, 0xf3, 0xbb,
|
|
|
|
0x28, 0x01,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CODESEPARATOR,
|
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_33,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89,
|
|
|
|
0x3e, 0x7f, 0x06, 0x31, 0x36,
|
|
|
|
0x4d, 0x7f, 0xd0, 0x1c, 0xb3,
|
|
|
|
0x3d, 0x24, 0xda, 0x45, 0x32,
|
|
|
|
0x9a, 0x00, 0x35, 0x7b, 0x3a,
|
|
|
|
0x78, 0x86, 0x21, 0x1a, 0xb4,
|
|
|
|
0x14, 0xd5, 0x5a,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 5800000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x0d, 0x77, 0x13, 0x64, 0x9f,
|
|
|
|
0x9a, 0x06, 0x78, 0xf4, 0xe8,
|
|
|
|
0x80, 0xb4, 0x0f, 0x86, 0xb9,
|
|
|
|
0x32, 0x89, 0xd1, 0xbb, 0x27,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
// This is a very weird script...
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x2a, 0x9b, 0xc5, 0x44, 0x7d, 0x66, 0x4c, 0x1d, 0x01,
|
|
|
|
0x41, 0x39, 0x2a, 0x84, 0x2d, 0x23, 0xdb, 0xa4, 0x5c,
|
|
|
|
0x4f, 0x13,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_NOP2, txscript.OP_DROP,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-10-09 01:13:52 +02:00
|
|
|
idx: 1,
|
|
|
|
bip16: false,
|
2015-01-30 07:03:01 +01:00
|
|
|
err: txscript.ErrStackScriptFailed,
|
2013-10-09 01:13:52 +02:00
|
|
|
nSigOps: 0, // multisig is in the pkScript!
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfoErr: txscript.ErrStackNonPushOnly,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-19 23:52:11 +01:00
|
|
|
// taken from tx b2d93dfd0b2c1a380e55e76a8d9cb3075dec9f4474e9485be008c337fd62c1f7
|
|
|
|
// on testnet
|
|
|
|
// multisig with zero required signatures
|
|
|
|
{
|
|
|
|
name: "CheckMultiSig zero required signatures",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2014-02-19 23:52:11 +01:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-19 23:52:11 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2014-02-19 23:52:11 +01:00
|
|
|
0x37, 0xb1, 0x7d, 0x76,
|
|
|
|
0x38, 0x51, 0xcd, 0x1a,
|
|
|
|
0xb0, 0x4a, 0x42, 0x44,
|
|
|
|
0x63, 0xd4, 0x13, 0xc4,
|
|
|
|
0xee, 0x5c, 0xf6, 0x13,
|
|
|
|
0x04, 0xc7, 0xfd, 0x76,
|
|
|
|
0x97, 0x7b, 0xea, 0x7f,
|
|
|
|
0xce, 0x07, 0x57, 0x05,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_0,
|
|
|
|
txscript.OP_DATA_37,
|
|
|
|
txscript.OP_0,
|
|
|
|
txscript.OP_DATA_33,
|
2014-02-19 23:52:11 +01:00
|
|
|
0x02, 0x4a, 0xb3, 0x3c, 0x3a,
|
|
|
|
0x54, 0x7a, 0x37, 0x29, 0x3e,
|
|
|
|
0xb8, 0x75, 0xb4, 0xbb, 0xdb,
|
|
|
|
0xd4, 0x73, 0xe9, 0xd4, 0xba,
|
|
|
|
0xfd, 0xf3, 0x56, 0x87, 0xe7,
|
|
|
|
0x97, 0x44, 0xdc, 0xd7, 0x0f,
|
|
|
|
0x6e, 0x4d, 0xe2,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_1,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2014-02-19 23:52:11 +01:00
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{},
|
2014-02-19 23:52:11 +01:00
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2014-02-19 23:52:11 +01:00
|
|
|
0x2c, 0x6b, 0x10, 0x7f, 0xdf, 0x10, 0x6f, 0x22, 0x6f,
|
|
|
|
0x3f, 0xa3, 0x27, 0xba, 0x36, 0xd6, 0xe3, 0xca, 0xc7,
|
|
|
|
0x3d, 0xf0,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUAL,
|
2014-02-19 23:52:11 +01:00
|
|
|
},
|
|
|
|
idx: 0,
|
|
|
|
bip16: true,
|
|
|
|
nSigOps: 1,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.ScriptHashTy,
|
2014-02-19 23:52:11 +01:00
|
|
|
NumInputs: 2,
|
2014-03-17 05:07:20 +01:00
|
|
|
ExpectedInputs: 2,
|
2014-02-19 23:52:11 +01:00
|
|
|
SigOps: 1,
|
|
|
|
},
|
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
// tx e5779b9e78f9650debc2893fd9636d827b26b4ddfa6a8172fe8708c924f5c39d
|
|
|
|
// First P2SH transaction in the blockchain
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "P2SH",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-12 23:35:27 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-12 23:35:27 +02:00
|
|
|
0x6d, 0x58, 0xf8, 0xa3,
|
|
|
|
0xaa, 0x43, 0x0b, 0x84,
|
|
|
|
0x78, 0x52, 0x3a, 0x65,
|
|
|
|
0xc2, 0x03, 0xa2, 0x7b,
|
|
|
|
0xb8, 0x81, 0x17, 0x8c,
|
|
|
|
0xb1, 0x23, 0x13, 0xaf,
|
|
|
|
0xde, 0x29, 0xf9, 0x2e,
|
|
|
|
0xd7, 0x56, 0xaa, 0x7e,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_2,
|
2013-06-12 23:35:27 +02:00
|
|
|
// OP_3 OP_7
|
|
|
|
0x53, 0x57,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
Value: 1000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x5b, 0x69, 0xd8, 0xb9, 0xdf,
|
|
|
|
0xa6, 0xe4, 0x12, 0x26, 0x47,
|
|
|
|
0xe1, 0x79, 0x4e, 0xaa, 0x3b,
|
|
|
|
0xfc, 0x11, 0x1f, 0x70, 0xef,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x43, 0x3e, 0xc2, 0xac, 0x1f, 0xfa, 0x1b, 0x7b, 0x7d,
|
|
|
|
0x02, 0x7f, 0x56, 0x45, 0x29, 0xc5, 0x71, 0x97, 0xf9,
|
|
|
|
0xae, 0x88,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUAL,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-06-21 02:33:56 +02:00
|
|
|
idx: 0,
|
|
|
|
bip16: true,
|
2013-06-20 19:07:44 +02:00
|
|
|
nSigOps: 0, // no signature ops in the pushed script.
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.ScriptHashTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 1,
|
|
|
|
ExpectedInputs: -1, // p2sh script is non standard
|
|
|
|
SigOps: 0,
|
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-06-25 01:12:08 +02:00
|
|
|
// next few tests are modified versions of previous to hit p2sh error
|
|
|
|
// cases.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 01:12:08 +02:00
|
|
|
// sigscript changed so that pkscript hash will not match.
|
|
|
|
name: "P2SH - bad hash",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-25 01:12:08 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-25 01:12:08 +02:00
|
|
|
0x6d, 0x58, 0xf8, 0xa3,
|
|
|
|
0xaa, 0x43, 0x0b, 0x84,
|
|
|
|
0x78, 0x52, 0x3a, 0x65,
|
|
|
|
0xc2, 0x03, 0xa2, 0x7b,
|
|
|
|
0xb8, 0x81, 0x17, 0x8c,
|
|
|
|
0xb1, 0x23, 0x13, 0xaf,
|
|
|
|
0xde, 0x29, 0xf9, 0x2e,
|
|
|
|
0xd7, 0x56, 0xaa, 0x7e,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_2,
|
2013-06-25 01:12:08 +02:00
|
|
|
// OP_3 OP_8
|
|
|
|
0x53, 0x58,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 01:12:08 +02:00
|
|
|
Value: 1000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-25 01:12:08 +02:00
|
|
|
0x5b, 0x69, 0xd8, 0xb9, 0xdf,
|
|
|
|
0xa6, 0xe4, 0x12, 0x26, 0x47,
|
|
|
|
0xe1, 0x79, 0x4e, 0xaa, 0x3b,
|
|
|
|
0xfc, 0x11, 0x1f, 0x70, 0xef,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-25 01:12:08 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-25 01:12:08 +02:00
|
|
|
0x43, 0x3e, 0xc2, 0xac, 0x1f, 0xfa, 0x1b, 0x7b, 0x7d,
|
|
|
|
0x02, 0x7f, 0x56, 0x45, 0x29, 0xc5, 0x71, 0x97, 0xf9,
|
|
|
|
0xae, 0x88,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUAL,
|
2013-06-25 01:12:08 +02:00
|
|
|
},
|
|
|
|
idx: 0,
|
2015-01-30 07:03:01 +01:00
|
|
|
err: txscript.ErrStackScriptFailed,
|
2013-06-25 01:12:08 +02:00
|
|
|
bip16: true,
|
|
|
|
nSigOps: 0, // no signature ops in the pushed script.
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.ScriptHashTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 1,
|
|
|
|
ExpectedInputs: -1, // p2sh script is non standard
|
|
|
|
SigOps: 0,
|
|
|
|
},
|
2013-06-25 01:12:08 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 01:12:08 +02:00
|
|
|
// sigscript changed so that pkscript hash will not match.
|
|
|
|
name: "P2SH - doesn't parse",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-25 01:12:08 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-25 01:12:08 +02:00
|
|
|
0x6d, 0x58, 0xf8, 0xa3,
|
|
|
|
0xaa, 0x43, 0x0b, 0x84,
|
|
|
|
0x78, 0x52, 0x3a, 0x65,
|
|
|
|
0xc2, 0x03, 0xa2, 0x7b,
|
|
|
|
0xb8, 0x81, 0x17, 0x8c,
|
|
|
|
0xb1, 0x23, 0x13, 0xaf,
|
|
|
|
0xde, 0x29, 0xf9, 0x2e,
|
|
|
|
0xd7, 0x56, 0xaa, 0x7e,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_2,
|
2013-06-25 01:12:08 +02:00
|
|
|
// pushed script.
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_2, 0x1,
|
2013-06-25 01:12:08 +02:00
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 01:12:08 +02:00
|
|
|
Value: 1000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-25 01:12:08 +02:00
|
|
|
0x5b, 0x69, 0xd8, 0xb9, 0xdf,
|
|
|
|
0xa6, 0xe4, 0x12, 0x26, 0x47,
|
|
|
|
0xe1, 0x79, 0x4e, 0xaa, 0x3b,
|
|
|
|
0xfc, 0x11, 0x1f, 0x70, 0xef,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-25 01:12:08 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-25 01:12:08 +02:00
|
|
|
0xd4, 0x8c, 0xe8, 0x6c, 0x69, 0x8f, 0x24, 0x68, 0x29,
|
|
|
|
0x92, 0x1b, 0xa9, 0xfb, 0x2a, 0x84, 0x4a, 0xe2, 0xad,
|
2013-06-25 14:12:15 +02:00
|
|
|
0xba, 0x67,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUAL,
|
2013-06-25 01:12:08 +02:00
|
|
|
},
|
2013-10-09 01:13:52 +02:00
|
|
|
idx: 0,
|
2015-01-30 07:03:01 +01:00
|
|
|
err: txscript.ErrStackShortScript,
|
2013-10-09 01:13:52 +02:00
|
|
|
bip16: true,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfoErr: txscript.ErrStackShortScript,
|
2013-06-25 01:12:08 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 14:12:15 +02:00
|
|
|
// sigscript changed so to be non pushonly.
|
|
|
|
name: "P2SH - non pushonly",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-25 14:12:15 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-25 14:12:15 +02:00
|
|
|
0x6d, 0x58, 0xf8, 0xa3,
|
|
|
|
0xaa, 0x43, 0x0b, 0x84,
|
|
|
|
0x78, 0x52, 0x3a, 0x65,
|
|
|
|
0xc2, 0x03, 0xa2, 0x7b,
|
|
|
|
0xb8, 0x81, 0x17, 0x8c,
|
|
|
|
0xb1, 0x23, 0x13, 0xaf,
|
|
|
|
0xde, 0x29, 0xf9, 0x2e,
|
|
|
|
0xd7, 0x56, 0xaa, 0x7e,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
// doesn't have to match signature.
|
|
|
|
// will never run.
|
|
|
|
SignatureScript: []byte{
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_2,
|
2013-06-25 14:12:15 +02:00
|
|
|
// pushed script.
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_1, 0x1,
|
|
|
|
txscript.OP_DUP,
|
2013-06-25 14:12:15 +02:00
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 14:12:15 +02:00
|
|
|
Value: 1000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-25 14:12:15 +02:00
|
|
|
0x5b, 0x69, 0xd8, 0xb9, 0xdf,
|
|
|
|
0xa6, 0xe4, 0x12, 0x26, 0x47,
|
|
|
|
0xe1, 0x79, 0x4e, 0xaa, 0x3b,
|
|
|
|
0xfc, 0x11, 0x1f, 0x70, 0xef,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-25 14:12:15 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-25 14:12:15 +02:00
|
|
|
0x43, 0x3e, 0xc2, 0xac, 0x1f, 0xfa, 0x1b, 0x7b, 0x7d,
|
|
|
|
0x02, 0x7f, 0x56, 0x45, 0x29, 0xc5, 0x71, 0x97, 0xf9,
|
|
|
|
0xae, 0x88,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUAL,
|
2013-06-25 14:12:15 +02:00
|
|
|
},
|
2013-10-09 01:13:52 +02:00
|
|
|
idx: 0,
|
2015-01-30 07:03:01 +01:00
|
|
|
parseErr: txscript.ErrStackP2SHNonPushOnly,
|
2013-10-09 01:13:52 +02:00
|
|
|
bip16: true,
|
|
|
|
nSigOps: 0, // no signature ops in the pushed script.
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfoErr: txscript.ErrStackNonPushOnly,
|
2013-06-25 14:12:15 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-26 15:16:00 +02:00
|
|
|
// sigscript changed so to be non pushonly.
|
|
|
|
name: "empty pkScript",
|
2015-02-05 22:16:39 +01:00
|
|
|
tx: &wire.MsgTx{
|
2013-06-26 15:16:00 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-26 15:16:00 +02:00
|
|
|
0x6d, 0x58, 0xf8, 0xa3,
|
|
|
|
0xaa, 0x43, 0x0b, 0x84,
|
|
|
|
0x78, 0x52, 0x3a, 0x65,
|
|
|
|
0xc2, 0x03, 0xa2, 0x7b,
|
|
|
|
0xb8, 0x81, 0x17, 0x8c,
|
|
|
|
0xb1, 0x23, 0x13, 0xaf,
|
|
|
|
0xde, 0x29, 0xf9, 0x2e,
|
|
|
|
0xd7, 0x56, 0xaa, 0x7e,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
// doesn't have to match signature.
|
|
|
|
// will never run.
|
|
|
|
SignatureScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
2013-06-26 15:16:00 +02:00
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-26 15:16:00 +02:00
|
|
|
Value: 1000000,
|
|
|
|
PkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-26 15:16:00 +02:00
|
|
|
0x5b, 0x69, 0xd8, 0xb9, 0xdf,
|
|
|
|
0xa6, 0xe4, 0x12, 0x26, 0x47,
|
|
|
|
0xe1, 0x79, 0x4e, 0xaa, 0x3b,
|
|
|
|
0xfc, 0x11, 0x1f, 0x70, 0xef,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-26 15:16:00 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
},
|
|
|
|
pkScript: []byte{},
|
|
|
|
idx: 0,
|
|
|
|
bip16: true,
|
|
|
|
nSigOps: 0, // no signature ops in the pushed script.
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.NonStandardTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 1,
|
|
|
|
ExpectedInputs: -1,
|
|
|
|
SigOps: 0,
|
|
|
|
},
|
2013-06-26 15:16:00 +02:00
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a number of tx from the blockchain to test otherwise difficult to test
|
|
|
|
// opcodes (i.e. those that involve signatures). Being from the blockchain,
|
|
|
|
// these transactions are known good.
|
|
|
|
// TODO(oga) For signatures we currently do not test SigHashSingle because
|
|
|
|
// nothing in the blockchain that we have yet seen uses them, making it hard
|
|
|
|
// to confirm we implemented the spec correctly.
|
|
|
|
func testTx(t *testing.T, test txTest) {
|
2015-01-30 07:03:01 +01:00
|
|
|
var flags txscript.ScriptFlags
|
2013-10-24 16:13:58 +02:00
|
|
|
if test.bip16 {
|
2015-01-30 07:03:01 +01:00
|
|
|
flags |= txscript.ScriptBip16
|
2013-10-24 16:13:58 +02:00
|
|
|
}
|
2015-02-14 15:37:47 +01:00
|
|
|
if test.strictSigs {
|
|
|
|
flags |= txscript.ScriptVerifyDERSignatures
|
2013-10-24 16:13:58 +02:00
|
|
|
}
|
2015-04-20 07:32:43 +02:00
|
|
|
engine, err := txscript.NewScript(test.pkScript, test.tx, test.idx,
|
|
|
|
flags)
|
2013-06-12 23:35:27 +02:00
|
|
|
if err != nil {
|
2013-06-25 14:12:15 +02:00
|
|
|
if err != test.parseErr {
|
|
|
|
t.Errorf("Failed to parse %s: got \"%v\" expected "+
|
|
|
|
"\"%v\"", test.name, err, test.parseErr)
|
|
|
|
}
|
2013-06-12 23:35:27 +02:00
|
|
|
return
|
|
|
|
}
|
2013-06-25 14:12:15 +02:00
|
|
|
if test.parseErr != nil {
|
|
|
|
t.Errorf("%s: parse succeeded when expecting \"%v\"", test.name,
|
|
|
|
test.parseErr)
|
|
|
|
}
|
2013-06-12 23:35:27 +02:00
|
|
|
|
|
|
|
err = engine.Execute()
|
|
|
|
if err != nil {
|
2013-06-19 00:36:44 +02:00
|
|
|
// failed means no specified error
|
|
|
|
if test.shouldFail == true {
|
|
|
|
return
|
|
|
|
}
|
2013-06-12 23:35:27 +02:00
|
|
|
if err != test.err {
|
|
|
|
t.Errorf("Failed to validate %s tx: %v expected %v",
|
|
|
|
test.name, err, test.err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2013-06-19 00:36:44 +02:00
|
|
|
if test.err != nil || test.shouldFail == true {
|
2013-06-12 23:35:27 +02:00
|
|
|
t.Errorf("%s: expected failure: %v, succeeded", test.name,
|
|
|
|
test.err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTX(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-12 23:35:27 +02:00
|
|
|
for i := range txTests {
|
|
|
|
testTx(t, txTests[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 19:07:44 +02:00
|
|
|
func TestGetPreciseSignOps(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-24 17:32:41 +02:00
|
|
|
// First we go over the range of tests in testTx and count the sigops in
|
|
|
|
// them.
|
2013-06-20 19:07:44 +02:00
|
|
|
for _, test := range txTests {
|
2015-01-30 07:03:01 +01:00
|
|
|
count := txscript.GetPreciseSigOpCount(
|
2013-06-20 19:07:44 +02:00
|
|
|
test.tx.TxIn[test.idx].SignatureScript, test.pkScript,
|
|
|
|
test.bip16)
|
|
|
|
if count != test.nSigOps {
|
|
|
|
t.Errorf("%s: expected count of %d, got %d", test.name,
|
|
|
|
test.nSigOps, count)
|
2013-06-21 02:33:56 +02:00
|
|
|
|
2013-06-20 19:07:44 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-24 17:32:41 +02:00
|
|
|
|
|
|
|
// Now we go over a number of tests to hit the more awkward error
|
|
|
|
// conditions in the P2SH cases..
|
|
|
|
|
|
|
|
type psocTest struct {
|
2013-06-25 14:12:15 +02:00
|
|
|
name string
|
2013-06-24 17:32:41 +02:00
|
|
|
scriptSig []byte
|
2013-06-25 14:12:15 +02:00
|
|
|
nSigOps int
|
|
|
|
err error
|
2013-06-24 17:32:41 +02:00
|
|
|
}
|
|
|
|
psocTests := []psocTest{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 14:12:15 +02:00
|
|
|
name: "scriptSig doesn't parse",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptSig: []byte{txscript.OP_PUSHDATA1, 2},
|
|
|
|
err: txscript.ErrStackShortScript,
|
2013-06-24 17:32:41 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 14:12:15 +02:00
|
|
|
name: "scriptSig isn't push only",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptSig: []byte{txscript.OP_1, txscript.OP_DUP},
|
2013-06-25 14:12:15 +02:00
|
|
|
nSigOps: 0,
|
2013-06-24 17:32:41 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-25 14:12:15 +02:00
|
|
|
name: "scriptSig length 0",
|
2013-06-24 17:32:41 +02:00
|
|
|
scriptSig: []byte{},
|
2013-06-25 14:12:15 +02:00
|
|
|
nSigOps: 0,
|
2013-06-24 17:32:41 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-24 17:32:41 +02:00
|
|
|
name: "No script at the end",
|
|
|
|
// No script at end but still push only.
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptSig: []byte{txscript.OP_1, txscript.OP_1},
|
2013-06-25 14:12:15 +02:00
|
|
|
nSigOps: 0,
|
2013-06-24 17:32:41 +02:00
|
|
|
},
|
|
|
|
// pushed script doesn't parse.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-24 17:32:41 +02:00
|
|
|
name: "pushed script doesn't parse",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptSig: []byte{txscript.OP_DATA_2,
|
|
|
|
txscript.OP_PUSHDATA1, 2},
|
|
|
|
err: txscript.ErrStackShortScript,
|
2013-06-24 17:32:41 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
// The signature in the p2sh script is nonsensical for the tests since
|
|
|
|
// this script will never be executed. What matters is that it matches
|
|
|
|
// the right pattern.
|
|
|
|
pkScript := []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-24 17:32:41 +02:00
|
|
|
0x43, 0x3e, 0xc2, 0xac, 0x1f, 0xfa, 0x1b, 0x7b, 0x7d,
|
|
|
|
0x02, 0x7f, 0x56, 0x45, 0x29, 0xc5, 0x71, 0x97, 0xf9,
|
|
|
|
0xae, 0x88,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUAL,
|
2013-06-24 17:32:41 +02:00
|
|
|
}
|
|
|
|
for _, test := range psocTests {
|
2015-01-30 07:03:01 +01:00
|
|
|
count := txscript.GetPreciseSigOpCount(
|
2013-06-24 17:32:41 +02:00
|
|
|
test.scriptSig, pkScript, true)
|
|
|
|
if count != test.nSigOps {
|
|
|
|
t.Errorf("%s: expected count of %d, got %d", test.name,
|
|
|
|
test.nSigOps, count)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-06-20 19:07:44 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 01:13:52 +02:00
|
|
|
type scriptInfoTest struct {
|
|
|
|
name string
|
|
|
|
sigScript []byte
|
|
|
|
pkScript []byte
|
|
|
|
bip16 bool
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo txscript.ScriptInfo
|
2013-10-09 01:13:52 +02:00
|
|
|
scriptInfoErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScriptInfo(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-10-09 01:13:52 +02:00
|
|
|
for _, test := range txTests {
|
2015-01-30 07:03:01 +01:00
|
|
|
si, err := txscript.CalcScriptInfo(
|
2013-10-09 01:13:52 +02:00
|
|
|
test.tx.TxIn[test.idx].SignatureScript,
|
|
|
|
test.pkScript, test.bip16)
|
|
|
|
if err != nil {
|
|
|
|
if err != test.scriptInfoErr {
|
|
|
|
t.Errorf("scriptinfo test \"%s\": got \"%v\""+
|
|
|
|
"expected \"%v\"", test.name, err,
|
|
|
|
test.scriptInfoErr)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if test.scriptInfoErr != nil {
|
|
|
|
t.Errorf("%s: succeeded when expecting \"%v\"",
|
|
|
|
test.name, test.scriptInfoErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if *si != test.scriptInfo {
|
|
|
|
t.Errorf("%s: scriptinfo doesn't match expected. "+
|
|
|
|
"got: \"%v\" expected \"%v\"", test.name,
|
|
|
|
*si, test.scriptInfo)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extraTests := []scriptInfoTest{
|
|
|
|
{
|
|
|
|
// Invented scripts, the hashes do not match
|
|
|
|
name: "pkscript doesn't parse",
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript: []byte{txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_1, 81,
|
|
|
|
txscript.OP_DATA_8,
|
|
|
|
txscript.OP_2DUP, txscript.OP_EQUAL,
|
|
|
|
txscript.OP_NOT, txscript.OP_VERIFY,
|
|
|
|
txscript.OP_ABS, txscript.OP_SWAP,
|
|
|
|
txscript.OP_ABS, txscript.OP_EQUAL,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
// truncated version of test below:
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript: []byte{txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-09 01:13:52 +02:00
|
|
|
0xfe, 0x44, 0x10, 0x65, 0xb6, 0x53, 0x22, 0x31,
|
|
|
|
0xde, 0x2f, 0xac, 0x56, 0x31, 0x52, 0x20, 0x5e,
|
|
|
|
0xc4, 0xf5, 0x9c,
|
|
|
|
},
|
|
|
|
bip16: true,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfoErr: txscript.ErrStackShortScript,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sigScript doesn't parse",
|
|
|
|
// Truncated version of p2sh script below.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript: []byte{txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_1, 81,
|
|
|
|
txscript.OP_DATA_8,
|
|
|
|
txscript.OP_2DUP, txscript.OP_EQUAL,
|
|
|
|
txscript.OP_NOT, txscript.OP_VERIFY,
|
|
|
|
txscript.OP_ABS, txscript.OP_SWAP,
|
|
|
|
txscript.OP_ABS,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript: []byte{txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-09 01:13:52 +02:00
|
|
|
0xfe, 0x44, 0x10, 0x65, 0xb6, 0x53, 0x22, 0x31,
|
|
|
|
0xde, 0x2f, 0xac, 0x56, 0x31, 0x52, 0x20, 0x5e,
|
2015-01-30 07:03:01 +01:00
|
|
|
0xc4, 0xf5, 0x9c, 0x74, txscript.OP_EQUAL,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
bip16: true,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfoErr: txscript.ErrStackShortScript,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Invented scripts, the hashes do not match
|
|
|
|
name: "p2sh standard script",
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript: []byte{txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_1, 81,
|
|
|
|
txscript.OP_DATA_25,
|
|
|
|
txscript.OP_DUP, txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20, 0x1, 0x2, 0x3, 0x4, 0x5,
|
2013-10-09 01:13:52 +02:00
|
|
|
0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe,
|
|
|
|
0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY, txscript.OP_CHECKSIG,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript: []byte{txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-09 01:13:52 +02:00
|
|
|
0xfe, 0x44, 0x10, 0x65, 0xb6, 0x53, 0x22, 0x31,
|
|
|
|
0xde, 0x2f, 0xac, 0x56, 0x31, 0x52, 0x20, 0x5e,
|
2015-01-30 07:03:01 +01:00
|
|
|
0xc4, 0xf5, 0x9c, 0x74, txscript.OP_EQUAL,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
bip16: true,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.ScriptHashTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 3,
|
|
|
|
ExpectedInputs: 3, // nonstandard p2sh.
|
|
|
|
SigOps: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// from 567a53d1ce19ce3d07711885168484439965501536d0d0294c5d46d46c10e53b
|
|
|
|
// from the blockchain.
|
|
|
|
name: "p2sh nonstandard script",
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript: []byte{txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_1, 81,
|
|
|
|
txscript.OP_DATA_8,
|
|
|
|
txscript.OP_2DUP, txscript.OP_EQUAL,
|
|
|
|
txscript.OP_NOT, txscript.OP_VERIFY,
|
|
|
|
txscript.OP_ABS, txscript.OP_SWAP,
|
|
|
|
txscript.OP_ABS, txscript.OP_EQUAL,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript: []byte{txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-10-09 01:13:52 +02:00
|
|
|
0xfe, 0x44, 0x10, 0x65, 0xb6, 0x53, 0x22, 0x31,
|
|
|
|
0xde, 0x2f, 0xac, 0x56, 0x31, 0x52, 0x20, 0x5e,
|
2015-01-30 07:03:01 +01:00
|
|
|
0xc4, 0xf5, 0x9c, 0x74, txscript.OP_EQUAL,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
bip16: true,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.ScriptHashTy,
|
2013-10-09 01:13:52 +02:00
|
|
|
NumInputs: 3,
|
|
|
|
ExpectedInputs: -1, // nonstandard p2sh.
|
|
|
|
SigOps: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Script is invented, numbers all fake.
|
|
|
|
name: "multisig script",
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript: []byte{txscript.OP_TRUE,
|
|
|
|
txscript.OP_TRUE, txscript.OP_TRUE,
|
|
|
|
txscript.OP_0, // Extra arg for OP_CHECKMULTISIG bug
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
pkScript: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_3, txscript.OP_DATA_33,
|
2013-10-09 01:13:52 +02:00
|
|
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9,
|
|
|
|
0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12,
|
|
|
|
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
|
|
|
|
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2013-10-09 01:13:52 +02:00
|
|
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9,
|
|
|
|
0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12,
|
|
|
|
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
|
|
|
|
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2013-10-09 01:13:52 +02:00
|
|
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9,
|
|
|
|
0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12,
|
|
|
|
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
|
|
|
|
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_3, txscript.OP_CHECKMULTISIG,
|
2013-10-09 01:13:52 +02:00
|
|
|
},
|
|
|
|
bip16: true,
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptInfo: txscript.ScriptInfo{
|
|
|
|
PkScriptClass: txscript.MultiSigTy,
|
2014-03-17 05:07:20 +01:00
|
|
|
NumInputs: 4,
|
|
|
|
ExpectedInputs: 4,
|
2013-10-09 01:13:52 +02:00
|
|
|
SigOps: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range extraTests {
|
2015-01-30 07:03:01 +01:00
|
|
|
si, err := txscript.CalcScriptInfo(test.sigScript,
|
2013-10-09 01:13:52 +02:00
|
|
|
test.pkScript, test.bip16)
|
|
|
|
if err != nil {
|
|
|
|
if err != test.scriptInfoErr {
|
|
|
|
t.Errorf("scriptinfo test \"%s\": got \"%v\""+
|
|
|
|
"expected \"%v\"", test.name, err,
|
|
|
|
test.scriptInfoErr)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if test.scriptInfoErr != nil {
|
|
|
|
t.Errorf("%s: succeeded when expecting \"%v\"",
|
|
|
|
test.name, test.scriptInfoErr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if *si != test.scriptInfo {
|
|
|
|
t.Errorf("%s: scriptinfo doesn't match expected. "+
|
|
|
|
"got: \"%v\" expected \"%v\"", test.name,
|
|
|
|
*si, test.scriptInfo)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-12 23:35:27 +02:00
|
|
|
type removeOpcodeTest struct {
|
|
|
|
name string
|
|
|
|
before []byte
|
|
|
|
remove byte
|
|
|
|
err error
|
|
|
|
after []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
var removeOpcodeTests = []removeOpcodeTest{
|
|
|
|
// Nothing to remove.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "nothing to remove",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_NOP},
|
|
|
|
remove: txscript.OP_CODESEPARATOR,
|
|
|
|
after: []byte{txscript.OP_NOP},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// Test basic opcode removal
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "codeseparator 1",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_NOP, txscript.OP_CODESEPARATOR,
|
|
|
|
txscript.OP_TRUE},
|
|
|
|
remove: txscript.OP_CODESEPARATOR,
|
|
|
|
after: []byte{txscript.OP_NOP, txscript.OP_TRUE},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// The opcode in question is actually part of the data in a previous
|
|
|
|
// opcode
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "codeseparator by coincidence",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_NOP, txscript.OP_DATA_1, txscript.OP_CODESEPARATOR,
|
|
|
|
txscript.OP_TRUE},
|
|
|
|
remove: txscript.OP_CODESEPARATOR,
|
|
|
|
after: []byte{txscript.OP_NOP, txscript.OP_DATA_1, txscript.OP_CODESEPARATOR,
|
|
|
|
txscript.OP_TRUE},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "invalid opcode",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_UNKNOWN186},
|
|
|
|
remove: txscript.OP_CODESEPARATOR,
|
|
|
|
after: []byte{txscript.OP_UNKNOWN186},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "invalid length (insruction)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_PUSHDATA1},
|
|
|
|
remove: txscript.OP_CODESEPARATOR,
|
|
|
|
err: txscript.ErrStackShortScript,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "invalid length (data)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_PUSHDATA1, 255, 254},
|
|
|
|
remove: txscript.OP_CODESEPARATOR,
|
|
|
|
err: txscript.ErrStackShortScript,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRemoveOpcode(t *testing.T, test *removeOpcodeTest) {
|
2015-01-30 07:03:01 +01:00
|
|
|
result, err := txscript.TstRemoveOpcode(test.before, test.remove)
|
2013-06-12 23:35:27 +02:00
|
|
|
if test.err != nil {
|
|
|
|
if err != test.err {
|
|
|
|
t.Errorf("%s: got unexpected error. exp: \"%v\" "+
|
|
|
|
"got: \"%v\"", test.name, test.err, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s: unexpected failure: \"%v\"", test.name, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !bytes.Equal(test.after, result) {
|
|
|
|
t.Errorf("%s: value does not equal expected: exp: \"%v\""+
|
|
|
|
" got: \"%v\"", test.name, test.after, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveOpcodes(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-12 23:35:27 +02:00
|
|
|
for i := range removeOpcodeTests {
|
|
|
|
testRemoveOpcode(t, &removeOpcodeTests[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type removeOpcodeByDataTest struct {
|
|
|
|
name string
|
|
|
|
before []byte
|
|
|
|
remove []byte
|
|
|
|
err error
|
|
|
|
after []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
var removeOpcodeByDataTests = []removeOpcodeByDataTest{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "nothing to do",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_NOP},
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: []byte{txscript.OP_NOP},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "simple case",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_DATA_4, 1, 2, 3, 4},
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
|
|
|
after: []byte{},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "simple case (miss)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_DATA_4, 1, 2, 3, 4},
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 5},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: []byte{txscript.OP_DATA_4, 1, 2, 3, 4},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-03-18 18:54:29 +01:00
|
|
|
// padded to keep it canonical.
|
|
|
|
name: "simple case (pushdata1)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: append(append([]byte{txscript.OP_PUSHDATA1, 76},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 72)...), []byte{1, 2, 3, 4}...),
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
|
|
|
after: []byte{},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-03-18 18:54:29 +01:00
|
|
|
name: "simple case (pushdata1 miss)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: append(append([]byte{txscript.OP_PUSHDATA1, 76},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 72)...), []byte{1, 2, 3, 4}...),
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 5},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: append(append([]byte{txscript.OP_PUSHDATA1, 76},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 72)...), []byte{1, 2, 3, 4}...),
|
2014-03-18 18:54:29 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple case (pushdata1 miss noncanonical)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_PUSHDATA1, 4, 1, 2, 3, 4},
|
2014-03-18 18:54:29 +01:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: []byte{txscript.OP_PUSHDATA1, 4, 1, 2, 3, 4},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-03-18 18:54:29 +01:00
|
|
|
name: "simple case (pushdata2)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: append(append([]byte{txscript.OP_PUSHDATA2, 0, 1},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 252)...), []byte{1, 2, 3, 4}...),
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
|
|
|
after: []byte{},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-03-18 18:54:29 +01:00
|
|
|
name: "simple case (pushdata2 miss)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: append(append([]byte{txscript.OP_PUSHDATA2, 0, 1},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 252)...), []byte{1, 2, 3, 4}...),
|
2014-03-18 18:54:29 +01:00
|
|
|
remove: []byte{1, 2, 3, 4, 5},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: append(append([]byte{txscript.OP_PUSHDATA2, 0, 1},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 252)...), []byte{1, 2, 3, 4}...),
|
2014-03-18 18:54:29 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple case (pushdata2 miss noncanonical)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_PUSHDATA2, 4, 0, 1, 2, 3, 4},
|
2014-03-18 18:54:29 +01:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: []byte{txscript.OP_PUSHDATA2, 4, 0, 1, 2, 3, 4},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-03-18 18:54:29 +01:00
|
|
|
// This is padded to make the push canonical.
|
|
|
|
name: "simple case (pushdata4)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: append(append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...),
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
|
|
|
after: []byte{},
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-03-18 18:54:29 +01:00
|
|
|
name: "simple case (pushdata4 miss noncanonical)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4},
|
2014-03-18 18:54:29 +01:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: []byte{txscript.OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-03-18 18:54:29 +01:00
|
|
|
{
|
|
|
|
// This is padded to make the push canonical.
|
|
|
|
name: "simple case (pushdata4 miss)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: append(append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...),
|
2014-03-18 18:54:29 +01:00
|
|
|
remove: []byte{1, 2, 3, 4, 5},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: append(append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0},
|
2014-04-11 20:54:44 +02:00
|
|
|
bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...),
|
2014-03-18 18:54:29 +01:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "invalid opcode ",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_UNKNOWN187},
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
2015-01-30 07:03:01 +01:00
|
|
|
after: []byte{txscript.OP_UNKNOWN187},
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "invalid length (instruction)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_PUSHDATA1},
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
2015-01-30 07:03:01 +01:00
|
|
|
err: txscript.ErrStackShortScript,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "invalid length (data)",
|
2015-01-30 07:03:01 +01:00
|
|
|
before: []byte{txscript.OP_PUSHDATA1, 255, 254},
|
2013-06-12 23:35:27 +02:00
|
|
|
remove: []byte{1, 2, 3, 4},
|
2015-01-30 07:03:01 +01:00
|
|
|
err: txscript.ErrStackShortScript,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRemoveOpcodeByData(t *testing.T, test *removeOpcodeByDataTest) {
|
2015-01-30 07:03:01 +01:00
|
|
|
result, err := txscript.TstRemoveOpcodeByData(test.before,
|
2013-06-12 23:35:27 +02:00
|
|
|
test.remove)
|
|
|
|
if test.err != nil {
|
|
|
|
if err != test.err {
|
|
|
|
t.Errorf("%s: got unexpected error. exp: \"%v\" "+
|
|
|
|
"got: \"%v\"", test.name, test.err, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s: unexpected failure: \"%v\"", test.name, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !bytes.Equal(test.after, result) {
|
|
|
|
t.Errorf("%s: value does not equal expected: exp: \"%v\""+
|
|
|
|
" got: \"%v\"", test.name, test.after, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestRemoveOpcodeByDatas(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-12 23:35:27 +02:00
|
|
|
for i := range removeOpcodeByDataTests {
|
|
|
|
testRemoveOpcodeByData(t, &removeOpcodeByDataTests[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for the script type logic
|
|
|
|
|
|
|
|
type scriptTypeTest struct {
|
|
|
|
name string
|
|
|
|
script []byte
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype txscript.ScriptClass
|
2013-06-12 23:35:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var scriptTypeTests = []scriptTypeTest{
|
|
|
|
// tx 0437cd7f8525ceed2324359c2d0ba26006d92d85.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "Pay Pubkey",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01,
|
|
|
|
0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6,
|
|
|
|
0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7,
|
|
|
|
0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea,
|
|
|
|
0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8,
|
|
|
|
0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4,
|
|
|
|
0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4,
|
|
|
|
0x12, 0xa3,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.PubKeyTy,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// tx 599e47a8114fe098103663029548811d2651991b62397e057f0c863c2bc9f9ea
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "Pay PubkeyHash",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x66, 0x0d, 0x4e, 0xf3, 0xa7, 0x43, 0xe3, 0xe6, 0x96,
|
|
|
|
0xad, 0x99, 0x03, 0x64, 0xe5, 0x55, 0xc2, 0x71, 0xad,
|
|
|
|
0x50, 0x4b,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUALVERIFY,
|
|
|
|
txscript.OP_CHECKSIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.PubKeyHashTy,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// part of tx 6d36bc17e947ce00bb6f12f8e7a56a1585c5a36188ffa2b05e10b4743273a74b
|
|
|
|
// codeseparator parts have been elided. (bitcoind's checks for multisig
|
|
|
|
// type doesn't have codesep etc either.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "multisig",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_33,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89, 0x3e, 0x7f, 0x06, 0x31,
|
|
|
|
0x36, 0x4d, 0x7f, 0xd0, 0x1c, 0xb3, 0x3d, 0x24, 0xda,
|
|
|
|
0x45, 0x32, 0x9a, 0x00, 0x35, 0x7b, 0x3a, 0x78, 0x86,
|
|
|
|
0x21, 0x1a, 0xb4, 0x14, 0xd5, 0x5a,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.MultiSigTy,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
|
|
|
// tx e5779b9e78f9650debc2893fd9636d827b26b4ddfa6a8172fe8708c924f5c39d
|
|
|
|
// P2SH
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-12 23:35:27 +02:00
|
|
|
name: "P2SH",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_HASH160,
|
|
|
|
txscript.OP_DATA_20,
|
2013-06-12 23:35:27 +02:00
|
|
|
0x43, 0x3e, 0xc2, 0xac, 0x1f, 0xfa, 0x1b, 0x7b, 0x7d,
|
|
|
|
0x02, 0x7f, 0x56, 0x45, 0x29, 0xc5, 0x71, 0x97, 0xf9,
|
|
|
|
0xae, 0x88,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_EQUAL,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.ScriptHashTy,
|
2013-06-12 23:35:27 +02:00
|
|
|
},
|
2013-11-14 22:07:35 +01:00
|
|
|
// Nulldata with no data at all.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-11-14 22:07:35 +01:00
|
|
|
name: "nulldata",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_RETURN,
|
2013-11-14 22:07:35 +01:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NullDataTy,
|
2013-11-14 22:07:35 +01:00
|
|
|
},
|
|
|
|
// Nulldata with small data.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-11-14 22:07:35 +01:00
|
|
|
name: "nulldata2",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_RETURN,
|
|
|
|
txscript.OP_DATA_8,
|
2013-11-14 22:07:35 +01:00
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NullDataTy,
|
2013-11-14 22:07:35 +01:00
|
|
|
},
|
|
|
|
// Nulldata with max allowed data.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-11-14 22:07:35 +01:00
|
|
|
name: "nulldata3",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_RETURN,
|
|
|
|
txscript.OP_PUSHDATA1,
|
2015-02-28 14:50:38 +01:00
|
|
|
0x50, // 80
|
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
0xeb, 0x64, 0x9f, 0x6b, 0xc3, 0xf4, 0xce, 0xf3,
|
2013-11-14 22:07:35 +01:00
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
0xeb, 0x64, 0x9f, 0x6b, 0xc3, 0xf4, 0xce, 0xf3,
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NullDataTy,
|
2013-11-14 22:07:35 +01:00
|
|
|
},
|
|
|
|
// Nulldata with more than max allowed data (so therefore nonstandard)
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-11-14 22:07:35 +01:00
|
|
|
name: "nulldata4",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_RETURN,
|
|
|
|
txscript.OP_PUSHDATA1,
|
2015-02-28 14:50:38 +01:00
|
|
|
0x51, // 81
|
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
0xeb, 0x64, 0x9f, 0x6b, 0xc3, 0xf4, 0xce, 0xf3,
|
2013-11-14 22:07:35 +01:00
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
0xeb, 0x64, 0x9f, 0x6b, 0xc3, 0xf4, 0xce, 0xf3,
|
|
|
|
0x08,
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-11-14 22:07:35 +01:00
|
|
|
},
|
|
|
|
// Almost nulldata, but add an additional opcode after the data to make
|
|
|
|
// it nonstandard.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-11-14 22:07:35 +01:00
|
|
|
name: "nulldata5",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_RETURN,
|
|
|
|
txscript.OP_DATA_1,
|
2013-11-14 22:07:35 +01:00
|
|
|
0x04,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
2013-11-14 22:07:35 +01:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-11-14 22:07:35 +01:00
|
|
|
}, // The next few are almost multisig (it is the more complex script type)
|
2013-06-27 00:28:44 +02:00
|
|
|
// but with various changes to make it fail.
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-27 00:28:44 +02:00
|
|
|
// multisig but funny nsigs..
|
|
|
|
name: "strange 1",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DUP,
|
|
|
|
txscript.OP_DATA_33,
|
2013-06-27 00:28:44 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89, 0x3e, 0x7f, 0x06, 0x31,
|
|
|
|
0x36, 0x4d, 0x7f, 0xd0, 0x1c, 0xb3, 0x3d, 0x24, 0xda,
|
|
|
|
0x45, 0x32, 0x9a, 0x00, 0x35, 0x7b, 0x3a, 0x78, 0x86,
|
|
|
|
0x21, 0x1a, 0xb4, 0x14, 0xd5, 0x5a,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-27 00:28:44 +02:00
|
|
|
name: "strange 2",
|
|
|
|
// multisig but funny pubkey.
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-27 00:28:44 +02:00
|
|
|
name: "strange 3",
|
|
|
|
// multisig but no matching npubkeys opcode.
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_33,
|
2013-06-27 00:28:44 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89, 0x3e, 0x7f, 0x06, 0x31,
|
|
|
|
0x36, 0x4d, 0x7f, 0xd0, 0x1c, 0xb3, 0x3d, 0x24, 0xda,
|
|
|
|
0x45, 0x32, 0x9a, 0x00, 0x35, 0x7b, 0x3a, 0x78, 0x86,
|
|
|
|
0x21, 0x1a, 0xb4, 0x14, 0xd5, 0x5a,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2013-06-27 00:28:44 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89, 0x3e, 0x7f, 0x06, 0x31,
|
|
|
|
0x36, 0x4d, 0x7f, 0xd0, 0x1c, 0xb3, 0x3d, 0x24, 0xda,
|
|
|
|
0x45, 0x32, 0x9a, 0x00, 0x35, 0x7b, 0x3a, 0x78, 0x86,
|
|
|
|
0x21, 0x1a, 0xb4, 0x14, 0xd5, 0x5a,
|
|
|
|
// No number.
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CHECKMULTISIG,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-27 00:28:44 +02:00
|
|
|
name: "strange 4",
|
|
|
|
// multisig but with multisigverify
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_33,
|
2013-06-27 00:28:44 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89, 0x3e, 0x7f, 0x06, 0x31,
|
|
|
|
0x36, 0x4d, 0x7f, 0xd0, 0x1c, 0xb3, 0x3d, 0x24, 0xda,
|
|
|
|
0x45, 0x32, 0x9a, 0x00, 0x35, 0x7b, 0x3a, 0x78, 0x86,
|
|
|
|
0x21, 0x1a, 0xb4, 0x14, 0xd5, 0x5a,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIGVERIFY,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-27 00:28:44 +02:00
|
|
|
name: "strange 5",
|
|
|
|
// multisig but wrong length.
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-06-27 00:28:44 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-27 01:32:11 +02:00
|
|
|
name: "doesn't parse",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_5, 0x1, 0x2, 0x3, 0x4,
|
2013-06-27 01:32:11 +02:00
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype: txscript.NonStandardTy,
|
2013-06-27 01:32:11 +02:00
|
|
|
},
|
2013-06-12 23:35:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func testScriptType(t *testing.T, test *scriptTypeTest) {
|
2015-01-30 07:03:01 +01:00
|
|
|
scripttype := txscript.GetScriptClass(test.script)
|
2013-06-12 23:35:27 +02:00
|
|
|
if scripttype != test.scripttype {
|
|
|
|
t.Errorf("%s: expected %s got %s", test.name, test.scripttype,
|
|
|
|
scripttype)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestScriptTypes(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-12 23:35:27 +02:00
|
|
|
for i := range scriptTypeTests {
|
|
|
|
testScriptType(t, &scriptTypeTests[i])
|
|
|
|
}
|
|
|
|
}
|
2013-06-20 00:31:44 +02:00
|
|
|
|
2013-06-27 01:32:11 +02:00
|
|
|
func TestIsPayToScriptHash(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-27 01:32:11 +02:00
|
|
|
for _, test := range scriptTypeTests {
|
2015-01-30 07:03:01 +01:00
|
|
|
shouldBe := (test.scripttype == txscript.ScriptHashTy)
|
|
|
|
p2sh := txscript.IsPayToScriptHash(test.script)
|
2013-06-27 01:32:11 +02:00
|
|
|
if p2sh != shouldBe {
|
|
|
|
t.Errorf("%s: epxected p2sh %v, got %v", test.name,
|
|
|
|
shouldBe, p2sh)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 00:31:44 +02:00
|
|
|
// This test sets the pc to a deliberately bad result then confirms that Step()
|
|
|
|
// and Disasm fail correctly.
|
|
|
|
func TestBadPC(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-20 00:31:44 +02:00
|
|
|
type pcTest struct {
|
|
|
|
script, off int
|
|
|
|
}
|
|
|
|
pcTests := []pcTest{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-21 02:33:56 +02:00
|
|
|
script: 2,
|
|
|
|
off: 0,
|
2013-06-20 00:31:44 +02:00
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-20 00:31:44 +02:00
|
|
|
script: 0,
|
2013-06-21 02:33:56 +02:00
|
|
|
off: 2,
|
2013-06-20 00:31:44 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
// tx with almost empty scripts.
|
2015-02-05 22:16:39 +01:00
|
|
|
tx := &wire.MsgTx{
|
2013-06-20 00:31:44 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-20 00:31:44 +02:00
|
|
|
0xc9, 0x97, 0xa5, 0xe5,
|
|
|
|
0x6e, 0x10, 0x41, 0x02,
|
|
|
|
0xfa, 0x20, 0x9c, 0x6a,
|
|
|
|
0x85, 0x2d, 0xd9, 0x06,
|
|
|
|
0x60, 0xa2, 0x0b, 0x2d,
|
|
|
|
0x9c, 0x35, 0x24, 0x23,
|
|
|
|
0xed, 0xce, 0x25, 0x85,
|
|
|
|
0x7f, 0xcd, 0x37, 0x04,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
SignatureScript: []uint8{txscript.OP_NOP},
|
2013-06-21 02:33:56 +02:00
|
|
|
Sequence: 4294967295,
|
2013-06-20 00:31:44 +02:00
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-21 02:33:56 +02:00
|
|
|
Value: 1000000000,
|
2013-06-20 00:31:44 +02:00
|
|
|
PkScript: []byte{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
}
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript := []byte{txscript.OP_NOP}
|
2013-06-20 00:31:44 +02:00
|
|
|
|
|
|
|
for _, test := range pcTests {
|
2015-04-20 07:32:43 +02:00
|
|
|
engine, err := txscript.NewScript(pkScript, tx, 0, 0)
|
2013-06-20 00:31:44 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to create script: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set to after all scripts
|
|
|
|
engine.TstSetPC(test.script, test.off)
|
|
|
|
|
|
|
|
_, err = engine.Step()
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Step with invalid pc (%v) succeeds!", test)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = engine.DisasmPC()
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("DisasmPC with invalid pc (%v) succeeds!",
|
|
|
|
test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-21 02:33:38 +02:00
|
|
|
|
|
|
|
// Most codepaths in CheckErrorCondition() are testd elsewhere, this tests
|
|
|
|
// the execute early test.
|
|
|
|
func TestCheckErrorCondition(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2013-06-21 02:33:38 +02:00
|
|
|
// tx with almost empty scripts.
|
2015-02-05 22:16:39 +01:00
|
|
|
tx := &wire.MsgTx{
|
2013-06-21 02:33:38 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
2013-06-21 02:33:38 +02:00
|
|
|
0xc9, 0x97, 0xa5, 0xe5,
|
|
|
|
0x6e, 0x10, 0x41, 0x02,
|
|
|
|
0xfa, 0x20, 0x9c, 0x6a,
|
|
|
|
0x85, 0x2d, 0xd9, 0x06,
|
|
|
|
0x60, 0xa2, 0x0b, 0x2d,
|
|
|
|
0x9c, 0x35, 0x24, 0x23,
|
|
|
|
0xed, 0xce, 0x25, 0x85,
|
|
|
|
0x7f, 0xcd, 0x37, 0x04,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []uint8{},
|
2013-06-21 02:33:56 +02:00
|
|
|
Sequence: 4294967295,
|
2013-06-21 02:33:38 +02:00
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-06-21 02:33:56 +02:00
|
|
|
Value: 1000000000,
|
2013-06-21 02:33:38 +02:00
|
|
|
PkScript: []byte{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
}
|
|
|
|
pkScript := []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_NOP,
|
|
|
|
txscript.OP_TRUE,
|
2013-06-21 02:33:38 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 07:32:43 +02:00
|
|
|
engine, err := txscript.NewScript(pkScript, tx, 0, 0)
|
2013-06-21 02:33:38 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to create script: %v", err)
|
|
|
|
}
|
|
|
|
|
2013-06-21 02:33:56 +02:00
|
|
|
for i := 0; i < len(pkScript)-1; i++ {
|
2013-06-21 02:33:38 +02:00
|
|
|
done, err := engine.Step()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to step %dth time: %v", i, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if done {
|
|
|
|
t.Errorf("finshed early on %dth time", i)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-02-25 21:04:37 +01:00
|
|
|
err = engine.CheckErrorCondition(false)
|
2015-01-30 07:03:01 +01:00
|
|
|
if err != txscript.ErrStackScriptUnfinished {
|
2013-06-21 02:33:38 +02:00
|
|
|
t.Errorf("got unexepected error %v on %dth iteration",
|
|
|
|
err, i)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done, err := engine.Step()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("final step failed %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !done {
|
|
|
|
t.Errorf("final step isn't done!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-02-25 21:04:37 +01:00
|
|
|
err = engine.CheckErrorCondition(false)
|
2013-06-21 02:33:38 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error %v on final check", err)
|
|
|
|
}
|
|
|
|
}
|
2013-09-10 17:39:29 +02:00
|
|
|
|
|
|
|
type TstSigScript struct {
|
|
|
|
name string
|
|
|
|
inputs []TstInput
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType txscript.SigHashType
|
2013-09-10 17:39:29 +02:00
|
|
|
compress bool
|
|
|
|
scriptAtWrongIndex bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type TstInput struct {
|
2015-02-05 22:16:39 +01:00
|
|
|
txout *wire.TxOut
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates bool
|
|
|
|
inputValidates bool
|
|
|
|
indexOutOfRange bool
|
|
|
|
}
|
|
|
|
|
2015-02-05 22:16:39 +01:00
|
|
|
var coinbaseOutPoint = &wire.OutPoint{
|
2013-09-10 17:39:29 +02:00
|
|
|
Index: (1 << 32) - 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pregenerated private key, with associated public key and pkScripts
|
|
|
|
// for the uncompressed and compressed hash160.
|
|
|
|
var (
|
2014-08-25 22:14:19 +02:00
|
|
|
privKeyD = []byte{0x6b, 0x0f, 0xd8, 0xda, 0x54, 0x22, 0xd0, 0xb7,
|
2013-09-10 17:39:29 +02:00
|
|
|
0xb4, 0xfc, 0x4e, 0x55, 0xd4, 0x88, 0x42, 0xb3, 0xa1, 0x65,
|
|
|
|
0xac, 0x70, 0x7f, 0x3d, 0xa4, 0x39, 0x5e, 0xcb, 0x3b, 0xb0,
|
|
|
|
0xd6, 0x0e, 0x06, 0x92}
|
|
|
|
pubkeyX = []byte{0xb2, 0x52, 0xf0, 0x49, 0x85, 0x78, 0x03, 0x03, 0xc8,
|
|
|
|
0x7d, 0xce, 0x51, 0x7f, 0xa8, 0x69, 0x0b, 0x91, 0x95, 0xf4,
|
|
|
|
0xf3, 0x5c, 0x26, 0x73, 0x05, 0x05, 0xa2, 0xee, 0xbc, 0x09,
|
|
|
|
0x38, 0x34, 0x3a}
|
|
|
|
pubkeyY = []byte{0xb7, 0xc6, 0x7d, 0xb2, 0xe1, 0xff, 0xc8, 0x43, 0x1f,
|
|
|
|
0x63, 0x32, 0x62, 0xaa, 0x60, 0xc6, 0x83, 0x30, 0xbd, 0x24,
|
|
|
|
0x7e, 0xef, 0xdb, 0x6f, 0x2e, 0x8d, 0x56, 0xf0, 0x3c, 0x9f,
|
|
|
|
0x6d, 0xb6, 0xf8}
|
|
|
|
uncompressedPkScript = []byte{0x76, 0xa9, 0x14, 0xd1, 0x7c, 0xb5,
|
|
|
|
0xeb, 0xa4, 0x02, 0xcb, 0x68, 0xe0, 0x69, 0x56, 0xbf, 0x32,
|
|
|
|
0x53, 0x90, 0x0e, 0x0a, 0x86, 0xc9, 0xfa, 0x88, 0xac}
|
|
|
|
compressedPkScript = []byte{0x76, 0xa9, 0x14, 0x27, 0x4d, 0x9f, 0x7f,
|
|
|
|
0x61, 0x7e, 0x7c, 0x7a, 0x1c, 0x1f, 0xb2, 0x75, 0x79, 0x10,
|
|
|
|
0x43, 0x65, 0x68, 0x27, 0x9d, 0x86, 0x88, 0xac}
|
|
|
|
shortPkScript = []byte{0x76, 0xa9, 0x14, 0xd1, 0x7c, 0xb5,
|
|
|
|
0xeb, 0xa4, 0x02, 0xcb, 0x68, 0xe0, 0x69, 0x56, 0xbf, 0x32,
|
|
|
|
0x53, 0x90, 0x0e, 0x0a, 0x88, 0xac}
|
|
|
|
uncompressedAddrStr = "1L6fd93zGmtzkK6CsZFVVoCwzZV3MUtJ4F"
|
|
|
|
compressedAddrStr = "14apLppt9zTq6cNw8SDfiJhk9PhkZrQtYZ"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Pretend output amounts.
|
|
|
|
const coinbaseVal = 2500000000
|
|
|
|
const fee = 5000000
|
|
|
|
|
|
|
|
var SigScriptTests = []TstSigScript{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "one input uncompressed",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "two inputs uncompressed",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "one input compressed",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, compressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: true,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "two inputs compressed",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, compressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal+fee, compressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: true,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-10-11 21:55:28 +02:00
|
|
|
name: "hashType SigHashNone",
|
2013-09-10 17:39:29 +02:00
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashNone,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-10-11 21:55:28 +02:00
|
|
|
name: "hashType SigHashSingle",
|
2013-09-10 17:39:29 +02:00
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashSingle,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-10-11 21:55:28 +02:00
|
|
|
name: "hashType SigHashAnyoneCanPay",
|
2013-09-10 17:39:29 +02:00
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAnyOneCanPay,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2014-10-11 21:55:28 +02:00
|
|
|
name: "hashType non-standard",
|
2013-09-10 17:39:29 +02:00
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2014-10-11 21:55:28 +02:00
|
|
|
hashType: 0x04,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "invalid compression",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: false,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: true,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "short PkScript",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, shortPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: false,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "valid script at wrong index",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: true,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2013-09-10 17:39:29 +02:00
|
|
|
name: "index out of range",
|
|
|
|
inputs: []TstInput{
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
2014-02-04 22:18:37 +01:00
|
|
|
{
|
2015-02-05 22:16:39 +01:00
|
|
|
txout: wire.NewTxOut(coinbaseVal+fee, uncompressedPkScript),
|
2013-09-10 17:39:29 +02:00
|
|
|
sigscriptGenerates: true,
|
|
|
|
inputValidates: true,
|
|
|
|
indexOutOfRange: false,
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType: txscript.SigHashAll,
|
2013-09-10 17:39:29 +02:00
|
|
|
compress: false,
|
|
|
|
scriptAtWrongIndex: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the sigscript generation for valid and invalid inputs, all
|
2014-10-11 21:55:28 +02:00
|
|
|
// hashTypes, and with and without compression. This test creates
|
2013-09-10 17:39:29 +02:00
|
|
|
// sigscripts to spend fake coinbase inputs, as sigscripts cannot be
|
|
|
|
// created for the MsgTxs in txTests, since they come from the blockchain
|
|
|
|
// and we don't have the private keys.
|
|
|
|
func TestSignatureScript(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
privKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), privKeyD)
|
2013-09-10 17:39:29 +02:00
|
|
|
|
|
|
|
nexttest:
|
|
|
|
for i := range SigScriptTests {
|
2015-02-05 22:16:39 +01:00
|
|
|
tx := wire.NewMsgTx()
|
2013-09-10 17:39:29 +02:00
|
|
|
|
2015-02-05 22:16:39 +01:00
|
|
|
output := wire.NewTxOut(500, []byte{txscript.OP_RETURN})
|
2013-09-10 17:39:29 +02:00
|
|
|
tx.AddTxOut(output)
|
|
|
|
|
|
|
|
for _ = range SigScriptTests[i].inputs {
|
2015-02-05 22:16:39 +01:00
|
|
|
txin := wire.NewTxIn(coinbaseOutPoint, nil)
|
2013-09-10 17:39:29 +02:00
|
|
|
tx.AddTxIn(txin)
|
|
|
|
}
|
|
|
|
|
|
|
|
var script []byte
|
|
|
|
var err error
|
|
|
|
for j := range tx.TxIn {
|
|
|
|
var idx int
|
|
|
|
if SigScriptTests[i].inputs[j].indexOutOfRange {
|
|
|
|
t.Errorf("at test %v", SigScriptTests[i].name)
|
|
|
|
idx = len(SigScriptTests[i].inputs)
|
|
|
|
} else {
|
|
|
|
idx = j
|
|
|
|
}
|
2015-01-30 07:03:01 +01:00
|
|
|
script, err = txscript.SignatureScript(tx, idx,
|
2014-04-18 00:15:30 +02:00
|
|
|
SigScriptTests[i].inputs[j].txout.PkScript,
|
2014-10-11 21:55:28 +02:00
|
|
|
SigScriptTests[i].hashType, privKey,
|
2014-04-18 00:15:30 +02:00
|
|
|
SigScriptTests[i].compress)
|
2013-09-10 17:39:29 +02:00
|
|
|
|
|
|
|
if (err == nil) != SigScriptTests[i].inputs[j].sigscriptGenerates {
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("passed test '%v' incorrectly",
|
|
|
|
SigScriptTests[i].name)
|
|
|
|
} else {
|
|
|
|
t.Errorf("failed test '%v': %v",
|
|
|
|
SigScriptTests[i].name, err)
|
|
|
|
}
|
|
|
|
continue nexttest
|
|
|
|
}
|
|
|
|
if !SigScriptTests[i].inputs[j].sigscriptGenerates {
|
|
|
|
// done with this test
|
|
|
|
continue nexttest
|
|
|
|
}
|
|
|
|
|
|
|
|
tx.TxIn[j].SignatureScript = script
|
|
|
|
}
|
|
|
|
|
|
|
|
// If testing using a correct sigscript but for an incorrect
|
|
|
|
// index, use last input script for first input. Requires > 0
|
|
|
|
// inputs for test.
|
|
|
|
if SigScriptTests[i].scriptAtWrongIndex {
|
|
|
|
tx.TxIn[0].SignatureScript = script
|
|
|
|
SigScriptTests[i].inputs[0].inputValidates = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate tx input scripts
|
2015-02-14 15:37:47 +01:00
|
|
|
scriptFlags := txscript.ScriptBip16 | txscript.ScriptVerifyDERSignatures
|
2015-04-20 07:32:43 +02:00
|
|
|
for j := range tx.TxIn {
|
|
|
|
engine, err := txscript.NewScript(SigScriptTests[i].
|
|
|
|
inputs[j].txout.PkScript, tx, j, scriptFlags)
|
2013-09-10 17:39:29 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("cannot create script vm for test %v: %v",
|
|
|
|
SigScriptTests[i].name, err)
|
|
|
|
continue nexttest
|
|
|
|
}
|
|
|
|
err = engine.Execute()
|
|
|
|
if (err == nil) != SigScriptTests[i].inputs[j].inputValidates {
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("passed test '%v' validation incorrectly: %v",
|
|
|
|
SigScriptTests[i].name, err)
|
|
|
|
} else {
|
|
|
|
t.Errorf("failed test '%v' validation: %v",
|
|
|
|
SigScriptTests[i].name, err)
|
|
|
|
}
|
|
|
|
continue nexttest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-06 01:10:16 +01:00
|
|
|
|
|
|
|
func TestStringifyClass(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass txscript.ScriptClass
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nonstandardty",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass: txscript.NonStandardTy,
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed: "nonstandard",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "pubkey",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass: txscript.PubKeyTy,
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed: "pubkey",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "pubkeyhash",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass: txscript.PubKeyHashTy,
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed: "pubkeyhash",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "scripthash",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass: txscript.ScriptHashTy,
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed: "scripthash",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multisigty",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass: txscript.MultiSigTy,
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed: "multisig",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "nulldataty",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass: txscript.NullDataTy,
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed: "nulldata",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "broken",
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptclass: txscript.ScriptClass(255),
|
2015-01-29 21:39:44 +01:00
|
|
|
stringed: "Invalid",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2013-11-06 01:10:16 +01:00
|
|
|
typeString := test.scriptclass.String()
|
|
|
|
if typeString != test.stringed {
|
|
|
|
t.Errorf("%s: got \"%s\" expected \"%s\"", test.name,
|
|
|
|
typeString, test.stringed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-03 20:42:22 +01:00
|
|
|
|
|
|
|
// bogusAddress implements the btcutil.Address interface so the tests can ensure
|
|
|
|
// unsupported address types are handled properly.
|
|
|
|
type bogusAddress struct{}
|
|
|
|
|
|
|
|
// EncodeAddress simply returns an empty string. It exists to satsify the
|
|
|
|
// btcutil.Address interface.
|
|
|
|
func (b *bogusAddress) EncodeAddress() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScriptAddress simply returns an empty byte slice. It exists to satsify the
|
|
|
|
// btcutil.Address interface.
|
|
|
|
func (b *bogusAddress) ScriptAddress() []byte {
|
|
|
|
return []byte{}
|
|
|
|
}
|
|
|
|
|
2014-03-13 18:20:45 +01:00
|
|
|
// IsForNet lies blatantly to satisfy the btcutil.Address interface.
|
2015-02-06 06:18:27 +01:00
|
|
|
func (b *bogusAddress) IsForNet(chainParams *chaincfg.Params) bool {
|
2014-03-13 18:20:45 +01:00
|
|
|
return true // why not?
|
|
|
|
}
|
|
|
|
|
2014-07-03 02:36:06 +02:00
|
|
|
// String simply returns an empty string. It exists to satsify the
|
|
|
|
// btcutil.Address interface.
|
|
|
|
func (b *bogusAddress) String() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2014-01-03 20:42:22 +01:00
|
|
|
func TestPayToAddrScript(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-01-03 20:42:22 +01:00
|
|
|
// 1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX
|
|
|
|
p2pkhMain, err := btcutil.NewAddressPubKeyHash([]byte{
|
|
|
|
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
|
|
|
|
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84,
|
2015-02-06 06:18:27 +01:00
|
|
|
}, &chaincfg.MainNetParams)
|
2014-01-03 20:42:22 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create public key hash address: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Taken from transaction:
|
|
|
|
// b0539a45de13b3e0403909b8bd1a555b8cbe45fd4e3f3fda76f3a5f52835c29d
|
|
|
|
p2shMain, _ := btcutil.NewAddressScriptHashFromHash([]byte{
|
|
|
|
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
|
|
|
|
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4,
|
2015-02-06 06:18:27 +01:00
|
|
|
}, &chaincfg.MainNetParams)
|
2014-01-03 20:42:22 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create script hash address: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-02-20 19:37:42 +01:00
|
|
|
// mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg
|
|
|
|
p2pkCompressedMain, err := btcutil.NewAddressPubKey([]byte{
|
2014-02-21 09:09:55 +01:00
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
2015-02-06 06:18:27 +01:00
|
|
|
0x52, 0xc6, 0xb4}, &chaincfg.MainNetParams)
|
2014-02-20 19:37:42 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create pubkey address (compressed): %v",
|
|
|
|
err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
p2pkCompressed2Main, err := btcutil.NewAddressPubKey([]byte{
|
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
2015-02-06 06:18:27 +01:00
|
|
|
0xb1, 0x6e, 0x65}, &chaincfg.MainNetParams)
|
2014-02-20 19:37:42 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create pubkey address (compressed 2): %v",
|
|
|
|
err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p2pkUncompressedMain, err := btcutil.NewAddressPubKey([]byte{
|
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
2015-02-06 06:18:27 +01:00
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3}, &chaincfg.MainNetParams)
|
2014-02-20 19:37:42 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create pubkey address (uncompressed): %v",
|
|
|
|
err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-01-03 20:42:22 +01:00
|
|
|
tests := []struct {
|
|
|
|
in btcutil.Address
|
|
|
|
expected []byte
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
// pay-to-pubkey-hash address on mainnet
|
|
|
|
{
|
|
|
|
p2pkhMain,
|
|
|
|
[]byte{
|
|
|
|
0x76, 0xa9, 0x14, 0xe3, 0x4c, 0xce, 0x70, 0xc8,
|
|
|
|
0x63, 0x73, 0x27, 0x3e, 0xfc, 0xc5, 0x4c, 0xe7,
|
|
|
|
0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84, 0x88,
|
|
|
|
0xac,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
// pay-to-script-hash address on mainnet
|
|
|
|
{
|
|
|
|
p2shMain,
|
|
|
|
[]byte{
|
|
|
|
0xa9, 0x14, 0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86,
|
|
|
|
0xef, 0xa8, 0x4c, 0x37, 0xc0, 0x51, 0x99, 0x29,
|
|
|
|
0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4, 0x87,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
2014-02-20 19:37:42 +01:00
|
|
|
// pay-to-pubkey address on mainnet. compressed key.
|
|
|
|
{
|
|
|
|
p2pkCompressedMain,
|
|
|
|
[]byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2014-02-20 19:37:42 +01:00
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34,
|
|
|
|
0x4c, 0x95, 0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57,
|
|
|
|
0x3d, 0x8d, 0x79, 0x03, 0xc3, 0xeb, 0xec, 0x3a,
|
|
|
|
0x95, 0x77, 0x24, 0x89, 0x5d, 0xca, 0x52, 0xc6,
|
2015-01-30 07:03:01 +01:00
|
|
|
0xb4, txscript.OP_CHECKSIG,
|
2014-02-20 19:37:42 +01:00
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
// pay-to-pubkey address on mainnet. compressed key (other way).
|
|
|
|
{
|
|
|
|
p2pkCompressed2Main,
|
|
|
|
[]byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2014-02-20 19:37:42 +01:00
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb,
|
|
|
|
0x1b, 0xa1, 0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c,
|
|
|
|
0x61, 0xcf, 0x43, 0xe0, 0x01, 0xf9, 0x13, 0x7f,
|
|
|
|
0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e, 0xb1, 0x6e,
|
2015-01-30 07:03:01 +01:00
|
|
|
0x65, txscript.OP_CHECKSIG,
|
2014-02-20 19:37:42 +01:00
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
// pay-to-pubkey address on mainnet. uncompressed key.
|
|
|
|
{
|
|
|
|
p2pkUncompressedMain,
|
|
|
|
[]byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_65,
|
2014-02-20 19:37:42 +01:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a,
|
|
|
|
0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc,
|
|
|
|
0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48,
|
|
|
|
0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a,
|
|
|
|
0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b,
|
|
|
|
0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f,
|
|
|
|
0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12,
|
2015-01-30 07:03:01 +01:00
|
|
|
0xa3, txscript.OP_CHECKSIG,
|
2014-02-20 19:37:42 +01:00
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
2014-01-03 20:42:22 +01:00
|
|
|
|
|
|
|
// Supported address types with nil pointers.
|
2015-01-30 07:03:01 +01:00
|
|
|
{(*btcutil.AddressPubKeyHash)(nil), []byte{}, txscript.ErrUnsupportedAddress},
|
|
|
|
{(*btcutil.AddressScriptHash)(nil), []byte{}, txscript.ErrUnsupportedAddress},
|
|
|
|
{(*btcutil.AddressPubKey)(nil), []byte{}, txscript.ErrUnsupportedAddress},
|
2014-01-03 20:42:22 +01:00
|
|
|
|
|
|
|
// Unsupported address type.
|
2015-01-30 07:03:01 +01:00
|
|
|
{&bogusAddress{}, []byte{}, txscript.ErrUnsupportedAddress},
|
2014-01-03 20:42:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(test.in)
|
2014-01-03 20:42:22 +01:00
|
|
|
if err != test.err {
|
|
|
|
t.Errorf("PayToAddrScript #%d unexpected error - "+
|
|
|
|
"got %v, want %v", i, err, test.err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(pkScript, test.expected) {
|
|
|
|
t.Errorf("PayToAddrScript #%d got: %x\nwant: %x",
|
|
|
|
i, pkScript, test.expected)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-21 01:20:24 +01:00
|
|
|
|
|
|
|
func TestMultiSigScript(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-02-21 01:20:24 +01:00
|
|
|
// mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg
|
|
|
|
p2pkCompressedMain, err := btcutil.NewAddressPubKey([]byte{
|
2014-02-21 09:09:55 +01:00
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
2015-02-06 06:18:27 +01:00
|
|
|
0x52, 0xc6, 0xb4}, &chaincfg.MainNetParams)
|
2014-02-21 01:20:24 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create pubkey address (compressed): %v",
|
|
|
|
err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
p2pkCompressed2Main, err := btcutil.NewAddressPubKey([]byte{
|
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
2015-02-06 06:18:27 +01:00
|
|
|
0xb1, 0x6e, 0x65}, &chaincfg.MainNetParams)
|
2014-02-21 01:20:24 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create pubkey address (compressed 2): %v",
|
|
|
|
err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p2pkUncompressedMain, err := btcutil.NewAddressPubKey([]byte{
|
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
2015-02-06 06:18:27 +01:00
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3}, &chaincfg.MainNetParams)
|
2014-02-21 01:20:24 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to create pubkey address (uncompressed): %v",
|
|
|
|
err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
2014-02-21 09:09:55 +01:00
|
|
|
keys []*btcutil.AddressPubKey
|
|
|
|
nrequired int
|
|
|
|
expected []byte
|
|
|
|
err error
|
2014-02-21 01:20:24 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
[]*btcutil.AddressPubKey{
|
|
|
|
p2pkCompressedMain,
|
|
|
|
p2pkCompressed2Main,
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
[]byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_1,
|
|
|
|
txscript.OP_DATA_33,
|
2014-02-21 01:20:24 +01:00
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34,
|
|
|
|
0x4c, 0x95, 0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57,
|
|
|
|
0x3d, 0x8d, 0x79, 0x03, 0xc3, 0xeb, 0xec, 0x3a,
|
|
|
|
0x95, 0x77, 0x24, 0x89, 0x5d, 0xca, 0x52, 0xc6,
|
|
|
|
0xb4,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2014-02-21 01:20:24 +01:00
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb,
|
|
|
|
0x1b, 0xa1, 0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c,
|
|
|
|
0x61, 0xcf, 0x43, 0xe0, 0x01, 0xf9, 0x13, 0x7f,
|
|
|
|
0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e, 0xb1, 0x6e,
|
|
|
|
0x65,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_2, txscript.OP_CHECKMULTISIG,
|
2014-02-21 01:20:24 +01:00
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]*btcutil.AddressPubKey{
|
|
|
|
p2pkCompressedMain,
|
|
|
|
p2pkCompressed2Main,
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
[]byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_2,
|
|
|
|
txscript.OP_DATA_33,
|
2014-02-21 01:20:24 +01:00
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34,
|
|
|
|
0x4c, 0x95, 0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57,
|
|
|
|
0x3d, 0x8d, 0x79, 0x03, 0xc3, 0xeb, 0xec, 0x3a,
|
|
|
|
0x95, 0x77, 0x24, 0x89, 0x5d, 0xca, 0x52, 0xc6,
|
|
|
|
0xb4,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_DATA_33,
|
2014-02-21 01:20:24 +01:00
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb,
|
|
|
|
0x1b, 0xa1, 0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c,
|
|
|
|
0x61, 0xcf, 0x43, 0xe0, 0x01, 0xf9, 0x13, 0x7f,
|
|
|
|
0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e, 0xb1, 0x6e,
|
|
|
|
0x65,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_2, txscript.OP_CHECKMULTISIG,
|
2014-02-21 01:20:24 +01:00
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]*btcutil.AddressPubKey{
|
|
|
|
p2pkCompressedMain,
|
|
|
|
p2pkCompressed2Main,
|
|
|
|
},
|
|
|
|
3,
|
|
|
|
[]byte{},
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.ErrBadNumRequired,
|
2014-02-21 01:20:24 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
[]*btcutil.AddressPubKey{
|
|
|
|
p2pkUncompressedMain,
|
|
|
|
},
|
|
|
|
1,
|
|
|
|
[]byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_1, txscript.OP_DATA_65,
|
2014-02-21 01:20:24 +01:00
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a,
|
|
|
|
0x01, 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc,
|
|
|
|
0x1e, 0xb6, 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48,
|
|
|
|
0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6, 0x90, 0x9a,
|
|
|
|
0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b,
|
|
|
|
0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f,
|
|
|
|
0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, 0x12,
|
|
|
|
0xa3,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_1, txscript.OP_CHECKMULTISIG,
|
2014-02-21 01:20:24 +01:00
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]*btcutil.AddressPubKey{
|
|
|
|
p2pkUncompressedMain,
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
[]byte{},
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.ErrBadNumRequired,
|
2014-02-21 01:20:24 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
2015-01-30 07:03:01 +01:00
|
|
|
script, err := txscript.MultiSigScript(test.keys,
|
2014-02-21 01:20:24 +01:00
|
|
|
test.nrequired)
|
|
|
|
if err != test.err {
|
|
|
|
t.Errorf("MultiSigScript #%d unexpected error - "+
|
|
|
|
"got %v, want %v", i, err, test.err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(script, test.expected) {
|
|
|
|
t.Errorf("MultiSigScript #%d got: %x\nwant: %x",
|
|
|
|
i, script, test.expected)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-18 00:15:30 +02:00
|
|
|
|
2015-02-05 22:16:39 +01:00
|
|
|
func signAndCheck(msg string, tx *wire.MsgTx, idx int, pkScript []byte,
|
2015-01-30 07:03:01 +01:00
|
|
|
hashType txscript.SigHashType, kdb txscript.KeyDB, sdb txscript.ScriptDB,
|
2014-04-18 00:15:30 +02:00
|
|
|
previousScript []byte) error {
|
|
|
|
|
2015-04-20 07:32:43 +02:00
|
|
|
sigScript, err := txscript.SignTxOutput(&chaincfg.TestNet3Params, tx,
|
|
|
|
idx, pkScript, hashType, kdb, sdb, []byte{})
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to sign output %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkScripts(msg, tx, idx, sigScript, pkScript)
|
|
|
|
}
|
|
|
|
|
2015-04-20 07:32:43 +02:00
|
|
|
func checkScripts(msg string, tx *wire.MsgTx, idx int, sigScript, pkScript []byte) error {
|
|
|
|
tx.TxIn[idx].SignatureScript = sigScript
|
|
|
|
engine, err := txscript.NewScript(pkScript, tx, idx,
|
|
|
|
txscript.ScriptBip16|txscript.ScriptVerifyDERSignatures)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to make script engine for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = engine.Execute()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid script signature for %s: %v", msg,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type addressToKey struct {
|
2014-09-29 23:31:26 +02:00
|
|
|
key *btcec.PrivateKey
|
2014-04-18 00:15:30 +02:00
|
|
|
compressed bool
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
func mkGetKey(keys map[string]addressToKey) txscript.KeyDB {
|
2014-04-18 00:15:30 +02:00
|
|
|
if keys == nil {
|
2015-01-30 07:03:01 +01:00
|
|
|
return txscript.KeyClosure(func(addr btcutil.Address) (*btcec.PrivateKey,
|
2014-04-18 00:15:30 +02:00
|
|
|
bool, error) {
|
|
|
|
return nil, false, errors.New("nope")
|
|
|
|
})
|
|
|
|
}
|
2015-01-30 07:03:01 +01:00
|
|
|
return txscript.KeyClosure(func(addr btcutil.Address) (*btcec.PrivateKey,
|
2014-04-18 00:15:30 +02:00
|
|
|
bool, error) {
|
|
|
|
a2k, ok := keys[addr.EncodeAddress()]
|
|
|
|
if !ok {
|
|
|
|
return nil, false, errors.New("nope")
|
|
|
|
}
|
|
|
|
return a2k.key, a2k.compressed, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
func mkGetScript(scripts map[string][]byte) txscript.ScriptDB {
|
2014-04-18 00:15:30 +02:00
|
|
|
if scripts == nil {
|
2015-01-30 07:03:01 +01:00
|
|
|
return txscript.ScriptClosure(func(addr btcutil.Address) (
|
2014-04-18 00:15:30 +02:00
|
|
|
[]byte, error) {
|
|
|
|
return nil, errors.New("nope")
|
|
|
|
})
|
|
|
|
}
|
2015-01-30 07:03:01 +01:00
|
|
|
return txscript.ScriptClosure(func(addr btcutil.Address) ([]byte,
|
2014-04-18 00:15:30 +02:00
|
|
|
error) {
|
|
|
|
script, ok := scripts[addr.EncodeAddress()]
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("nope")
|
|
|
|
}
|
|
|
|
return script, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSignTxOutput(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-04-18 00:15:30 +02:00
|
|
|
// make key
|
|
|
|
// make script based on key.
|
|
|
|
// sign with magic pixie dust.
|
2015-01-30 07:03:01 +01:00
|
|
|
hashTypes := []txscript.SigHashType{
|
|
|
|
txscript.SigHashOld, // no longer used but should act like all
|
|
|
|
txscript.SigHashAll,
|
|
|
|
txscript.SigHashNone,
|
|
|
|
txscript.SigHashSingle,
|
|
|
|
txscript.SigHashAll | txscript.SigHashAnyOneCanPay,
|
|
|
|
txscript.SigHashNone | txscript.SigHashAnyOneCanPay,
|
|
|
|
txscript.SigHashSingle | txscript.SigHashAnyOneCanPay,
|
2014-04-18 00:15:30 +02:00
|
|
|
}
|
2015-02-05 22:16:39 +01:00
|
|
|
tx := &wire.MsgTx{
|
2014-04-18 00:15:30 +02:00
|
|
|
Version: 1,
|
2015-02-05 22:16:39 +01:00
|
|
|
TxIn: []*wire.TxIn{
|
|
|
|
&wire.TxIn{
|
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash{},
|
2014-04-18 00:15:30 +02:00
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
&wire.TxIn{
|
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash{},
|
2014-04-18 00:15:30 +02:00
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
&wire.TxIn{
|
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash{},
|
2014-04-18 00:15:30 +02:00
|
|
|
Index: 2,
|
|
|
|
},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
TxOut: []*wire.TxOut{
|
|
|
|
&wire.TxOut{
|
2014-04-18 00:15:30 +02:00
|
|
|
Value: 1,
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
&wire.TxOut{
|
2014-04-18 00:15:30 +02:00
|
|
|
Value: 2,
|
|
|
|
},
|
2015-02-05 22:16:39 +01:00
|
|
|
&wire.TxOut{
|
2014-04-18 00:15:30 +02:00
|
|
|
Value: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to Pubkey Hash (uncompressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, pkScript, hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(nil), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to Pubkey Hash (uncompressed) (merging with correct)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(nil), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(nil), sigScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, pkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to Pubkey Hash (compressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, pkScript, hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(nil), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to Pubkey Hash (compressed) with duplicate merge
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(nil), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(nil), sigScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, pkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (uncompressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, pkScript, hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(nil), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (uncompressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(nil), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(nil), sigScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, pkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (compressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, pkScript, hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(nil), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (compressed) with duplicate merge
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(nil), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, pkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(nil), sigScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, pkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// As before, but with p2sh now.
|
|
|
|
// Pay to Pubkey Hash (uncompressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, scriptPkScript,
|
|
|
|
hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to Pubkey Hash (uncompressed) with duplicate merge
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, scriptPkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to Pubkey Hash (compressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, scriptPkScript,
|
|
|
|
hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to Pubkey Hash (compressed) with duplicate merge
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKeyHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
btcutil.Hash160(pk), &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, scriptPkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (uncompressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, scriptPkScript,
|
|
|
|
hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (uncompressed) with duplicate merge
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeUncompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, false},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, scriptPkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (compressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, scriptPkScript,
|
|
|
|
hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pay to PubKey (compressed)
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk := (*btcec.PublicKey)(&key.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address, err := btcutil.NewAddressPubKey(pk,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.PayToAddrScript(address)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// by the above loop, this should be valid, now sign
|
|
|
|
// again and merge.
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address.EncodeAddress(): {key, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s a "+
|
|
|
|
"second time: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript, scriptPkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("twice signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Basic Multisig
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key1, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk1 := (*btcec.PublicKey)(&key1.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address1, err := btcutil.NewAddressPubKey(pk1,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key2, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey 2 for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk2 := (*btcec.PublicKey)(&key2.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address2, err := btcutil.NewAddressPubKey(pk2,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address 2 for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.MultiSigScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
[]*btcutil.AddressPubKey{address1, address2},
|
|
|
|
2)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := signAndCheck(msg, tx, i, scriptPkScript,
|
|
|
|
hashType,
|
|
|
|
mkGetKey(map[string]addressToKey{
|
|
|
|
address1.EncodeAddress(): {key1, true},
|
|
|
|
address2.EncodeAddress(): {key2, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two part multisig, sign with one key then the other.
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key1, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk1 := (*btcec.PublicKey)(&key1.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address1, err := btcutil.NewAddressPubKey(pk1,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key2, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey 2 for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk2 := (*btcec.PublicKey)(&key2.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address2, err := btcutil.NewAddressPubKey(pk2,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address 2 for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.MultiSigScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
[]*btcutil.AddressPubKey{address1, address2},
|
|
|
|
2)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address1.EncodeAddress(): {key1, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only 1 out of 2 signed, this *should* fail.
|
|
|
|
if checkScripts(msg, tx, i, sigScript,
|
|
|
|
scriptPkScript) == nil {
|
|
|
|
t.Errorf("part signed script valid for %s", msg)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sign with the other key and merge
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address2.EncodeAddress(): {key2, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), sigScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
err = checkScripts(msg, tx, i, sigScript,
|
|
|
|
scriptPkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("fully signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two part multisig, sign with one key then both, check key dedup
|
|
|
|
// correctly.
|
|
|
|
for _, hashType := range hashTypes {
|
|
|
|
for i := range tx.TxIn {
|
|
|
|
msg := fmt.Sprintf("%d:%d", hashType, i)
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key1, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk1 := (*btcec.PublicKey)(&key1.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address1, err := btcutil.NewAddressPubKey(pk1,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2014-09-29 23:31:26 +02:00
|
|
|
key2, err := btcec.NewPrivateKey(btcec.S256())
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
2014-08-25 22:14:19 +02:00
|
|
|
t.Errorf("failed to make privKey 2 for %s: %v",
|
2014-04-18 00:15:30 +02:00
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
pk2 := (*btcec.PublicKey)(&key2.PublicKey).
|
|
|
|
SerializeCompressed()
|
|
|
|
address2, err := btcutil.NewAddressPubKey(pk2,
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make address 2 for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
pkScript, err := txscript.MultiSigScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
[]*btcutil.AddressPubKey{address1, address2},
|
|
|
|
2)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make pkscript "+
|
|
|
|
"for %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptAddr, err := btcutil.NewAddressScriptHash(
|
2015-02-06 06:18:27 +01:00
|
|
|
pkScript, &chaincfg.TestNet3Params)
|
2014-04-18 00:15:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make p2sh addr for %s: %v",
|
|
|
|
msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
scriptPkScript, err := txscript.PayToAddrScript(
|
2014-04-18 00:15:30 +02:00
|
|
|
scriptAddr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to make script pkscript for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err := txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address1.EncodeAddress(): {key1, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), []byte{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg,
|
|
|
|
err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only 1 out of 2 signed, this *should* fail.
|
|
|
|
if checkScripts(msg, tx, i, sigScript,
|
|
|
|
scriptPkScript) == nil {
|
|
|
|
t.Errorf("part signed script valid for %s", msg)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sign with the other key and merge
|
2015-01-30 07:03:01 +01:00
|
|
|
sigScript, err = txscript.SignTxOutput(
|
2015-02-06 06:18:27 +01:00
|
|
|
&chaincfg.TestNet3Params, tx, i, scriptPkScript,
|
2014-04-18 00:15:30 +02:00
|
|
|
hashType, mkGetKey(map[string]addressToKey{
|
|
|
|
address1.EncodeAddress(): {key1, true},
|
|
|
|
address2.EncodeAddress(): {key2, true},
|
|
|
|
}), mkGetScript(map[string][]byte{
|
|
|
|
scriptAddr.EncodeAddress(): pkScript,
|
|
|
|
}), sigScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to sign output %s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we should pass.
|
|
|
|
err = checkScripts(msg, tx, i, sigScript,
|
|
|
|
scriptPkScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("fully signed script invalid for "+
|
|
|
|
"%s: %v", msg, err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-08 13:46:15 +02:00
|
|
|
|
|
|
|
func TestCalcMultiSigStats(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-08-08 13:46:15 +02:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
script []byte
|
|
|
|
expected error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "short script",
|
|
|
|
script: []byte{
|
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
expected: txscript.ErrStackShortScript,
|
2014-08-08 13:46:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "stack underflow",
|
|
|
|
script: []byte{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_RETURN,
|
|
|
|
txscript.OP_PUSHDATA1,
|
2014-08-08 13:46:15 +02:00
|
|
|
0x29,
|
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
0xeb, 0x64, 0x9f, 0x6b, 0xc3, 0xf4, 0xce, 0xf3,
|
|
|
|
0x08,
|
|
|
|
},
|
2015-01-30 07:03:01 +01:00
|
|
|
expected: txscript.ErrStackUnderflow,
|
2014-08-08 13:46:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multisig script",
|
|
|
|
script: []uint8{
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_FALSE,
|
|
|
|
txscript.OP_DATA_72,
|
2014-08-08 13:46:15 +02:00
|
|
|
0x30, 0x45, 0x02, 0x20, 0x10,
|
|
|
|
0x6a, 0x3e, 0x4e, 0xf0, 0xb5,
|
|
|
|
0x1b, 0x76, 0x4a, 0x28, 0x87,
|
|
|
|
0x22, 0x62, 0xff, 0xef, 0x55,
|
|
|
|
0x84, 0x65, 0x14, 0xda, 0xcb,
|
|
|
|
0xdc, 0xbb, 0xdd, 0x65, 0x2c,
|
|
|
|
0x84, 0x9d, 0x39, 0x5b, 0x43,
|
|
|
|
0x84, 0x02, 0x21, 0x00, 0xe0,
|
|
|
|
0x3a, 0xe5, 0x54, 0xc3, 0xcb,
|
|
|
|
0xb4, 0x06, 0x00, 0xd3, 0x1d,
|
|
|
|
0xd4, 0x6f, 0xc3, 0x3f, 0x25,
|
|
|
|
0xe4, 0x7b, 0xf8, 0x52, 0x5b,
|
|
|
|
0x1f, 0xe0, 0x72, 0x82, 0xe3,
|
|
|
|
0xb6, 0xec, 0xb5, 0xf3, 0xbb,
|
|
|
|
0x28, 0x01,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_CODESEPARATOR,
|
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_DATA_33,
|
2014-08-08 13:46:15 +02:00
|
|
|
0x02, 0x32, 0xab, 0xdc, 0x89,
|
|
|
|
0x3e, 0x7f, 0x06, 0x31, 0x36,
|
|
|
|
0x4d, 0x7f, 0xd0, 0x1c, 0xb3,
|
|
|
|
0x3d, 0x24, 0xda, 0x45, 0x32,
|
|
|
|
0x9a, 0x00, 0x35, 0x7b, 0x3a,
|
|
|
|
0x78, 0x86, 0x21, 0x1a, 0xb4,
|
|
|
|
0x14, 0xd5, 0x5a,
|
2015-01-30 07:03:01 +01:00
|
|
|
txscript.OP_TRUE,
|
|
|
|
txscript.OP_CHECKMULTISIG,
|
2014-08-08 13:46:15 +02:00
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
2015-01-30 07:03:01 +01:00
|
|
|
if _, _, err := txscript.CalcMultiSigStats(test.script); err != test.expected {
|
2014-08-08 13:46:15 +02:00
|
|
|
t.Errorf("CalcMultiSigStats #%d (%s) wrong result\n"+
|
|
|
|
"got: %x\nwant: %x", i, test.name, err,
|
|
|
|
test.expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasCanonicalPushes(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-08-08 13:46:15 +02:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
script []byte
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "does not parse",
|
|
|
|
script: []byte{
|
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "non-canonical push",
|
2015-01-30 07:03:01 +01:00
|
|
|
script: []byte{txscript.OP_PUSHDATA1, 4, 1, 2, 3, 4},
|
2014-08-08 13:46:15 +02:00
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
2015-02-25 02:11:57 +01:00
|
|
|
pops, err := txscript.TstParseScript(test.script)
|
|
|
|
if err != nil {
|
|
|
|
if test.expected {
|
|
|
|
t.Errorf("StandardPushesTests #%d failed to TstParseScript: %v", i, err)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, pop := range pops {
|
|
|
|
if txscript.TstHasCanonicalPushes(pop) != test.expected {
|
|
|
|
t.Errorf("TstHasCanonicalPushes #%d (%s) wrong result\n"+
|
|
|
|
"got: %v\nwant: %v", i, test.name, true,
|
|
|
|
test.expected)
|
|
|
|
break
|
|
|
|
}
|
2014-08-08 13:46:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsPushOnlyScript(t *testing.T) {
|
2015-01-29 21:39:44 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2014-08-08 13:46:15 +02:00
|
|
|
test := struct {
|
|
|
|
name string
|
|
|
|
script []byte
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
name: "does not parse",
|
|
|
|
script: []byte{
|
|
|
|
0x04, 0x67, 0x08, 0xaf, 0xdb, 0x0f, 0xe5, 0x54,
|
|
|
|
0x82, 0x71, 0x96, 0x7f, 0x1a, 0x67, 0x13, 0x0b,
|
|
|
|
0x71, 0x05, 0xcd, 0x6a, 0x82, 0x8e, 0x03, 0x90,
|
|
|
|
0x9a, 0x67, 0x96, 0x2e, 0x0e, 0xa1, 0xf6, 0x1d,
|
|
|
|
},
|
|
|
|
expected: false,
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:03:01 +01:00
|
|
|
if txscript.IsPushOnlyScript(test.script) != test.expected {
|
2014-08-08 13:46:15 +02:00
|
|
|
t.Errorf("IsPushOnlyScript (%s) wrong result\n"+
|
2015-01-29 23:26:20 +01:00
|
|
|
"got: %v\nwant: %v", test.name, true,
|
2014-08-08 13:46:15 +02:00
|
|
|
test.expected)
|
|
|
|
}
|
|
|
|
}
|
2015-02-25 21:04:37 +01:00
|
|
|
|
|
|
|
func TestInvalidFlagCombinations(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
tests := []txscript.ScriptFlags{
|
|
|
|
txscript.ScriptVerifyCleanStack,
|
|
|
|
}
|
|
|
|
|
|
|
|
// tx with almost empty scripts.
|
|
|
|
tx := &wire.MsgTx{
|
|
|
|
Version: 1,
|
|
|
|
TxIn: []*wire.TxIn{
|
|
|
|
{
|
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: wire.ShaHash([32]byte{
|
|
|
|
0xc9, 0x97, 0xa5, 0xe5,
|
|
|
|
0x6e, 0x10, 0x41, 0x02,
|
|
|
|
0xfa, 0x20, 0x9c, 0x6a,
|
|
|
|
0x85, 0x2d, 0xd9, 0x06,
|
|
|
|
0x60, 0xa2, 0x0b, 0x2d,
|
|
|
|
0x9c, 0x35, 0x24, 0x23,
|
|
|
|
0xed, 0xce, 0x25, 0x85,
|
|
|
|
0x7f, 0xcd, 0x37, 0x04,
|
|
|
|
}),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
SignatureScript: []uint8{txscript.OP_NOP},
|
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TxOut: []*wire.TxOut{
|
|
|
|
{
|
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: []byte{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
}
|
|
|
|
pkScript := []byte{txscript.OP_NOP}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
2015-04-20 07:32:43 +02:00
|
|
|
_, err := txscript.NewScript(pkScript, tx, 0, test)
|
2015-02-25 21:04:37 +01:00
|
|
|
if err != txscript.ErrInvalidFlags {
|
|
|
|
t.Fatalf("TestInvalidFlagCombinations #%d unexpected "+
|
|
|
|
"error: %v", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|