Skip to content

Commit

Permalink
Sanity-check script sizes in bitcoin-tx
Browse files Browse the repository at this point in the history
Summary:
"Sanity-check script sizes in bitcoin-tx (Matt Corallo)"

This is a backport from Core PR11554: bitcoin/bitcoin#11554

Test Plan:
  ninja check
  ./test/functional/test_runner.py

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, deadalnix, Fabien

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D4666
  • Loading branch information
MarcoFalke authored and jonspock committed Oct 5, 2020
1 parent c96d12f commit ff02d80
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/bitcoin-tx.cpp
Expand Up @@ -401,6 +401,11 @@ static void MutateTxAddOutMultiSig(CMutableTransaction &tx,
CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);

if (bScriptHash) {
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
throw std::runtime_error(
strprintf("redeemScript exceeds size limit: %d > %d",
scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
}
// Get the ID for the script, and then construct a P2SH destination for
// it.
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
Expand Down Expand Up @@ -462,7 +467,18 @@ static void MutateTxAddOutScript(CMutableTransaction &tx,
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) {
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
throw std::runtime_error(
strprintf("redeemScript exceeds size limit: %d > %d",
scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
}
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
}

Expand Down

0 comments on commit ff02d80

Please sign in to comment.