mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge #13721: Bugfixes for BIP 174 combining and deserialization
fad231ad41Fix merging of global unknown data in PSBTs (Andrew Chow)41df035ee1Check that PSBT keys are the correct length (Andrew Chow) Pull request description: This PR fixes a few bugs that were found and adds tests checking for these errors. Specifically: - Single byte keys are checked to actually be one byte. - Unknown global data must be merged when combining two PSBTs. Tree-SHA512: c0e7b4bc607d510cc005aaa7c0813ee58c5467ab7ce4adce485522dfeee92b1af3d29fe89df778b0ea812bb3827e085b30e04d4f4ebcefd8364d809573991332
This commit is contained in:
@@ -474,6 +474,7 @@ void PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
|
||||
for (unsigned int i = 0; i < outputs.size(); ++i) {
|
||||
outputs[i].Merge(psbt.outputs[i]);
|
||||
}
|
||||
unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
|
||||
}
|
||||
|
||||
bool PartiallySignedTransaction::IsSane() const
|
||||
|
||||
@@ -284,12 +284,16 @@ struct PSBTInput
|
||||
case PSBT_IN_NON_WITNESS_UTXO:
|
||||
if (non_witness_utxo) {
|
||||
throw std::ios_base::failure("Duplicate Key, input non-witness utxo already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Non-witness utxo key is more than one byte type");
|
||||
}
|
||||
UnserializeFromVector(s, non_witness_utxo);
|
||||
break;
|
||||
case PSBT_IN_WITNESS_UTXO:
|
||||
if (!witness_utxo.IsNull()) {
|
||||
throw std::ios_base::failure("Duplicate Key, input witness utxo already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Witness utxo key is more than one byte type");
|
||||
}
|
||||
UnserializeFromVector(s, witness_utxo);
|
||||
break;
|
||||
@@ -319,6 +323,8 @@ struct PSBTInput
|
||||
case PSBT_IN_SIGHASH:
|
||||
if (sighash_type > 0) {
|
||||
throw std::ios_base::failure("Duplicate Key, input sighash type already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Sighash type key is more than one byte type");
|
||||
}
|
||||
UnserializeFromVector(s, sighash_type);
|
||||
break;
|
||||
@@ -326,6 +332,8 @@ struct PSBTInput
|
||||
{
|
||||
if (!redeem_script.empty()) {
|
||||
throw std::ios_base::failure("Duplicate Key, input redeemScript already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Input redeemScript key is more than one byte type");
|
||||
}
|
||||
s >> redeem_script;
|
||||
break;
|
||||
@@ -334,6 +342,8 @@ struct PSBTInput
|
||||
{
|
||||
if (!witness_script.empty()) {
|
||||
throw std::ios_base::failure("Duplicate Key, input witnessScript already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Input witnessScript key is more than one byte type");
|
||||
}
|
||||
s >> witness_script;
|
||||
break;
|
||||
@@ -347,6 +357,8 @@ struct PSBTInput
|
||||
{
|
||||
if (!final_script_sig.empty()) {
|
||||
throw std::ios_base::failure("Duplicate Key, input final scriptSig already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Final scriptSig key is more than one byte type");
|
||||
}
|
||||
s >> final_script_sig;
|
||||
break;
|
||||
@@ -355,6 +367,8 @@ struct PSBTInput
|
||||
{
|
||||
if (!final_script_witness.IsNull()) {
|
||||
throw std::ios_base::failure("Duplicate Key, input final scriptWitness already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Final scriptWitness key is more than one byte type");
|
||||
}
|
||||
UnserializeFromVector(s, final_script_witness.stack);
|
||||
break;
|
||||
@@ -442,6 +456,8 @@ struct PSBTOutput
|
||||
{
|
||||
if (!redeem_script.empty()) {
|
||||
throw std::ios_base::failure("Duplicate Key, output redeemScript already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Output redeemScript key is more than one byte type");
|
||||
}
|
||||
s >> redeem_script;
|
||||
break;
|
||||
@@ -450,6 +466,8 @@ struct PSBTOutput
|
||||
{
|
||||
if (!witness_script.empty()) {
|
||||
throw std::ios_base::failure("Duplicate Key, output witnessScript already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Output witnessScript key is more than one byte type");
|
||||
}
|
||||
s >> witness_script;
|
||||
break;
|
||||
@@ -564,6 +582,8 @@ struct PartiallySignedTransaction
|
||||
{
|
||||
if (tx) {
|
||||
throw std::ios_base::failure("Duplicate Key, unsigned tx already provided");
|
||||
} else if (key.size() != 1) {
|
||||
throw std::ios_base::failure("Global unsigned tx key is more than one byte type");
|
||||
}
|
||||
CMutableTransaction mtx;
|
||||
UnserializeFromVector(s, mtx);
|
||||
|
||||
Reference in New Issue
Block a user