Merge bitcoin/bitcoin#32255: miniscript: Correct off-by-one assert guards (#31727 follow-up)
Some checks are pending
CI / test each commit (push) Waiting to run
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Waiting to run
CI / macOS 14 native, arm64, fuzz (push) Waiting to run
CI / Windows native, VS 2022 (push) Waiting to run
CI / Windows native, fuzz, VS 2022 (push) Waiting to run
CI / Linux->Windows cross, no tests (push) Waiting to run
CI / Windows, test cross-built (push) Blocked by required conditions
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Waiting to run

3693e4d6ee miniscript: Correct off-by-one assert guards (Hodlinator)

Pull request description:

  First instances discovered by darosior in https://github.com/bitcoin/bitcoin/pull/31727#issuecomment-2619342125.

ACKs for top commit:
  maflcko:
    lgtm ACK 3693e4d6ee
  sipa:
    ACK 3693e4d6ee
  l0rinc:
    Tested ACK 3693e4d6ee

Tree-SHA512: a41302bb9349d5ad2daf89431c67fdbe80f91690e1759d01529acd1b2fa5d99bad3383da684ee62c00584f7696cd3f87efff084c74edf52eb7cd88d60ee99829
This commit is contained in:
merge-script 2025-04-14 10:59:07 +01:00
commit 5116655980
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -1009,7 +1009,7 @@ private:
next_sats.push_back(sats[sats.size() - 1] + sub->ops.sat);
sats = std::move(next_sats);
}
assert(k <= sats.size());
assert(k < sats.size());
return {count, sats[k], sats[0]};
}
}
@ -1177,7 +1177,7 @@ private:
next_sats.push_back(sats[sats.size() - 1] + sub->ws.sat);
sats = std::move(next_sats);
}
assert(k <= sats.size());
assert(k < sats.size());
return {sats[k], sats[0]};
}
}
@ -1227,7 +1227,7 @@ private:
// satisfying 0 keys.
auto& nsat{sats[0]};
CHECK_NONFATAL(node.k != 0);
assert(node.k <= sats.size());
assert(node.k < sats.size());
return {std::move(nsat), std::move(sats[node.k])};
}
case Fragment::MULTI: {
@ -1253,7 +1253,7 @@ private:
// The dissatisfaction consists of k+1 stack elements all equal to 0.
InputStack nsat = ZERO;
for (size_t i = 0; i < node.k; ++i) nsat = std::move(nsat) + ZERO;
assert(node.k <= sats.size());
assert(node.k < sats.size());
return {std::move(nsat), std::move(sats[node.k])};
}
case Fragment::THRESH: {
@ -1288,7 +1288,7 @@ private:
// Include all dissatisfactions (even these non-canonical ones) in nsat.
if (i != node.k) nsat = std::move(nsat) | std::move(sats[i]);
}
assert(node.k <= sats.size());
assert(node.k < sats.size());
return {std::move(nsat), std::move(sats[node.k])};
}
case Fragment::OLDER: {