Skip to content

Commit fbf529f

Browse files
Actually Check Simplicity when feature enabled
1 parent ba9fde9 commit fbf529f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/script/interpreter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,18 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
20262026
execdata.m_validation_weight_left_init = true;
20272027
return ExecuteWitnessScript(stack, exec_script, flags, SigVersion::TAPSCRIPT, checker, execdata, serror);
20282028
}
2029+
if ((flags & SCRIPT_VERIFY_SIMPLICITY) && (control[0] & TAPROOT_LEAF_MASK) == TAPROOT_LEAF_TAPSIMPLICITY) {
2030+
if (stack.size() != 2 || script.size() != 32) return set_error(serror, SCRIPT_ERR_SIMPLICITY_WRONG_LENGTH);
2031+
// Tapsimplicity (leaf version 0xbe)
2032+
const valtype& simplicity_program = SpanPopBack(stack);
2033+
const valtype& simplicity_witness = SpanPopBack(stack);
2034+
const int64_t budget = ::GetSerializeSize(witness.stack) + VALIDATION_WEIGHT_OFFSET;
2035+
rawBitcoinTapEnv simplicityRawTap;
2036+
simplicityRawTap.controlBlock = control.data();
2037+
simplicityRawTap.pathLen = (control.size() - TAPROOT_CONTROL_BASE_SIZE) / TAPROOT_CONTROL_NODE_SIZE;
2038+
simplicityRawTap.scriptCMR = script.data();
2039+
return checker.CheckSimplicity(simplicity_program, simplicity_witness, simplicityRawTap, budget, serror);
2040+
}
20292041
if (flags & SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION) {
20302042
return set_error(serror, SCRIPT_ERR_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION);
20312043
}

src/script/interpreter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ enum : uint32_t {
146146
// Making unknown public key versions (in BIP 342 scripts) non-standard
147147
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE = (1U << 20),
148148

149+
// Support simplicity
150+
SCRIPT_VERIFY_SIMPLICITY = (1U << 21),
151+
149152
// Constants to point to the highest flag in use. Add new flags above this line.
150153
//
151154
SCRIPT_VERIFY_END_MARKER

0 commit comments

Comments
 (0)