Skip to content

Commit

Permalink
[consensus] Expose OP_SUCCESS logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtowns committed Oct 8, 2024
1 parent bc908ac commit 4f07a77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,11 +1785,9 @@ bool GenericTransactionSignatureChecker<T>::CheckSequence(const CScriptNum& nSeq
template class GenericTransactionSignatureChecker<CTransaction>;
template class GenericTransactionSignatureChecker<CMutableTransaction>;

static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CScript& exec_script, unsigned int flags, SigVersion sigversion, const BaseSignatureChecker& checker, ScriptExecutionData& execdata, ScriptError* serror)
std::optional<bool> CheckTapscriptOpSuccess(const CScript& exec_script, unsigned int flags, ScriptError* serror)
{
std::vector<valtype> stack{stack_span.begin(), stack_span.end()};

if (sigversion == SigVersion::TAPSCRIPT) {
{
// OP_SUCCESSx processing overrides everything, including stack element size limits
CScript::const_iterator pc = exec_script.begin();
while (pc < exec_script.end()) {
Expand All @@ -1806,6 +1804,19 @@ static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CS
return set_success(serror);
}
}
}

return std::nullopt;
}

static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CScript& exec_script, unsigned int flags, SigVersion sigversion, const BaseSignatureChecker& checker, ScriptExecutionData& execdata, ScriptError* serror)
{
std::vector<valtype> stack{stack_span.begin(), stack_span.end()};

if (sigversion == SigVersion::TAPSCRIPT) {

auto r = CheckTapscriptOpSuccess(exec_script, flags, serror);
if (r.has_value()) return *r;

// Tapscript enforces initial stack size limits (altstack is empty here)
if (stack.size() > MAX_STACK_SIZE) return set_error(serror, SCRIPT_ERR_STACK_SIZE);
Expand Down
1 change: 1 addition & 0 deletions src/script/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,6 @@ size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey,
int FindAndDelete(CScript& script, const CScript& b);

bool CastToBool(const std::vector<unsigned char>& vch);
std::optional<bool> CheckTapscriptOpSuccess(const CScript& exec_script, unsigned int flags, ScriptError* serror);

#endif // BITCOIN_SCRIPT_INTERPRETER_H

0 comments on commit 4f07a77

Please sign in to comment.