mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
psbt: Enforce sighash type of signatures matches psbt
BIP 174 states that the sighash type of all signatures must match the type given by the PSBT, so do that.
This commit is contained in:
parent
56bef1fddd
commit
7ab8bcdced
1 changed files with 20 additions and 0 deletions
20
src/psbt.cpp
20
src/psbt.cpp
|
@ -425,6 +425,26 @@ PSBTError SignPSBTInput(const SigningProvider& provider, PartiallySignedTransact
|
|||
return PSBTError::SIGHASH_MISMATCH;
|
||||
}
|
||||
|
||||
// Check all existing signatures use the sighash type
|
||||
if (sighash == SIGHASH_DEFAULT) {
|
||||
if (!input.m_tap_key_sig.empty() && input.m_tap_key_sig.size() != 64) {
|
||||
return PSBTError::SIGHASH_MISMATCH;
|
||||
}
|
||||
for (const auto& [_, sig] : input.m_tap_script_sigs) {
|
||||
if (sig.size() != 64) return PSBTError::SIGHASH_MISMATCH;
|
||||
}
|
||||
} else {
|
||||
if (!input.m_tap_key_sig.empty() && (input.m_tap_key_sig.size() != 65 || input.m_tap_key_sig.back() != *sighash)) {
|
||||
return PSBTError::SIGHASH_MISMATCH;
|
||||
}
|
||||
for (const auto& [_, sig] : input.m_tap_script_sigs) {
|
||||
if (sig.size() != 65 || sig.back() != *sighash) return PSBTError::SIGHASH_MISMATCH;
|
||||
}
|
||||
for (const auto& [_, sig] : input.partial_sigs) {
|
||||
if (sig.second.back() != *sighash) return PSBTError::SIGHASH_MISMATCH;
|
||||
}
|
||||
}
|
||||
|
||||
sigdata.witness = false;
|
||||
bool sig_complete;
|
||||
if (txdata == nullptr) {
|
||||
|
|
Loading…
Add table
Reference in a new issue