txscript: Cleanup and improve opcode tests.
- Remove all redundant opcode tests in favor of the JSON-based tests in the data directory. - Remove duplicate stack nip test - Add new tests to data/script_invalid.json to exercise additional negative error paths - Remove old unneeded pubkey trace code from opcodeCheckSig - Simplify and improve the disassembly print function - Add new tests to directly test all individual opcode disassembly - Add new tests to directly test opcode disabled function which does not get invoked during ordinary execution - Improve test coverage of opcode.go
This commit is contained in:
parent
2e433b0eb3
commit
8ef68dcc6e
4 changed files with 198 additions and 4482 deletions
|
@ -141,6 +141,8 @@
|
|||
["2 2 0 IF LSHIFT ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "LSHIFT disabled"],
|
||||
["2 2 0 IF RSHIFT ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "RSHIFT disabled"],
|
||||
|
||||
["", "EQUAL NOT", "P2SH,STRICTENC", "EQUAL must error when there are no stack items"],
|
||||
["0", "EQUAL NOT", "P2SH,STRICTENC", "EQUAL must error when there are not 2 stack items"],
|
||||
["0 1","EQUAL", "P2SH,STRICTENC"],
|
||||
["1 1 ADD", "0 EQUAL", "P2SH,STRICTENC"],
|
||||
["11 1 ADD 12 SUB", "11 EQUAL", "P2SH,STRICTENC"],
|
||||
|
@ -368,6 +370,16 @@
|
|||
["NOP", "HASH160 1", "P2SH,STRICTENC"],
|
||||
["NOP", "HASH256 1", "P2SH,STRICTENC"],
|
||||
|
||||
["Increase CHECKSIG and CHECKMULTISIG negative test coverage"],
|
||||
["", "CHECKSIG NOT", "STRICTENC", "CHECKSIG must error when there are no stack items"],
|
||||
["0", "CHECKSIG NOT", "STRICTENC", "CHECKSIG must error when there are not 2 stack items"],
|
||||
["", "CHECKMULTISIG NOT", "STRICTENC", "CHECKMULTISIG must error when there are no stack items"],
|
||||
["", "-1 CHECKMULTISIG NOT", "STRICTENC", "CHECKMULTISIG must error when the specified number of pubkeys is negative"],
|
||||
["", "1 CHECKMULTISIG NOT", "STRICTENC", "CHECKMULTISIG must error when there are not enough pubkeys on the stack"],
|
||||
["", "-1 0 CHECKMULTISIG NOT", "STRICTENC", "CHECKMULTISIG must error when the specified number of signatures is negative"],
|
||||
["", "1 'pk1' 1 CHECKMULTISIG NOT", "STRICTENC", "CHECKMULTISIG must error when there are not enough signatures on the stack"],
|
||||
["", "'dummy' 'sig1' 1 'pk1' 1 CHECKMULTISIG IF 1 ENDIF", "", "CHECKMULTISIG must push false to stack when signature is invalid when NOT in strict enc mode"],
|
||||
|
||||
["",
|
||||
"0 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG 0 0 CHECKMULTISIG",
|
||||
"P2SH,STRICTENC",
|
||||
|
@ -426,7 +438,7 @@
|
|||
["0x4d 0xFF00 0x111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "DROP 1", "MINIMALDATA",
|
||||
"PUSHDATA2 of 255 bytes minimally represented by PUSHDATA1"],
|
||||
|
||||
["0x4f 0x00100000 0x11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "DROP 1", "MINIMALDATA",
|
||||
["0x4e 0x00010000 0x11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "DROP 1", "MINIMALDATA",
|
||||
"PUSHDATA4 of 256 bytes minimally represented by PUSHDATA2"],
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash"
|
||||
"math/big"
|
||||
|
@ -729,27 +728,32 @@ func (pop *parsedOpcode) print(oneline bool) string {
|
|||
if replName, ok := opcodeOnelineRepls[opcodeName]; ok {
|
||||
opcodeName = replName
|
||||
}
|
||||
|
||||
// Nothing more to do for non-data push opcodes.
|
||||
if pop.opcode.length == 1 {
|
||||
return opcodeName
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%x", pop.data)
|
||||
}
|
||||
|
||||
retString := opcodeName
|
||||
// Nothing more to do for non-data push opcodes.
|
||||
if pop.opcode.length == 1 {
|
||||
return retString
|
||||
return opcodeName
|
||||
}
|
||||
if oneline {
|
||||
retString = ""
|
||||
|
||||
// Add length for the OP_PUSHDATA# opcodes.
|
||||
retString := opcodeName
|
||||
switch pop.opcode.length {
|
||||
case -1:
|
||||
retString += fmt.Sprintf(" 0x%02x", len(pop.data))
|
||||
case -2:
|
||||
retString += fmt.Sprintf(" 0x%04x", len(pop.data))
|
||||
case -4:
|
||||
retString += fmt.Sprintf(" 0x%08x", len(pop.data))
|
||||
}
|
||||
if !oneline && pop.opcode.length < 0 {
|
||||
//add length to the end of retString
|
||||
retString += fmt.Sprintf(" 0x%0*x", 2*-pop.opcode.length,
|
||||
len(pop.data))
|
||||
}
|
||||
for _, val := range pop.data {
|
||||
if !oneline {
|
||||
retString += " "
|
||||
}
|
||||
retString += fmt.Sprintf("%02x", val)
|
||||
}
|
||||
return retString
|
||||
|
||||
return fmt.Sprintf("%s 0x%02x", retString, pop.data)
|
||||
}
|
||||
|
||||
func (pop *parsedOpcode) bytes() ([]byte, error) {
|
||||
|
@ -1561,17 +1565,6 @@ func opcodeCheckSig(op *parsedOpcode, vm *Engine) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
log.Tracef("%v", newLogClosure(func() string {
|
||||
return fmt.Sprintf("op_checksig\n"+
|
||||
"pubKey:\n%v"+
|
||||
"pubKey.X: %v\n"+
|
||||
"pubKey.Y: %v\n"+
|
||||
"signature.R: %v\n"+
|
||||
"signature.S: %v\n"+
|
||||
"checkScriptHash:\n%v",
|
||||
hex.Dump(pkStr), pubKey.X, pubKey.Y,
|
||||
signature.R, signature.S, hex.Dump(hash))
|
||||
}))
|
||||
ok := signature.Verify(hash, pubKey)
|
||||
vm.dstack.PushBool(ok)
|
||||
return nil
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -605,16 +605,6 @@ func TestStack(t *testing.T) {
|
|||
ErrStackUnderflow,
|
||||
[][]byte{{2}, {3}},
|
||||
},
|
||||
{
|
||||
"Nip too much",
|
||||
[][]byte{{1}, {2}, {3}},
|
||||
func(s *stack) error {
|
||||
// bite off more than we can chew
|
||||
return s.NipN(3)
|
||||
},
|
||||
ErrStackUnderflow,
|
||||
[][]byte{{2}, {3}},
|
||||
},
|
||||
{
|
||||
"keep on tucking",
|
||||
[][]byte{{1}, {2}, {3}},
|
||||
|
|
Loading…
Reference in a new issue