From ad0d98ce7560133e696c2136463b5a2f66ffb86c Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 18 Jun 2019 23:49:32 -0500 Subject: [PATCH] txscript; Use const for sighashall optimization. This breaks the dependency on chaincfg.SigHashOptimization which is no longer available in v2 of the chaincfg module. The constant is set to false to ensure the same semantics are kept and an additional comment has been added regarding the status. --- txscript/opcode.go | 8 ++++++-- txscript/sighash.go | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/txscript/opcode.go b/txscript/opcode.go index 6a37a702..ca21be23 100644 --- a/txscript/opcode.go +++ b/txscript/opcode.go @@ -16,7 +16,6 @@ import ( "golang.org/x/crypto/ripemd160" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/dcrec" "github.com/decred/dcrd/dcrec/edwards" @@ -25,7 +24,12 @@ import ( "github.com/decred/dcrd/wire" ) -var optimizeSigVerification = chaincfg.SigHashOptimization +// optimizeSigVerification is an optimization for verification of transactions +// that contain scripts with CHECKSIG operations with a hash type of SigHashAll. +// +// WARNING: This has not been properly vetted or tested, so it needs significant +// review to ensure it does not break consensus before being enabled. +const optimizeSigVerification = false // An opcode defines the information related to a txscript opcode. opfunc, if // present, is the function to call to perform the opcode on the script. The diff --git a/txscript/sighash.go b/txscript/sighash.go index 904e2d77..0e743ba0 100644 --- a/txscript/sighash.go +++ b/txscript/sighash.go @@ -10,7 +10,6 @@ import ( "fmt" "math" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/wire" ) @@ -299,7 +298,7 @@ func calcSignatureHash(signScript []byte, hashType SigHashType, tx *wire.MsgTx, // can be reused because only the witness data has been modified, so // the wasteful extra O(N^2) hash can be avoided. var prefixHash chainhash.Hash - if chaincfg.SigHashOptimization && cachedPrefix != nil && + if optimizeSigVerification && cachedPrefix != nil && hashType&sigHashMask == SigHashAll && hashType&SigHashAnyOneCanPay == 0 {