Skip to content

Commit

Permalink
Merge bitcoin#11554: Sanity-check script sizes in bitcoin-tx
Browse files Browse the repository at this point in the history
a6f33ea Sanity-check script sizes in bitcoin-tx (Matt Corallo)

Pull request description:

Tree-SHA512: bb8ecb628763af23816ab085758f6140920a6ff05dcb298129c2bbe584a02a759c700a05740eca77023292c98a5658b2a608fa27d5a948d183f87ed9ab827952
  • Loading branch information
MarcoFalke authored and barrystyle committed Jan 22, 2020
1 parent db17812 commit 08471c9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/pacglobal-tx.cpp
Expand Up @@ -351,7 +351,10 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);

if (bScriptHash) {
// Get the address for the redeem script, then call
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
throw std::runtime_error(strprintf(
"redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
}
// GetScriptForDestination() to construct a P2SH scriptPubKey.
CBitcoinAddress addr(scriptPubKey);
scriptPubKey = GetScriptForDestination(addr.Get());
Expand Down Expand Up @@ -411,9 +414,18 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
bScriptHash = (flags.find("S") != std::string::npos);
}

if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
throw std::runtime_error(strprintf(
"script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
}

if (bScriptHash) {
CBitcoinAddress addr(scriptPubKey);
scriptPubKey = GetScriptForDestination(addr.Get());
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
throw std::runtime_error(strprintf(
"redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
}
CBitcoinAddress addr(scriptPubKey);
scriptPubKey = GetScriptForDestination(addr.Get());
}

// construct TxOut, append to transaction output list
Expand Down

0 comments on commit 08471c9

Please sign in to comment.