Merge bitcoin/bitcoin#22650: Remove -deprecatedrpc=addresses flag and corresponding code/logic

43cd6b8af9 doc: add release notes for removal of the -deprecatedrpc=addresses flag (Michael Dietz)
2b1fdc2c6c refactor: minor styling, prefer snake case and same line if (Michael Dietz)
d64deac7b8 refactor: share logic between ScriptPubKeyToUniv and ScriptToUniv (Michael Dietz)
8721638daa rpc: remove deprecated addresses and reqSigs from rpc outputs (Michael Dietz)

Pull request description:

  Resolves #21797 now that we've branched-off to v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed.

   `-deprecatedrpc=addresses` was initially added in this PR #20286 (which resolved the original issue #20102).

  Some chunks of code and logic are no longer used/necessary with the removal of this, and therefore some minor refactoring is done in this PR as well (separated commits)

ACKs for top commit:
  MarcoFalke:
    re-ACK 43cd6b8af9 🐉
  meshcollider:
    Code review ACK 43cd6b8af9
  jonatack:
    ACK 43cd6b8af9 per `git range-diff a9d0cec 92dc5e9 43cd6b8`, also rebased to latest master, debug built + quick re-review of each commit to bring back context, and ran tests locally at the final commit

Tree-SHA512: fba83495e396d3c06f0dcf49292f14f4aa6b68fa758f0503941fade1a6e7271cda8378e2734af1faea550d1b43c85a36c52ebcc9dec0732936f9233b4b97901c
This commit is contained in:
Samuel Dobson
2021-09-29 10:07:04 +13:00
15 changed files with 53 additions and 316 deletions

View File

@@ -56,46 +56,8 @@ FUZZ_TARGET_INIT(script, initialize_script)
assert(script == decompressed_script);
}
CTxDestination address;
TxoutType type_ret;
std::vector<CTxDestination> addresses;
int required_ret;
bool extract_destinations_ret = ExtractDestinations(script, type_ret, addresses, required_ret);
bool extract_destination_ret = ExtractDestination(script, address);
if (!extract_destinations_ret) {
assert(!extract_destination_ret);
if (type_ret == TxoutType::MULTISIG) {
assert(addresses.empty() && required_ret == 0);
} else {
assert(type_ret == TxoutType::PUBKEY ||
type_ret == TxoutType::NONSTANDARD ||
type_ret == TxoutType::NULL_DATA);
}
} else {
assert(required_ret >= 1 && required_ret <= 16);
assert((unsigned long)required_ret == addresses.size());
assert(type_ret == TxoutType::MULTISIG || required_ret == 1);
}
if (type_ret == TxoutType::NONSTANDARD || type_ret == TxoutType::NULL_DATA) {
assert(!extract_destinations_ret);
}
if (!extract_destination_ret) {
assert(type_ret == TxoutType::PUBKEY ||
type_ret == TxoutType::NONSTANDARD ||
type_ret == TxoutType::NULL_DATA ||
type_ret == TxoutType::MULTISIG);
} else {
assert(address == addresses[0]);
}
if (type_ret == TxoutType::NONSTANDARD ||
type_ret == TxoutType::NULL_DATA ||
type_ret == TxoutType::MULTISIG) {
assert(!extract_destination_ret);
}
TxoutType which_type;
bool is_standard_ret = IsStandard(script, which_type);
assert(type_ret == which_type);
if (!is_standard_ret) {
assert(which_type == TxoutType::NONSTANDARD ||
which_type == TxoutType::NULL_DATA ||
@@ -112,6 +74,20 @@ FUZZ_TARGET_INIT(script, initialize_script)
which_type == TxoutType::NONSTANDARD);
}
CTxDestination address;
bool extract_destination_ret = ExtractDestination(script, address);
if (!extract_destination_ret) {
assert(which_type == TxoutType::PUBKEY ||
which_type == TxoutType::NONSTANDARD ||
which_type == TxoutType::NULL_DATA ||
which_type == TxoutType::MULTISIG);
}
if (which_type == TxoutType::NONSTANDARD ||
which_type == TxoutType::NULL_DATA ||
which_type == TxoutType::MULTISIG) {
assert(!extract_destination_ret);
}
const FlatSigningProvider signing_provider;
(void)InferDescriptor(script, signing_provider);
(void)IsSegWitOutput(signing_provider, script);
@@ -133,15 +109,11 @@ FUZZ_TARGET_INIT(script, initialize_script)
(void)ScriptToAsmStr(script, true);
UniValue o1(UniValue::VOBJ);
ScriptPubKeyToUniv(script, o1, true, true);
ScriptPubKeyToUniv(script, o1, true, false);
ScriptPubKeyToUniv(script, o1, true);
UniValue o2(UniValue::VOBJ);
ScriptPubKeyToUniv(script, o2, false, true);
ScriptPubKeyToUniv(script, o2, false, false);
ScriptPubKeyToUniv(script, o2, false);
UniValue o3(UniValue::VOBJ);
ScriptToUniv(script, o3, true);
UniValue o4(UniValue::VOBJ);
ScriptToUniv(script, o4, false);
ScriptToUniv(script, o3);
{
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);

View File

@@ -103,6 +103,6 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
(void)IsWitnessStandard(tx, coins_view_cache);
UniValue u(UniValue::VOBJ);
TxToUniv(tx, /* hashBlock */ uint256::ZERO, /* include_addresses */ true, u);
TxToUniv(tx, /* hashBlock */ uint256::ONE, /* include_addresses */ false, u);
TxToUniv(tx, /* hashBlock */ uint256::ZERO, u);
TxToUniv(tx, /* hashBlock */ uint256::ONE, u);
}

View File

@@ -252,67 +252,6 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
BOOST_CHECK(std::get<WitnessUnknown>(address) == unk);
}
BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
{
CKey keys[3];
CPubKey pubkeys[3];
for (int i = 0; i < 3; i++) {
keys[i].MakeNewKey(true);
pubkeys[i] = keys[i].GetPubKey();
}
CScript s;
TxoutType whichType;
std::vector<CTxDestination> addresses;
int nRequired;
// TxoutType::PUBKEY
s.clear();
s << ToByteVector(pubkeys[0]) << OP_CHECKSIG;
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
BOOST_CHECK_EQUAL(addresses.size(), 1U);
BOOST_CHECK_EQUAL(nRequired, 1);
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
// TxoutType::PUBKEYHASH
s.clear();
s << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
BOOST_CHECK_EQUAL(addresses.size(), 1U);
BOOST_CHECK_EQUAL(nRequired, 1);
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
// TxoutType::SCRIPTHASH
CScript redeemScript(s); // initialize with leftover P2PKH script
s.clear();
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
BOOST_CHECK_EQUAL(addresses.size(), 1U);
BOOST_CHECK_EQUAL(nRequired, 1);
BOOST_CHECK(std::get<ScriptHash>(addresses[0]) == ScriptHash(redeemScript));
// TxoutType::MULTISIG
s.clear();
s << OP_2 <<
ToByteVector(pubkeys[0]) <<
ToByteVector(pubkeys[1]) <<
OP_2 << OP_CHECKMULTISIG;
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
BOOST_CHECK_EQUAL(whichType, TxoutType::MULTISIG);
BOOST_CHECK_EQUAL(addresses.size(), 2U);
BOOST_CHECK_EQUAL(nRequired, 2);
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
BOOST_CHECK(std::get<PKHash>(addresses[1]) == PKHash(pubkeys[1]));
// TxoutType::NULL_DATA
s.clear();
s << OP_RETURN << std::vector<unsigned char>({75});
BOOST_CHECK(!ExtractDestinations(s, whichType, addresses, nRequired));
}
BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
{
CKey keys[3];