Encountering OP_VERIF and OP_VERNOTIF in execution is always an error.

I honestly thought we already handled this, but some tests dhill is
working on shows that we didn't.
This commit is contained in:
Owain G. Ainsworth 2014-03-14 14:48:19 +00:00
parent 201d6651c9
commit 8df0af32d6
2 changed files with 24 additions and 1 deletions

View file

@ -862,6 +862,22 @@ type parsedOpcode struct {
opfunc func(op parsedOpcode, s Script) error
}
// The following opcodes are always illegal when passed over by the program
// counter even if in a non-executed branch. (it isn't a coincidence that they
// are conditionals).
func (pop *parsedOpcode) alwaysIllegal() bool {
switch pop.opcode.value {
case OP_VERIF:
return true
case OP_VERNOTIF:
return true
default:
return false
}
}
// The following opcode are conditional and thus change the conditional
// execution stack state when passed.
func (pop *parsedOpcode) conditional() bool {
switch pop.opcode.value {
case OP_IF:

View file

@ -52,6 +52,11 @@ var (
// is encountered.
StackErrReservedOpcode = errors.New("Reserved Opcode")
// StackErrAlwaysIllegal is returned when an opcode marked as always
// illegal is encountered. Currently this is just OP_VERIF and
// OP_VERNOTIF.
StackErrAlwaysIllegal = errors.New("Always Illlegal instruction encountered")
// StackErrEarlyReturn is returned when OP_RETURN is executed in the
// script.
StackErrEarlyReturn = errors.New("Script returned early")
@ -602,7 +607,9 @@ func (m *Script) Step() (done bool, err error) {
if m.condStack[0] != OpCondTrue {
// some opcodes still 'activate' if on the non-executing side
// of conditional execution
if opcode.conditional() {
if opcode.alwaysIllegal() {
return true, StackErrAlwaysIllegal
} else if opcode.conditional() {
executeInstr = true
} else {
executeInstr = false