txscript/engine: 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.

Backport of af67951b9a66df3aac1bf3d6376af0730287bbf2
This commit is contained in:
Conner Fromknecht 2019-04-19 00:35:28 -07:00 committed by Olaoluwa Osuntokun
parent e98b7c1a9a
commit 549a1f26f2
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -946,7 +946,11 @@ func NewEngine(scriptPubKey []byte, tx *wire.MsgTx, txIdx int, flags ScriptFlags
if vm.hasFlag(ScriptBip16) && isScriptHash(vm.scripts[1]) { if vm.hasFlag(ScriptBip16) && isScriptHash(vm.scripts[1]) {
// Only accept input scripts that push data for P2SH. // 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 && !isPushOnly(vm.scripts[0]) {
return nil, scriptError(ErrNotPushOnly, return nil, scriptError(ErrNotPushOnly,
"pay to script hash is not push only") "pay to script hash is not push only")
} }