From 11daf6ceb1d9ea1f8d638b123eecfe39d162a7c3 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 2 Nov 2021 10:07:46 -0400 Subject: More Span simplifications Based on suggestions by MarcoFalke --- src/script/descriptor.cpp | 2 +- src/script/interpreter.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/script') diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 1c99df147b..30f929664f 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1252,7 +1252,7 @@ std::unique_ptr InferXOnlyPubkey(const XOnlyPubKey& xkey, ParseS std::unique_ptr InferScript(const CScript& script, ParseScriptContext ctx, const SigningProvider& provider) { if (ctx == ParseScriptContext::P2TR && script.size() == 34 && script[0] == 32 && script[33] == OP_CHECKSIG) { - XOnlyPubKey key{Span{script.data() + 1, script.data() + 33}}; + XOnlyPubKey key{Span{script}.subspan(1, 32)}; return std::make_unique(InferXOnlyPubkey(key, ctx, provider)); } diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index d83ec7192b..6433ba1b58 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1858,7 +1858,7 @@ uint256 ComputeTaprootMerkleRoot(Span control, const uint25 uint256 k = tapleaf_hash; for (int i = 0; i < path_len; ++i) { CHashWriter ss_branch{HASHER_TAPBRANCH}; - Span node(control.data() + TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * i, TAPROOT_CONTROL_NODE_SIZE); + Span node{Span{control}.subspan(TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * i, TAPROOT_CONTROL_NODE_SIZE)}; if (std::lexicographical_compare(k.begin(), k.end(), node.begin(), node.end())) { ss_branch << k << node; } else { @@ -1874,7 +1874,7 @@ static bool VerifyTaprootCommitment(const std::vector& control, c assert(control.size() >= TAPROOT_CONTROL_BASE_SIZE); assert(program.size() >= uint256::size()); //! The internal pubkey (x-only, so no Y coordinate parity). - const XOnlyPubKey p{Span{control.data() + 1, control.data() + TAPROOT_CONTROL_BASE_SIZE}}; + const XOnlyPubKey p{Span{control}.subspan(1, TAPROOT_CONTROL_BASE_SIZE - 1)}; //! The output pubkey (taken from the scriptPubKey). const XOnlyPubKey q{program}; // Compute the Merkle root from the leaf and the provided path. @@ -1886,7 +1886,7 @@ static bool VerifyTaprootCommitment(const std::vector& control, c static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion, const std::vector& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror, bool is_p2sh) { CScript exec_script; //!< Actually executed script (last stack item in P2WSH; implied P2PKH script in P2WPKH; leaf script in P2TR) - Span stack{witness.stack}; + Span stack{witness.stack}; ScriptExecutionData execdata; if (witversion == 0) { -- cgit v1.2.3