Andrew Poelstra <apoels...@wpsoftware.net> writes: > I had a similar thought. But my feeling is that replacing the stack > interpreter data structure is still too invasive to justify the benefit. > > Also, one of my favorite things about this BIP is the tiny diff.
To be fair, this diff is even smaller than the OP_CAT diff :) Though I had to strongly resist refactoring, that interpreter code needs a good shake! Using a class for the stack is worth doing anyway (macros, really??). diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index dcaf28c2472..2ee2034115f 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -403,6 +403,19 @@ static bool EvalChecksig(const valtype& sig, const valtype& pubkey, CScript::con assert(false); } +// First 520 bytes is free, after than you consume an extra slot! +static size_t effective_size(const std::vector<std::vector<unsigned char> >& stack) +{ + size_t esize = stack.size(); + + for (const auto& v : stack) + { + if (v.size() > MAX_SCRIPT_ELEMENT_SIZE) + esize += (v.size() - 1) / MAX_SCRIPT_ELEMENT_SIZE; + } + return esize; +} + bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror) { static const CScriptNum bnZero(0); @@ -1239,7 +1252,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& } // Size limits - if (stack.size() + altstack.size() > MAX_STACK_SIZE) + if (effective_size(stack) + effective_size(altstack) > MAX_STACK_SIZE) return set_error(serror, SCRIPT_ERR_STACK_SIZE); } } _______________________________________________ bitcoin-dev mailing list bitcoin-dev@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev