code: func (vm *Engine) CheckErrorCondition(finalScript bool) error {
  	// Check execution is actually done.  When pc is past the end of script
  	// array there are no more scripts to run.
  	if vm.scriptIdx < len(vm.scripts) {
  		return scriptError(ErrScriptUnfinished,
  			"error check when script unfinished")
  	}
  
  	// If we're in version zero witness execution mode, and this was the
  	// final script, then the stack MUST be clean in order to maintain
  	// compatibility with BIP16.
  	if finalScript && vm.isWitnessVersionActive(0) && vm.dstack.Depth() != 1 {
  		return scriptError(ErrEvalFalse, "witness program must "+
  			"have clean stack")
  	}
  
  	if finalScript && vm.hasFlag(ScriptVerifyCleanStack) &&
  		vm.dstack.Depth() != 1 {
  
  		str := fmt.Sprintf("stack contains %d unexpected items",
  			vm.dstack.Depth()-1)
  		return scriptError(ErrCleanStack, str)
  	} else if vm.dstack.Depth() < 1 {
  		return scriptError(ErrEmptyStack,
  			"stack empty at end of script execution")
  	}
  
  	v, err := vm.dstack.PopBool()
  	if err != nil {
  		return err
  	}
  	if !v {
  		// Log interesting data.
  		log.Tracef("%v", newLogClosure(func() string {
  			dis0, _ := vm.DisasmScript(0)
  			dis1, _ := vm.DisasmScript(1)
  			return fmt.Sprintf("scripts failed: script0: %s\n"+
  				"script1: %s", dis0, dis1)
  		}))
  		return scriptError(ErrEvalFalse,
  			"false stack entry at end of script execution")
  	}
  	return nil
  }
docs: // CheckErrorCondition returns nil if the running script has ended and was
  // successful, leaving a a true boolean on the stack.  An error otherwise,
  // including if the script has not finished.