The function with_leaf_script directly uses a slice of the script as part of constructing the hash. However, according to BIP341, it is required to use the script encoded with CompactSize before including it in the hash. The actual difference is that the length prefix is missing, which results in a different value for the Merkle tree root compared to the standard approach.
The function with_leaf_script directly uses a slice of the script as part of constructing the hash. However, according to BIP341, it is required to use the script encoded with CompactSize before including it in the hash. The actual difference is that the length prefix is missing, which results in a different value for the Merkle tree root compared to the standard approach.
https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#constructing-and-spending-taproot-outputs