2017-01-07 18:31:03 +01:00
|
|
|
// Copyright (c) 2013-2017 The btcsuite developers
|
2015-04-20 22:28:00 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-10-20 08:18:31 +02:00
|
|
|
package txscript
|
2015-04-20 22:28:00 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-08-08 21:04:33 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2015-04-20 22:28:00 +02:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestBadPC sets the pc to a deliberately bad result then confirms that Step()
|
|
|
|
// and Disasm fail correctly.
|
|
|
|
func TestBadPC(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2016-10-20 08:18:31 +02:00
|
|
|
tests := []struct {
|
2015-04-20 22:28:00 +02:00
|
|
|
script, off int
|
2016-10-20 08:18:31 +02:00
|
|
|
}{
|
|
|
|
{script: 2, off: 0},
|
|
|
|
{script: 0, off: 2},
|
2015-04-20 22:28:00 +02:00
|
|
|
}
|
2016-10-20 08:18:31 +02:00
|
|
|
|
2015-04-20 22:28:00 +02:00
|
|
|
// tx with almost empty scripts.
|
|
|
|
tx := &wire.MsgTx{
|
|
|
|
Version: 1,
|
|
|
|
TxIn: []*wire.TxIn{
|
|
|
|
{
|
|
|
|
PreviousOutPoint: wire.OutPoint{
|
2016-08-08 21:04:33 +02:00
|
|
|
Hash: chainhash.Hash([32]byte{
|
2015-04-20 22:28:00 +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,
|
|
|
|
},
|
2016-10-20 08:18:31 +02:00
|
|
|
SignatureScript: mustParseShortForm("NOP"),
|
2015-04-20 22:28:00 +02:00
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
2016-10-20 08:18:31 +02:00
|
|
|
TxOut: []*wire.TxOut{{
|
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: nil,
|
|
|
|
}},
|
2015-04-20 22:28:00 +02:00
|
|
|
LockTime: 0,
|
|
|
|
}
|
2016-10-20 08:18:31 +02:00
|
|
|
pkScript := mustParseShortForm("NOP")
|
2015-04-20 22:28:00 +02:00
|
|
|
|
2016-10-20 08:18:31 +02:00
|
|
|
for _, test := range tests {
|
|
|
|
vm, err := NewEngine(pkScript, tx, 0, 0, nil)
|
2015-04-20 22:28:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to create script: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set to after all scripts
|
2016-10-20 08:18:31 +02:00
|
|
|
vm.scriptIdx = test.script
|
|
|
|
vm.scriptOff = test.off
|
2015-04-20 22:28:00 +02:00
|
|
|
|
|
|
|
_, err = vm.Step()
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Step with invalid pc (%v) succeeds!", test)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = vm.DisasmPC()
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("DisasmPC with invalid pc (%v) succeeds!",
|
|
|
|
test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestCheckErrorCondition tests the execute early test in CheckErrorCondition()
|
|
|
|
// since most code paths are tested elsewhere.
|
|
|
|
func TestCheckErrorCondition(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
// tx with almost empty scripts.
|
|
|
|
tx := &wire.MsgTx{
|
|
|
|
Version: 1,
|
2016-10-20 08:18:31 +02:00
|
|
|
TxIn: []*wire.TxIn{{
|
|
|
|
PreviousOutPoint: wire.OutPoint{
|
|
|
|
Hash: chainhash.Hash([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,
|
2015-04-20 22:28:00 +02:00
|
|
|
},
|
2016-10-20 08:18:31 +02:00
|
|
|
SignatureScript: nil,
|
|
|
|
Sequence: 4294967295,
|
|
|
|
}},
|
|
|
|
TxOut: []*wire.TxOut{{
|
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: nil,
|
|
|
|
}},
|
2015-04-20 22:28:00 +02:00
|
|
|
LockTime: 0,
|
|
|
|
}
|
2016-10-20 08:18:31 +02:00
|
|
|
pkScript := mustParseShortForm("NOP NOP NOP NOP NOP NOP NOP NOP NOP" +
|
|
|
|
" NOP TRUE")
|
2015-04-20 22:28:00 +02:00
|
|
|
|
2016-10-20 08:18:31 +02:00
|
|
|
vm, err := NewEngine(pkScript, tx, 0, 0, nil)
|
2015-04-20 22:28:00 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to create script: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(pkScript)-1; i++ {
|
|
|
|
done, err := vm.Step()
|
|
|
|
if err != nil {
|
2017-01-07 18:31:03 +01:00
|
|
|
t.Fatalf("failed to step %dth time: %v", i, err)
|
2015-04-20 22:28:00 +02:00
|
|
|
}
|
|
|
|
if done {
|
2017-01-07 18:31:03 +01:00
|
|
|
t.Fatalf("finshed early on %dth time", i)
|
2015-04-20 22:28:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err = vm.CheckErrorCondition(false)
|
2017-01-07 18:31:03 +01:00
|
|
|
if !IsErrorCode(err, ErrScriptUnfinished) {
|
|
|
|
t.Fatalf("got unexepected error %v on %dth iteration",
|
2015-04-20 22:28:00 +02:00
|
|
|
err, i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done, err := vm.Step()
|
|
|
|
if err != nil {
|
2017-01-07 18:31:03 +01:00
|
|
|
t.Fatalf("final step failed %v", err)
|
2015-04-20 22:28:00 +02:00
|
|
|
}
|
|
|
|
if !done {
|
2017-01-07 18:31:03 +01:00
|
|
|
t.Fatalf("final step isn't done!")
|
2015-04-20 22:28:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err = vm.CheckErrorCondition(false)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error %v on final check", err)
|
|
|
|
}
|
|
|
|
}
|
2015-05-02 21:56:55 +02:00
|
|
|
|
|
|
|
// TestInvalidFlagCombinations ensures the script engine returns the expected
|
|
|
|
// error when disallowed flag combinations are specified.
|
|
|
|
func TestInvalidFlagCombinations(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2016-10-20 08:18:31 +02:00
|
|
|
tests := []ScriptFlags{
|
|
|
|
ScriptVerifyCleanStack,
|
2015-05-02 21:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// tx with almost empty scripts.
|
|
|
|
tx := &wire.MsgTx{
|
|
|
|
Version: 1,
|
|
|
|
TxIn: []*wire.TxIn{
|
|
|
|
{
|
|
|
|
PreviousOutPoint: wire.OutPoint{
|
2016-08-08 21:04:33 +02:00
|
|
|
Hash: chainhash.Hash([32]byte{
|
2015-05-02 21:56:55 +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,
|
|
|
|
},
|
2016-10-20 08:18:31 +02:00
|
|
|
SignatureScript: []uint8{OP_NOP},
|
2015-05-02 21:56:55 +02:00
|
|
|
Sequence: 4294967295,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TxOut: []*wire.TxOut{
|
|
|
|
{
|
|
|
|
Value: 1000000000,
|
|
|
|
PkScript: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
LockTime: 0,
|
|
|
|
}
|
2016-10-20 08:18:31 +02:00
|
|
|
pkScript := []byte{OP_NOP}
|
2015-05-02 21:56:55 +02:00
|
|
|
|
|
|
|
for i, test := range tests {
|
2016-10-20 08:18:31 +02:00
|
|
|
_, err := NewEngine(pkScript, tx, 0, test, nil)
|
2017-01-07 18:31:03 +01:00
|
|
|
if !IsErrorCode(err, ErrInvalidFlags) {
|
2015-05-02 21:56:55 +02:00
|
|
|
t.Fatalf("TestInvalidFlagCombinations #%d unexpected "+
|
|
|
|
"error: %v", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestCheckPubKeyEncoding ensures the internal checkPubKeyEncoding function
|
|
|
|
// works as expected.
|
|
|
|
func TestCheckPubKeyEncoding(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
key []byte
|
|
|
|
isValid bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "uncompressed ok",
|
2016-10-20 08:18:31 +02:00
|
|
|
key: hexToBytes("0411db93e1dcdb8a016b49840f8c53bc1eb68" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf" +
|
|
|
|
"9744464f82e160bfa9b8b64f9d4c03f999b8643f656b" +
|
|
|
|
"412a3"),
|
|
|
|
isValid: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compressed ok",
|
2016-10-20 08:18:31 +02:00
|
|
|
key: hexToBytes("02ce0b14fb842b1ba549fdd675c98075f12e9" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"c510f8ef52bd021a9a1f4809d3b4d"),
|
|
|
|
isValid: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compressed ok",
|
2016-10-20 08:18:31 +02:00
|
|
|
key: hexToBytes("032689c7c2dab13309fb143e0e8fe39634252" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"1887e976690b6b47f5b2a4b7d448e"),
|
|
|
|
isValid: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "hybrid",
|
2016-10-20 08:18:31 +02:00
|
|
|
key: hexToBytes("0679be667ef9dcbbac55a06295ce870b07029" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"bfcdb2dce28d959f2815b16f81798483ada7726a3c46" +
|
|
|
|
"55da4fbfc0e1108a8fd17b448a68554199c47d08ffb1" +
|
|
|
|
"0d4b8"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
key: nil,
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-10-20 08:18:31 +02:00
|
|
|
vm := Engine{flags: ScriptVerifyStrictEncoding}
|
2015-05-02 21:56:55 +02:00
|
|
|
for _, test := range tests {
|
2016-10-20 08:18:31 +02:00
|
|
|
err := vm.checkPubKeyEncoding(test.key)
|
2015-05-02 21:56:55 +02:00
|
|
|
if err != nil && test.isValid {
|
|
|
|
t.Errorf("checkSignatureEncoding test '%s' failed "+
|
|
|
|
"when it should have succeeded: %v", test.name,
|
|
|
|
err)
|
|
|
|
} else if err == nil && !test.isValid {
|
|
|
|
t.Errorf("checkSignatureEncooding test '%s' succeeded "+
|
|
|
|
"when it should have failed", test.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestCheckSignatureEncoding ensures the internal checkSignatureEncoding
|
|
|
|
// function works as expected.
|
|
|
|
func TestCheckSignatureEncoding(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
sig []byte
|
|
|
|
isValid bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "valid signature",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty.",
|
|
|
|
sig: nil,
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bad magic",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("314402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bad 1st int marker magic",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304403204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bad 2nd int marker",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41032018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "short len",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304302204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "long len",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304502204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "long X",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402424e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "long Y",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022118152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "short Y",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41021918152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "trailing crap",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d0901"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "X == N ",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("30440220fffffffffffffffffffffffffffff" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"ffebaaedce6af48a03bbfd25e8cd0364141022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "X == N ",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("30440220fffffffffffffffffffffffffffff" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"ffebaaedce6af48a03bbfd25e8cd0364142022018152" +
|
|
|
|
"2ec8eca07de4860a4acdd12909d831cc56cbbac46220" +
|
|
|
|
"82221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Y == N",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd410220fffff" +
|
|
|
|
"ffffffffffffffffffffffffffebaaedce6af48a03bb" +
|
|
|
|
"fd25e8cd0364141"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Y > N",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd410220fffff" +
|
|
|
|
"ffffffffffffffffffffffffffebaaedce6af48a03bb" +
|
|
|
|
"fd25e8cd0364142"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "0 len X",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("302402000220181522ec8eca07de4860a4acd" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"d12909d831cc56cbbac4622082221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "0 len Y",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("302402204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd410200"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "extra R padding",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("30450221004e45e16932b8af514961a1d3a1a" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181" +
|
|
|
|
"522ec8eca07de4860a4acdd12909d831cc56cbbac462" +
|
|
|
|
"2082221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "extra S padding",
|
2016-10-20 08:18:31 +02:00
|
|
|
sig: hexToBytes("304502204e45e16932b8af514961a1d3a1a25" +
|
2015-05-02 21:56:55 +02:00
|
|
|
"fdf3f4f7732e9d624c6c61548ab5fb8cd41022100181" +
|
|
|
|
"522ec8eca07de4860a4acdd12909d831cc56cbbac462" +
|
|
|
|
"2082221a8768d1d09"),
|
|
|
|
isValid: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-10-20 08:18:31 +02:00
|
|
|
vm := Engine{flags: ScriptVerifyStrictEncoding}
|
2015-05-02 21:56:55 +02:00
|
|
|
for _, test := range tests {
|
2016-10-20 08:18:31 +02:00
|
|
|
err := vm.checkSignatureEncoding(test.sig)
|
2015-05-02 21:56:55 +02:00
|
|
|
if err != nil && test.isValid {
|
|
|
|
t.Errorf("checkSignatureEncoding test '%s' failed "+
|
|
|
|
"when it should have succeeded: %v", test.name,
|
|
|
|
err)
|
|
|
|
} else if err == nil && !test.isValid {
|
|
|
|
t.Errorf("checkSignatureEncooding test '%s' succeeded "+
|
|
|
|
"when it should have failed", test.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|