Changeset View
Changeset View
Standalone View
Standalone View
src/script/interpreter.cpp
Show First 20 Lines • Show All 1,774 Lines • ▼ Show 20 Lines | if ((flags & SCRIPT_VERIFY_CLEANSTACK) != 0) { | ||||
// CLEANSTACK->P2SH+CLEANSTACK would be possible, which is not a | // CLEANSTACK->P2SH+CLEANSTACK would be possible, which is not a | ||||
// softfork (and P2SH should be one). | // softfork (and P2SH should be one). | ||||
assert((flags & SCRIPT_VERIFY_P2SH) != 0); | assert((flags & SCRIPT_VERIFY_P2SH) != 0); | ||||
if (stack.size() != 1) { | if (stack.size() != 1) { | ||||
return set_error(serror, ScriptError::CLEANSTACK); | return set_error(serror, ScriptError::CLEANSTACK); | ||||
} | } | ||||
} | } | ||||
if (flags & SCRIPT_VERIFY_INPUT_SIGCHECKS) { | |||||
// This limit is intended for standard use, and is based on an | |||||
// examination of typical and historical standard uses. | |||||
// - allowing P2SH ECDSA multisig with compressed keys, which at an | |||||
// extreme (1-of-15) may have 15 SigChecks in ~590 bytes of scriptSig. | |||||
// - allowing Bare ECDSA multisig, which at an extreme (1-of-3) may have | |||||
// 3 sigchecks in ~72 bytes of scriptSig. | |||||
// - Since the size of an input is 41 bytes + length of scriptSig, then | |||||
// the most dense possible inputs satisfying this rule would be: | |||||
// 2 sigchecks and 26 bytes: 1/33.50 sigchecks/byte. | |||||
// 3 sigchecks and 69 bytes: 1/36.66 sigchecks/byte. | |||||
// The latter can be readily done with 1-of-3 bare multisignatures, | |||||
// however the former is not practically doable with standard scripts, | |||||
// so the practical density limit is 1/36.66. | |||||
static_assert(INT_MAX > MAX_SCRIPT_SIZE, | |||||
"overflow sanity check on max script size"); | |||||
static_assert(INT_MAX / 43 / 3 > MAX_OPS_PER_SCRIPT, | |||||
"overflow sanity check on maximum possible sigchecks " | |||||
"from sig+redeem+pub scripts"); | |||||
if (int(scriptSig.size()) < metrics.nSigChecks * 43 - 60) { | |||||
return set_error(serror, ScriptError::INPUT_SIGCHECKS); | |||||
} | |||||
} | |||||
metricsOut = metrics; | metricsOut = metrics; | ||||
return set_success(serror); | return set_success(serror); | ||||
} | } |