Skip to content

Commit

Permalink
txscript: Make alwaysIllegal accept raw opcode.
Browse files Browse the repository at this point in the history
This converts the alwaysIllegal function defined on a parsed opcode to a
standalone function named isOpcodeAlwaysIllegal 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.
  • Loading branch information
davecgh authored and cfromknecht committed Feb 5, 2021
1 parent a3d3df3 commit 6bdd5c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 15 additions & 1 deletion txscript/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ func isOpcodeDisabled(opcode byte) bool {
}
}

// isOpcodeAlwaysIllegal returns whether or not the opcode is 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 isOpcodeAlwaysIllegal(opcode byte) bool {
switch opcode {
case OP_VERIF:
return true
case OP_VERNOTIF:
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.
Expand All @@ -206,7 +220,7 @@ func (vm *Engine) executeOpcode(pop *parsedOpcode) error {
}

// Always-illegal opcodes are fail on program counter.
if pop.alwaysIllegal() {
if isOpcodeAlwaysIllegal(pop.opcode.value) {
str := fmt.Sprintf("attempt to execute reserved opcode %s",
pop.opcode.name)
return scriptError(ErrReservedOpcode, str)
Expand Down
14 changes: 0 additions & 14 deletions txscript/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,20 +692,6 @@ func (pop *parsedOpcode) checkParseableInScript(script []byte, scriptPos int) (i
return scriptPos, nil
}

// alwaysIllegal returns whether or not the opcode is 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
}
}

// isConditional returns whether or not the opcode is a conditional opcode which
// changes the conditional execution stack when executed.
func (pop *parsedOpcode) isConditional() bool {
Expand Down

0 comments on commit 6bdd5c0

Please sign in to comment.