MCPcopy Create free account
hub / github.com/ElementsProject/elements / ComputeTaprootMerkleRoot

Function ComputeTaprootMerkleRoot

src/script/interpreter.cpp:3256–3271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3254}
3255
3256uint256 ComputeTaprootMerkleRoot(Span<const unsigned char> control, const uint256& tapleaf_hash)
3257{
3258 const int path_len = (control.size() - TAPROOT_CONTROL_BASE_SIZE) / TAPROOT_CONTROL_NODE_SIZE;
3259 uint256 k = tapleaf_hash;
3260 for (int i = 0; i < path_len; ++i) {
3261 CHashWriter ss_branch = CHashWriter{HASHER_TAPBRANCH_ELEMENTS};
3262 Span node{Span{control}.subspan(TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * i, TAPROOT_CONTROL_NODE_SIZE)};
3263 if (std::lexicographical_compare(k.begin(), k.end(), node.begin(), node.end())) {
3264 ss_branch << k << node;
3265 } else {
3266 ss_branch << node << k;
3267 }
3268 k = ss_branch.GetSHA256();
3269 }
3270 return k;
3271}
3272
3273static bool VerifyTaprootCommitment(const std::vector<unsigned char>& control, const std::vector<unsigned char>& program, const uint256& tapleaf_hash)
3274{

Callers 3

VerifyTaprootCommitmentFunction · 0.85
InferTaprootTreeFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85

Calls 4

GetSHA256Method · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

FUZZ_TARGET_INITFunction · 0.68