Skip to content

Commit fe92c15

Browse files
committed
script/sign: avoid duplicated signature verification after signing
`ProduceSignature` already calls `VerifyScript` internally as last step in order to check whether the signature data is complete. If and only if that is the case, the `complete` field of the `SignatureData` is set accordingly and there is no need then to verify the script after again, as we already know that it would succeed. This leads to a rough ~20% speed-up for `SignTransaction` for single-input ECDSA or Taproot inputs, according to the `SignTransaction{ECDSA,Taproot}` benchmarks.
1 parent 0800895 commit fe92c15

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/script/sign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
831831
}
832832

833833
ScriptError serror = SCRIPT_ERR_OK;
834-
if (!VerifyScript(txin.scriptSig, prevPubKey, &txin.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount, txdata, MissingDataBehavior::FAIL), &serror)) {
834+
if (!sigdata.complete && !VerifyScript(txin.scriptSig, prevPubKey, &txin.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount, txdata, MissingDataBehavior::FAIL), &serror)) {
835835
if (serror == SCRIPT_ERR_INVALID_STACK_OPERATION) {
836836
// Unable to sign input and verification failed (possible attempt to partially sign).
837837
input_errors[i] = Untranslated("Unable to sign input, invalid stack size (possibly missing key)");

0 commit comments

Comments
 (0)