Skip to content

Commit 497718b

Browse files
committed
Treat amount<0 also as missing data for P2WPKH/P2WSH
Historically lack of amount data has been treated as amount==-1. Change this and treat it as missing data, as introduced in the previous commits. To be minimally invasive, do this at SignatureHash() call sites rather than inside SignatureHash() (which currently has no means or returning a failure code).
1 parent 3820090 commit 497718b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/script/interpreter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,9 @@ bool GenericTransactionSignatureChecker<T>::CheckECDSASignature(const std::vecto
16811681
int nHashType = vchSig.back();
16821682
vchSig.pop_back();
16831683

1684+
// Witness sighashes need the amount.
1685+
if (sigversion == SigVersion::WITNESS_V0 && amount < 0) return HandleMissingData(m_mdb);
1686+
16841687
uint256 sighash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion, this->txdata);
16851688

16861689
if (!VerifyECDSASignature(vchSig, pubkey, sighash))

src/script/sign.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provid
2626
if (sigversion == SigVersion::WITNESS_V0 && !key.IsCompressed())
2727
return false;
2828

29+
// Signing for witness scripts needs the amount.
30+
if (sigversion == SigVersion::WITNESS_V0 && amount < 0) return false;
31+
2932
uint256 hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion);
3033
if (!key.Sign(hash, vchSig))
3134
return false;

0 commit comments

Comments
 (0)