Skip to content

Commit 339da9c

Browse files
committed
Merge #11411: script: Change SignatureHash input index check to an assert.
5ddf560 script: Change SignatureHash input index check to an assert. (Jim Posen) Pull request description: In the SignatureHash function, the input index must refer to a valid index. This is not enforced equally in the segwit/non-segwit branches and should be an assertion rather than returning a error hash. Tree-SHA512: a775fc9e9bd9835c0ab36368aa45ab3d53e38f31fd4d2b8684a77ee6028c854c363df038681a59358b30138957573ad63b71d4a722c16e0830fb4fa72669ef39
2 parents c5c77bd + 5ddf560 commit 339da9c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/script/interpreter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,8 @@ PrecomputedTransactionData::PrecomputedTransactionData(const CTransaction& txTo)
11751175

11761176
uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
11771177
{
1178+
assert(nIn < txTo.vin.size());
1179+
11781180
if (sigversion == SIGVERSION_WITNESS_V0) {
11791181
uint256 hashPrevouts;
11801182
uint256 hashSequence;
@@ -1221,10 +1223,6 @@ uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsig
12211223
}
12221224

12231225
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
1224-
if (nIn >= txTo.vin.size()) {
1225-
// nIn out of range
1226-
return one;
1227-
}
12281226

12291227
// Check for invalid use of SIGHASH_SINGLE
12301228
if ((nHashType & 0x1f) == SIGHASH_SINGLE) {

0 commit comments

Comments
 (0)