Currently CHECKMULTISIG
recalculates the sighash every time it verifies a key-signature pair. It is not necessary because sighash for the same nHashType
is always the same inside a CHECKMULTISIG
. Therefore, we could reuse a sighash as long as the nHashType
is not changed.
Note that in CHECKMULTISIG
, the trimming of scriptCode
(with CODESEPARATOR
and FindAndDelete()
) is done before the signature checking loop. So the scriptCode
is always a constant in the same CHECKMULTISIG
operation. However, this is not guaranteed across different CHECKSIG
or CHECKMULTISIG
so a cross-opcode sighash cache could not be done in the same way.