| 3254 | } |
| 3255 | |
| 3256 | uint256 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 | |
| 3273 | static bool VerifyTaprootCommitment(const std::vector<unsigned char>& control, const std::vector<unsigned char>& program, const uint256& tapleaf_hash) |
| 3274 | { |