txscript: always enforce MINIMAL_IF during tapscript execution

This commit is contained in:
Olaoluwa Osuntokun 2022-01-06 18:21:59 -08:00
parent a7a8ad7d37
commit 3c6be738ed
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -839,15 +839,27 @@ func opcodeNop(op *opcode, data []byte, vm *Engine) error {
// the stack will be popped and interpreted as a boolean.
func popIfBool(vm *Engine) (bool, error) {
// When not in witness execution mode, not executing a v0 witness
// program, or the minimal if flag isn't set pop the top stack item as
// a normal bool.
if !vm.isWitnessVersionActive(0) || !vm.hasFlag(ScriptVerifyMinimalIf) {
// program, or not doing tapscript execution, or the minimal if flag
// isn't set pop the top stack item as a normal bool.
switch {
// Minimal if is always on for taproot execution.
case vm.isWitnessVersionActive(TaprootWitnessVersion):
break
// If this isn't the base segwit version, then we'll coerce the stack
// element as a bool as normal.
case !vm.isWitnessVersionActive(BaseSegwitWitnessVersion):
fallthrough
// If the minimal if flag isn't set, then we don't need any extra
// checks here.
case !vm.hasFlag(ScriptVerifyMinimalIf):
return vm.dstack.PopBool()
}
// At this point, a v0 witness program is being executed and the minimal
// if flag is set, so enforce additional constraints on the top stack
// item.
// At this point, a v0 or v1 witness program is being executed and the
// minimal if flag is set, so enforce additional constraints on the top
// stack item.
so, err := vm.dstack.PopByteArray()
if err != nil {
return false, err