From e610deb203e737c9ae16a3864ab09c99a8af26c9 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 13 Mar 2019 01:12:54 -0500 Subject: [PATCH] txscript: Make isConditional accept raw opcode. This converts the isConditional function defined on a parsed opcode to a standalone function named isOpcodeConditional which accepts an opcode as a byte instead in order to make it more flexible for raw script analysis. It also updates all callers accordingly. --- txscript/engine.go | 19 ++++++++++++++++++- txscript/opcode.go | 17 ----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/txscript/engine.go b/txscript/engine.go index 1c6a124b..ddb26de5 100644 --- a/txscript/engine.go +++ b/txscript/engine.go @@ -208,6 +208,23 @@ func isOpcodeAlwaysIllegal(opcode byte) bool { } } +// isOpcodeConditional returns whether or not the opcode is a conditional opcode +// which changes the conditional execution stack when executed. +func isOpcodeConditional(opcode byte) bool { + switch opcode { + case OP_IF: + return true + case OP_NOTIF: + return true + case OP_ELSE: + return true + case OP_ENDIF: + return true + default: + return false + } +} + // executeOpcode peforms execution on the passed opcode. It takes into account // whether or not it is hidden by conditionals, but some rules still must be // tested in this case. @@ -243,7 +260,7 @@ func (vm *Engine) executeOpcode(pop *parsedOpcode) error { // Nothing left to do when this is not a conditional opcode and it is // not in an executing branch. - if !vm.isBranchExecuting() && !pop.isConditional() { + if !vm.isBranchExecuting() && !isOpcodeConditional(pop.opcode.value) { return nil } diff --git a/txscript/opcode.go b/txscript/opcode.go index dc4ec50e..7705f59b 100644 --- a/txscript/opcode.go +++ b/txscript/opcode.go @@ -692,23 +692,6 @@ func (pop *parsedOpcode) checkParseableInScript(script []byte, scriptPos int) (i return scriptPos, nil } -// isConditional returns whether or not the opcode is a conditional opcode which -// changes the conditional execution stack when executed. -func (pop *parsedOpcode) isConditional() bool { - switch pop.opcode.value { - case OP_IF: - return true - case OP_NOTIF: - return true - case OP_ELSE: - return true - case OP_ENDIF: - return true - default: - return false - } -} - // checkMinimalDataPush returns whether or not the current data push uses the // smallest possible opcode to represent it. For example, the value 15 could // be pushed with OP_DATA_1 15 (among other variations); however, OP_15 is a