From af67951b9a66df3aac1bf3d6376af0730287bbf2 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 13 Mar 2019 01:11:27 -0500 Subject: [PATCH] txscript: Optimize new engine push only script. This modifies the check for whether or not a pay-to-script-hash signature script is a push only script to make use of the new and more efficient raw script function. Also, since the script will have already been checked further above when the ScriptVerifySigPushOnly flags is set, avoid checking it again in that case. --- txscript/engine.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/txscript/engine.go b/txscript/engine.go index 1cc101bd38..2c36560737 100644 --- a/txscript/engine.go +++ b/txscript/engine.go @@ -721,8 +721,11 @@ func NewEngine(scriptPubKey []byte, tx *wire.MsgTx, txIdx int, flags ScriptFlags // The signature script must only contain data pushes for P2SH which is // determined based on the form of the public key script. if isAnyKindOfScriptHash(scriptPubKey) { - // Only accept input scripts that push data for P2SH. - if !isPushOnly(vm.scripts[0]) { + // Notice that the push only checks have already been done when the flag + // to verify signature scripts are push only is set above, so avoid + // checking again. + alreadyChecked := vm.hasFlag(ScriptVerifySigPushOnly) + if !alreadyChecked && !IsPushOnlyScript(scriptSig) { return nil, scriptError(ErrNotPushOnly, "pay to script hash is not push only") }