Skip to content

Commit 2f01903

Browse files
committed
Avoid temporary vectors/uint256s in VerifyTaprootCommitment
As XOnlyPubKey has a Span-based constructor, that can be used directly without needing to first convert the byte sequence into a vector, only to convert that to a uint256, which only then can then be passed as a span to the constructor.
1 parent 4fc15d1 commit 2f01903

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/script/interpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,9 +1874,9 @@ static bool VerifyTaprootCommitment(const std::vector<unsigned char>& control, c
18741874
assert(control.size() >= TAPROOT_CONTROL_BASE_SIZE);
18751875
assert(program.size() >= uint256::size());
18761876
//! The internal pubkey (x-only, so no Y coordinate parity).
1877-
const XOnlyPubKey p{uint256(std::vector<unsigned char>(control.begin() + 1, control.begin() + TAPROOT_CONTROL_BASE_SIZE))};
1877+
const XOnlyPubKey p{Span<const unsigned char>{control.data() + 1, control.data() + TAPROOT_CONTROL_BASE_SIZE}};
18781878
//! The output pubkey (taken from the scriptPubKey).
1879-
const XOnlyPubKey q{uint256(program)};
1879+
const XOnlyPubKey q{program};
18801880
// Compute the Merkle root from the leaf and the provided path.
18811881
const uint256 merkle_root = ComputeTaprootMerkleRoot(control, tapleaf_hash);
18821882
// Verify that the output pubkey matches the tweaked internal pubkey, after correcting for parity.

0 commit comments

Comments
 (0)