Skip to content

Commit bd7c5e2

Browse files
committed
Add BIP-341 specified constraints to ComputeTaprootMerkleRoot
BIP 341 specifies constraints on the size of the control block _c_ used to compute the taproot merkle root. > The last stack element is called the control block _c_, and must have > length _33 + 32m_, for a value of m that is an integer between 0 and > 128, inclusive. Fail if it does not have such a length. (See BIP-341 "Script Validation Rules" here: https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#script-validation-rules)
1 parent 90e49c1 commit bd7c5e2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/script/interpreter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,10 @@ uint256 ComputeTapleafHash(uint8_t leaf_version, const CScript& script)
18321832

18331833
uint256 ComputeTaprootMerkleRoot(Span<const unsigned char> control, const uint256& tapleaf_hash)
18341834
{
1835+
assert(control.size() >= TAPROOT_CONTROL_BASE_SIZE);
1836+
assert(control.size() <= TAPROOT_CONTROL_MAX_SIZE);
1837+
assert((control.size() - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_NODE_SIZE == 0);
1838+
18351839
const int path_len = (control.size() - TAPROOT_CONTROL_BASE_SIZE) / TAPROOT_CONTROL_NODE_SIZE;
18361840
uint256 k = tapleaf_hash;
18371841
for (int i = 0; i < path_len; ++i) {

0 commit comments

Comments
 (0)